Skip to content

ai fts: improve full-text index docs and scoring details#23302

Open
zhaoshangzi wants to merge 3 commits into
pingcap:release-8.5from
zhaoshangzi:fts_sql_change1
Open

ai fts: improve full-text index docs and scoring details#23302
zhaoshangzi wants to merge 3 commits into
pingcap:release-8.5from
zhaoshangzi:fts_sql_change1

Conversation

@zhaoshangzi

@zhaoshangzi zhaoshangzi commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

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.

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)

What is the related PR or file link(s)?

  • This PR is translated from:
  • Other reference link(s):

AI agent involvement

  • The changes in this PR were primarily made by an AI agent on behalf of the PR author.

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

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.
@zhaoshangzi
zhaoshangzi requested review from 3pointer and lilin90 July 17, 2026 08:37
@ti-chi-bot ti-chi-bot Bot added contribution This PR is from a community contributor. missing-translation-status This PR does not have translation status info. labels Jul 17, 2026
@pingcap-cla-assistant

pingcap-cla-assistant Bot commented Jul 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f48b4472-dd4c-402a-902a-0b2d8853176f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lilin90 lilin90 added the translation/no-need No need to translate this PR. label Jul 17, 2026
@ti-chi-bot ti-chi-bot Bot removed the missing-translation-status This PR does not have translation status info. label Jul 17, 2026
@lilin90 lilin90 added the ONCALL Relates to documentation oncall. label Jul 17, 2026
@lilin90 lilin90 self-assigned this Jul 17, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from lilin90. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@lilin90 lilin90 changed the title Improve full-text index docs and scoring details ai FTS: improve full-text index docs and scoring details Jul 17, 2026
@lilin90 lilin90 changed the title ai FTS: improve full-text index docs and scoring details ai fts: improve full-text index docs and scoring details Jul 17, 2026
@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 20, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-20 04:37:17.349099407 +0000 UTC m=+1206823.385194453: ☑️ agreed by 3pointer.

Comment thread ai/guides/vector-search-full-text-search-sql.md Outdated
Comment thread ai/guides/vector-search-full-text-search-sql.md Outdated

### 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- 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:**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Viewing existing index names:**
**View existing index names:**

WHERE TABLE_SCHEMA = 'your_database' AND TABLE_NAME = 'stock_items';
```

**Dropping a full-text index:**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**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`:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> **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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@lilin90

lilin90 commented Jul 21, 2026

Copy link
Copy Markdown
Member

@zhaoshangzi Would you please address the comments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. ONCALL Relates to documentation oncall. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. translation/no-need No need to translate this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants