> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# TSVECTOR

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The `TSVECTOR` <InternalLink path="data-types">data type</InternalLink> stores a list of lexemes, optionally with integer positions and weights. `TSVECTOR` values are used in <InternalLink path="full-text-search">full-text search</InternalLink>.

## Syntax

A `TSVECTOR` comprises individual lexemes in the form: `'These' 'lexemes' 'are' 'not' 'normalized' 'lexemes.'`.

You can optionally add the following to each lexeme:

* One or more comma-separated integer positions:

  `'These':1 'lexemes':2 'are':3 'not':4 'normalized':5 'lexemes.':6`
* A weight letter (`A`, `B`, `C`, or `D`), in combination with an integer position:

  `'These':1 'lexemes':2B 'are':3 'not':4 'normalized':5A 'lexemes.':6B`

  If not specified, a lexeme's weight defaults to `D`. The lexemes in a `TSQUERY` and `TSVECTOR` will only match if they have matching weights. For more information about weights, see the [PostgreSQL documentation](https://www.postgresql.org/docs/15/datatype-textsearch#DATATYPE-TSVECTOR).

To be usable in <InternalLink path="full-text-search">full-text search</InternalLink>, the lexemes **must be normalized**. You can do this by using the `to_tsvector()` <InternalLink path="functions-and-operators#full-text-search-functions">built-in function</InternalLink> to convert a string input to `TSVECTOR`:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT to_tsvector('These lexemes are not normalized lexemes.');
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       to_tsvector
--------------------------
  'lexem':2,6 'normal':5
```

Normalization removes the following from the input:

* Derivatives of words, which are reduced using a [stemming](https://wikipedia.org/wiki/Stemming) algorithm.
* *Stop words*. These are words that are considered not useful for indexing and searching, based on the <InternalLink path="full-text-search#text-search-configuration">text search configuration</InternalLink>. In the preceding example, "These", "are", and "not" are identified as stop words.
* Punctuation and capitalization.

In the preceding output, the integers indicate that `normal` is in the fifth position and `lexem` is in both the second and sixth position in the input.

## Examples

For usage examples, see <InternalLink path="full-text-search">Full-Text Search</InternalLink>.

## See also

* <InternalLink path="full-text-search">Full-Text Search</InternalLink>
* <InternalLink path="tsquery">`TSQUERY`</InternalLink>
* <InternalLink path="data-types">Data Types</InternalLink>
