ai fts: improve full-text index docs and scoring details#23302
ai fts: improve full-text index docs and scoring details#23302zhaoshangzi wants to merge 3 commits into
Conversation
Expand the full-text search guide with practical details: clarify that the STANDARD parser lowercases text for case-insensitive matching; add a "Managing full-text indexes" section explaining index naming, viewing (SHOW INDEX / INFORMATION_SCHEMA), dropping, and examples for CREATE/ALTER/CREATE FULLTEXT INDEX; add sections on tokenization and multi-word search semantics (fts_match_word uses tokenization and OR semantics, no phrase or prefix matching), explain effect of repeated terms on BM25 scoring, and document the BM25Tanvity relevance algorithm with the standard k1=1.2 and b=0.75 defaults.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
|
||
| ### Manage full-text indexes | ||
|
|
||
| When creating a full-text index, the index name is optional. If not specified, TiDB automatically uses the first column name of the index as the index name. |
There was a problem hiding this comment.
| When creating a full-text index, the index name is optional. If not specified, TiDB automatically uses the first column name of the index as the index name. | |
| When creating a full-text index, specifying an index name is optional. If you do not specify one, TiDB uses the name of the first indexed column as the index name by default. |
| When creating a full-text index, the index name is optional. If not specified, TiDB automatically uses the first column name of the index as the index name. | ||
|
|
||
| ```sql | ||
| -- Without specifying an index name, TiDB automatically generates the name "title" |
There was a problem hiding this comment.
| -- Without specifying an index name, TiDB automatically generates the name "title" | |
| -- Without specifying an index name, TiDB uses the first indexed column name ("title") as the index name |
| ALTER TABLE stock_items ADD FULLTEXT INDEX ft_title (title) WITH PARSER MULTILINGUAL; | ||
| ``` | ||
|
|
||
| **Viewing existing index names:** |
There was a problem hiding this comment.
| **Viewing existing index names:** | |
| **View existing index names:** |
| WHERE TABLE_SCHEMA = 'your_database' AND TABLE_NAME = 'stock_items'; | ||
| ``` | ||
|
|
||
| **Dropping a full-text index:** |
There was a problem hiding this comment.
| **Dropping a full-text index:** | |
| **Drop a full-text index:** |
|
|
||
| #### Specify an index name | ||
|
|
||
| In both `CREATE TABLE` and `ALTER TABLE` syntax, you can specify a name for the index after `FULLTEXT INDEX` or `FULLTEXT KEY`: |
There was a problem hiding this comment.
| In both `CREATE TABLE` and `ALTER TABLE` syntax, you can specify a name for the index after `FULLTEXT INDEX` or `FULLTEXT KEY`: | |
| In both `CREATE TABLE` and `ALTER TABLE` statements, you can specify an index name after `FULLTEXT INDEX` or `FULLTEXT KEY`: |
|
|
||
| #### Multi-word search: tokenization and query semantics | ||
|
|
||
| When using `fts_match_word()`, the query string is split into individual tokens according to the parser's rules, and each token is matched independently. |
There was a problem hiding this comment.
| When using `fts_match_word()`, the query string is split into individual tokens according to the parser's rules, and each token is matched independently. | |
| When you use `fts_match_word()`, the query string is tokenized according to the parser's rules, and each token is matched independently. |
|
|
||
| When using `fts_match_word()`, the query string is split into individual tokens according to the parser's rules, and each token is matched independently. | ||
|
|
||
| For the STANDARD parser, strings are split into words by spaces and punctuation. For the MULTILINGUAL parser, strings are split according to each language's segmentation rules. |
There was a problem hiding this comment.
| For the STANDARD parser, strings are split into words by spaces and punctuation. For the MULTILINGUAL parser, strings are split according to each language's segmentation rules. | |
| The STANDARD parser tokenizes strings into words using spaces and punctuation as delimiters. The MULTILINGUAL parser tokenizes strings according to language-specific segmentation rules. |
| SELECT * FROM users WHERE fts_match_word('Alice Smith', name); | ||
| ``` | ||
|
|
||
| A common misconception is that `fts_match_word('Alice X', name)` treats `"Alice X"` as a single entity for exact matching. In reality, it is tokenized into `Alice` and `X`, using OR semantics. Since `X` is a very short term, it can match many irrelevant documents. Avoid using very short query terms or single letters. |
There was a problem hiding this comment.
| A common misconception is that `fts_match_word('Alice X', name)` treats `"Alice X"` as a single entity for exact matching. In reality, it is tokenized into `Alice` and `X`, using OR semantics. Since `X` is a very short term, it can match many irrelevant documents. Avoid using very short query terms or single letters. | |
| A common misconception is that `fts_match_word('Alice X', name)` treats `"Alice X"` as a single entity for exact matching. In reality, it is tokenized into `Alice` and `X`, using OR semantics. Because `X` is a very short query term, it can match many irrelevant documents. Avoid using very short query terms or single letters. |
|
|
||
| A common misconception is that `fts_match_word('Alice X', name)` treats `"Alice X"` as a single entity for exact matching. In reality, it is tokenized into `Alice` and `X`, using OR semantics. Since `X` is a very short term, it can match many irrelevant documents. Avoid using very short query terms or single letters. | ||
|
|
||
| > **Note:** TiDB full-text search does not support exact phrase matching (matching all tokens consecutively in order). |
There was a problem hiding this comment.
| > **Note:** TiDB full-text search does not support exact phrase matching (matching all tokens consecutively in order). | |
| > **Note:** | |
| > | |
| > TiDB full-text search does not support exact phrase matching, where all query tokens must appear consecutively and in the specified order. |
|
|
||
| #### Relevance scoring algorithm | ||
|
|
||
| TiDB full-text search uses the **BM25Tanvity** algorithm for computing relevance scores. It is a variant of the classic BM25 (Okapi BM25) that uses Count-Min Sketch to approximate document frequency (DF) estimation for improved performance. |
There was a problem hiding this comment.
| TiDB full-text search uses the **BM25Tanvity** algorithm for computing relevance scores. It is a variant of the classic BM25 (Okapi BM25) that uses Count-Min Sketch to approximate document frequency (DF) estimation for improved performance. | |
| TiDB full-text search uses the **BM25Tantivy** algorithm to calculate relevance scores. This algorithm is a variant of the classic BM25 (Okapi BM25) algorithm that uses Count-Min Sketch to approximate document frequency (DF) for improved performance. |
|
@zhaoshangzi Would you please address the comments? |
First-time contributors' checklist
What is changed, added or deleted? (Required)
Expand the full-text search guide with practical details: clarify that the STANDARD parser lowercases text for case-insensitive matching; add a "Managing full-text indexes" section explaining index naming, viewing (SHOW INDEX / INFORMATION_SCHEMA), dropping, and examples for CREATE/ALTER/CREATE FULLTEXT INDEX; add sections on tokenization and multi-word search semantics (fts_match_word uses tokenization and OR semantics, no phrase or prefix matching), explain effect of repeated terms on BM25 scoring, and document the BM25Tanvity relevance algorithm with the standard k1=1.2 and b=0.75 defaults.
Which TiDB version(s) do your changes apply to? (Required)
Tips for choosing the affected version(s):
By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.
For details, see tips for choosing the affected versions.
What is the related PR or file link(s)?
AI agent involvement
Do your changes match any of the following descriptions?