-
Notifications
You must be signed in to change notification settings - Fork 99
feat: add threshold filtering to knn search #2531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wxyucs
wants to merge
1
commit into
antgroup:main
Choose a base branch
from
wxyucs:codex/issue-2081-knn-threshold
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,30 @@ BruteForce 索引支持用 Build 和 Add 方法写入数据,这里我们用 Ad | |
|
|
||
| 搜索请求至多返回 k 个结果,这些结果按照最近邻和查询向量的距离升序排序。输出的结果类似于: | ||
|
|
||
| ## 按阈值过滤 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [note] Same issue as the English docs: "本 PR 的阈值支持范围仅包括" references the PR itself. Consider rephrasing to describe the feature directly, e.g. "阈值过滤支持以下仍在维护的索引:BruteForce、HGraph、IVF、Pyramid、SINDI 和 SIMQ。" |
||
|
|
||
| 本 PR 的阈值支持范围仅包括仍在维护的索引:BruteForce、HGraph、IVF、Pyramid、SINDI 和 | ||
| SIMQ。HNSW 和 DiskANN 已弃用,是明确不在范围内的目标;本选项不会为这两个旧索引新增或修改行为。 | ||
|
|
||
| KNN 搜索参数支持在 JSON 顶层设置可选的 `threshold`: | ||
|
|
||
| ```json | ||
| { | ||
| "threshold": 4.0, | ||
| "hgraph": { "ef_search": 64 } | ||
| } | ||
| ``` | ||
|
|
||
| 设置后,结果至多返回 `k` 个邻居,并且每个返回距离都小于或等于 `threshold`。 | ||
| 边界值会被包含,结果仍按距离升序排列,因此可能返回少于 `k` 个结果,甚至没有结果。 | ||
| 不设置该字段时,KNN 行为保持不变。阈值使用索引返回的距离语义:`l2` 为 L2 平方距离, | ||
| `ip` 为 `1 - inner_product`,`cosine` 为 `1 - cosine_similarity`。因此 `ip` 可以使用负阈值; | ||
| 阈值必须是有限的 JSON 数字。 | ||
|
|
||
| 通过统一请求接口时,BruteForce、HGraph 和 IVF 支持使用 `SearchRequest::threshold_`; | ||
| Pyramid、SINDI 和 SIMQ 通过 KNN JSON 参数支持该选项。这六种索引是本功能支持的仍在维护的索引。 | ||
| 该选项只限制 KNN 结果;范围搜索请使用 `RangeSearch` 及其 `radius` 参数。`threshold` 可以和现有索引专用搜索参数同时传入。 | ||
|
|
||
| ```bash | ||
| results: | ||
| 6519: 13.855 | ||
|
|
@@ -105,4 +129,3 @@ results: | |
| 8703: 16.1161 | ||
| 5583: 16.1256 | ||
| ``` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note] The documentation references "This PR's threshold support" which ties the docs to a specific pull request. User-facing documentation should describe the feature itself without referencing the PR that added it. Consider rephrasing to something like "Threshold filtering is supported for the following maintained indexes: BruteForce, HGraph, IVF, Pyramid, SINDI, and SIMQ."
The same issue appears in the Chinese documentation.