SINDI support proximity scoring and phrase filter#2425
Conversation
|
/label S-waiting-on-review |
Merge Protections🟢 All 3 merge protections satisfied — ready to merge. Show 3 satisfied protections🟢 Require kind label
🟢 Require version label
🟢 Require linked issue for feature/bug PRs
|
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
|
/assign @Roxanne0321 |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces proximity scoring and phrase filtering capabilities to the SINDI sparse retrieval index, allowing the index to store term positions and perform proximity-aware re-ranking or exact phrase filtering. The review feedback highlights several critical performance and correctness optimizations. Specifically, it suggests optimizing the ordered distance search to O(M + N) using a two-pointer approach, avoiding redundant map clearing in the search path by tracking only dirty document indices, preventing potential uint16_t overflow for long token sequences, hoisting serialization buffers out of loops to eliminate heap allocations, and improving robustness by using span.empty() instead of null pointer checks.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
5cbb889 to
d891821
Compare
384d9eb to
b67c1c3
Compare
|
By default, position storage is disabled, proximity weight is 0, and phrase terms are empty, so the existing SINDI build/search logic is unchanged. New proximity/phrase logic only runs when explicitly enabled. |
74d5089 to
4086bcb
Compare
Signed-off-by: xuanji.ch <xuanji.ch@antgroup.com> Signed-off-by: zhuliming.zlm <zhuliming.zlm@antgroup.com> Assisted-by: Codex:gpt-5
4086bcb to
e20e92a
Compare
Change Type
Linked Issue
What Changed
Adds optional position-aware scoring to the SINDI sparse index. Documents can
now carry their original token order, and queries can boost documents where
query terms appear close together, or hard-filter documents that don't contain
a given phrase.
SparseVectorgains an optionaltoken_sequence_/token_seq_len_field carrying the raw tokenized document. Whenstore_positionsis enabled, per-term positions are extracted (capped bymax_positions_per_term, default 64) and stored as flat offset arrays + ashared position pool in
SparseTermDataCell.proximity_scorer.{h,cpp}): pairwise1/(min_dist+1)boost over query terms — allC(n,2)pairs or adjacent-onlypairs, ordered or unordered, multiplicative or additive. Re-ranks the top
proximity_candidatesby cosine before applying the boost.(
sloppy_phrase_match); a candidate passes only ifphrase_termsoccurwithin
phrase_slop.search_implandimmutable_search_impl(via a templated position backend),so mutable and immutable indexes behave identically. Fixes a latent cursor
misalignment in
deserialize_immutable_windowwhere the position block wasskipped.
store_positions,max_positions_per_term;search-side
proximity_candidates,proximity_weight,proximity_ordered,proximity_boost_multiplicative,proximity_all_pairs,phrase_terms,phrase_slop. All default to off/no-op.cal_memory_usage.Test Evidence
make fmtmake lintmake testmake cov, run tests, and collect coverageNew tests:
proximity_scorer_test.cpp— unit coverage for all/adjacent pairwiseproximity, ordered/unordered, sloppy phrase match, position extraction.
sparse_term_datacell_position_test.cpp— position storage / retrieval.sindi_test.cpp— end-to-end proximity + phrase, plus amutable-vs-immutable equality test across fp32 / sq8 / fp16 and remap.
Test details:
Compatibility Impact
SparseVectorgains two trailing fields(
token_seq_len_,token_sequence_); existing callers that leave themzero/null are unaffected. All new index/search parameters default to
off, so existing indexes and queries behave exactly as before.
Indexes built without
store_positionscannot use proximity/phrase.Performance and Concurrency Impact
only the top
proximity_candidates; per-doc cost is O(T²×P) (T = presentquery terms, P = positions/term). Position lists are read via non-owning
PosSpanviews to avoid per-candidate copies.query.
Documentation Impact
README.mdDEVELOPMENT.mdCONTRIBUTING.mddocs/docs/en/src/indexes/sindi.mdanddocs/docs/zh/src/indexes/sindi.md— added the new build params(
store_positions,max_positions_per_term), the search params(
proximity_*,phrase_*), and a "Proximity scoring and phrase filter"section covering the
token_sequence_input.Risk and Rollback
default to off.
indexes built without
store_positions.Checklist