Skip to content

fix(#10514): the PQ search can re-rank its candidates on the stored vectors and takes a beam - #10517

Closed
tae898 wants to merge 1 commit into
ArcadeData:mainfrom
tae898:fix/10514-pq-rerank
Closed

tae898 wants to merge 1 commit into
ArcadeData:mainfrom
tae898:fix/10514-pq-rerank

Conversation

@tae898

@tae898 tae898 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Covers item 1 of the Expected list in #10514: a re-rank with a real beam in the PQ search (findNeighborsFromVectorApproximate and the vectorApproximate Select).

What changed: findNeighborsFromVectorApproximate has a new overload (queryVector, k, efSearch, rerankOversample, allowedRIDs, guard) and a shorter one without the allow-list and guard. With rerankOversample > 0 the walk is still steered by the in-memory PQ codes, jvector keeps max(k * rerankOversample, efSearch) candidates (search(ssp, k, rerankK, 0, 0, bits) instead of search(ssp, k, bits), which is topK = rerankK = k), scores them with the stored vectors through the same liveOnlyScoreFunction the exact path uses, and returns the nearest k with exact distances. This is the BINARY idea (oversample, then score on the stored vectors), done by jvector's own reranker. In that mode the delta buffer and the allow-list pre-filter plan are answered exactly as well, so no row of the answer is on a different scale than the others. LSMVectorIndex.DEFAULT_APPROXIMATE_RERANK_OVERSAMPLE is 10 (the BINARY path uses 4; at 10 candidates per neighbour SIFT-1M with 32 subspaces measured 0.9864 in the issue). The select builder gets rerank() and rerank(int) for approximate(true). The guard exceptions (timeout, terminated statement) are rethrown as they are in the exact path.

Decision to review: rerankOversample = 0, and every existing signature, keep the PQ-only answer exactly as before. I did not change the default of findNeighborsFromVectorApproximate(q, k) and approximate(true), because their documented contract is zero record reads and PQ-scaled distances, and #6559, #6514 and #6797 pin that. If you want re-rank to be the default, it is a one-line change of the delegating overload plus those tests passing the PQ-only mode explicitly.

Test: Issue10514ApproximateRerankTest (4 tests), 20,000 x 64 vectors in 100 clusters with fixed seeds, PRODUCT with the default 16 subspaces, the exact top 10 of 100 queries computed in the test. It checks that the PQ-only recall is far below the exact search, that re-ranking 30 candidates per neighbour is within 0.02 of the exact search and the default 10 within 0.08, that the returned distances equal the exact squared L2 distances and ascend, that the fluent select reaches both modes, that rerank 0 gives the old answer, that the allow-list is honoured in the re-rank mode and that a negative oversample is refused. Before the change (same code with the re-rank switched off) the test fails: exact 1.0000, PQ scores only 0.3340, "re-ranked" 0.3340. After: PQ scores only 0.3580, re-ranked at the default 0.9470, at 30 candidates per neighbour 1.0000.

Tested: maven in docker (amazoncorretto-25) on the engine module, mvn -pl engine -Dtest=Issue10514ApproximateRerankTest test (before: 1 failure, after: pass), then mvn -pl engine -Dtest='Issue10514ApproximateRerankTest,PQSearchDebugTest,LSMVectorIndex*Test,Issue*Vector*Test,Issue6559*,Issue6514*Test,Issue6797*,Issue7378*,Issue6873VectorSelectTimeoutTest,Issue5558*,Issue9796*,PqCodesStaleForRebuiltGraphTest,Issue8960*,Issue9396*,Issue9633*' test: 518 tests, 0 failures. The probe from the issue on siftsmall (10,000 x 128, 100 queries), engine at upstream main 2eed9d4 against this branch, JDK 25, with the probe extended by three lines that call the new overload:

siftsmall, PRODUCT 32 subspaces, recall@10 of 100 queries before (upstream main 2eed9d4) after (this branch)
findNeighborsFromVectorApproximate k=10, PQ scores 0.8200 0.8330
findNeighborsFromVectorApproximate k=50, PQ scores 0.8390 0.8460
findNeighborsFromVectorApproximate k=100, PQ scores 0.8390 0.8460
findNeighborsFromVectorApproximate(q, 10, -1, 5), re-ranked not available 1.0000
findNeighborsFromVectorApproximate(q, 10, -1, 10), re-ranked not available 1.0000
findNeighborsFromVectorApproximate(q, 10, -1, 30), re-ranked not available 1.0000
SQL vectorNeighbors efSearch 100, PRODUCT (unchanged) 1.0000 1.0000

The index files of the PRODUCT index are the subject of the sibling pull request #10516.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added optional exact re-ranking for approximate vector searches to improve result recall and distance accuracy.
    • Added fluent query options to enable re-ranking with a default or custom oversampling value.
    • Re-ranked searches continue to honor allow-list filtering and return exact distances.
  • Bug Fixes

    • Improved fallback behavior when approximate vector search cannot be used.
    • Invalid negative oversampling values are now rejected with a clear error.

…ectors and takes a beam

findNeighborsFromVectorApproximate asked jvector for exactly k candidates (topK = rerankK = k) and returned the PQ scores, so its recall@10 stopped improving at any beam (0.72 on SIFT-1M with 32 subspaces). A new overload takes efSearch and rerankOversample: the walk is still steered by the in-memory PQ codes, jvector scores the best max(k * rerankOversample, efSearch) of them on the stored vectors, and the nearest k come back with exact distances. The delta buffer and the allow-list pre-filter plan are answered exactly in that mode, so every row is on one scale. rerankOversample 0, and every existing signature, keep the PQ-only answer. The select builder gets rerank() and rerank(int) for approximate(true).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mergify

mergify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3fe28910-4453-4535-98d2-d003d804c15d
📥 Commits

Reviewing files that changed from the base of the PR and between 2eed9d4 and 0592f2e.

📒 Files selected for processing: 5
  • engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java
  • engine/src/main/java/com/arcadedb/query/select/Select.java
  • engine/src/main/java/com/arcadedb/query/select/SelectExecutor.java
  • engine/src/main/java/com/arcadedb/query/select/SelectVectorBuilder.java
  • engine/src/test/java/com/arcadedb/index/vector/Issue10514ApproximateRerankTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Walkthrough

Approximate vector search now supports configurable candidate oversampling and exact reranking with stored vectors. SELECT queries can configure the oversampling value. Regression tests cover recall, distance accuracy, filtering, and validation.

Changes: Approximate vector reranking

Layer / File(s) Summary
Index reranking and fallback behavior
engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java
Adds reranking overloads and a default oversampling value of 10. Positive oversampling reranks retained PQ candidates with stored vectors. Zero keeps the non-reranked path, and negative values are rejected. Exact-search fallbacks preserve efSearch.
SELECT builder and execution wiring
engine/src/main/java/com/arcadedb/query/select/Select.java, engine/src/main/java/com/arcadedb/query/select/SelectVectorBuilder.java, engine/src/main/java/com/arcadedb/query/select/SelectExecutor.java
Adds rerank() and rerank(int) builder methods and passes the configured oversampling value to approximate vector searches.
Reranking regression coverage
engine/src/test/java/com/arcadedb/index/vector/Issue10514ApproximateRerankTest.java
Adds deterministic tests for recall, exact squared-L2 distances, zero and negative oversampling, allow-list filtering, and fluent selection.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant SelectVectorBuilder
  participant SelectExecutor
  participant LSMVectorIndex
  participant PQSearch
  participant StoredVectors
  SelectVectorBuilder->>SelectExecutor: set rerank oversampling
  SelectExecutor->>LSMVectorIndex: execute approximate vector search
  LSMVectorIndex->>PQSearch: retrieve candidate neighbors
  PQSearch-->>LSMVectorIndex: candidate neighbors
  LSMVectorIndex->>StoredVectors: calculate exact candidate distances
  StoredVectors-->>LSMVectorIndex: exact distances
  LSMVectorIndex-->>SelectExecutor: nearest neighbors
Loading

Possibly related issues

  • ArcadeData/arcadedb#10514: Requests configurable overquery and exact reranking for PQ approximate search, which this change adds.

Suggested reviewers: lvca

Merge Risk: ⚪ Minimal · up to 0592f

No confirmed issue blocks merging. The reported test results should still be confirmed through normal validation.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: PRODUCT-quantized search can re-rank candidates. It is concise enough and directly related to the pull request.
Description check Passed The description provides a detailed change summary, motivation, related issue reference, implementation notes, test coverage, and validation results. It does not use the repository template headings o…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description provides a detailed change summary, motivation, related issue reference, implementation notes, test coverage, and validation results. It does not use the repository template headings or include the checklist, but the required information is mostly present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 4 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@tae898

tae898 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

The red checks are not from this change. Issue7089NaNTransparentSumAvgTest, Issue7139RetainedBackupNotDestroyedTest and python-e2e-tests fail the same way on main (runs 39560511262 at 046db7b and 39558984773 at 65f93c5). The third unit failure, Issue5596MergeCoverageTest.aCleanAppendConflictIsStillMerged, is the edge-append page merge, a path this PR does not touch (it changes LSMVectorIndex, Select, SelectExecutor and SelectVectorBuilder only), and it passed on those main runs, so it looks like a concurrency-timing flake.

@tae898

tae898 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Merged as part of #10545 (a5661e9), which carries this branch's commits in order; closing. Thanks for folding them in.

@tae898 tae898 closed this Oct 21, 2026
@tae898
tae898 deleted the fix/10514-pq-rerank branch October 21, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant