…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]>
Covers item 1 of the Expected list in #10514: a re-rank with a real beam in the PQ search (
findNeighborsFromVectorApproximateand thevectorApproximateSelect).What changed:
findNeighborsFromVectorApproximatehas a new overload(queryVector, k, efSearch, rerankOversample, allowedRIDs, guard)and a shorter one without the allow-list and guard. WithrerankOversample > 0the walk is still steered by the in-memory PQ codes, jvector keepsmax(k * rerankOversample, efSearch)candidates (search(ssp, k, rerankK, 0, 0, bits)instead ofsearch(ssp, k, bits), which istopK = rerankK = k), scores them with the stored vectors through the sameliveOnlyScoreFunctionthe 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_OVERSAMPLEis 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 getsrerank()andrerank(int)forapproximate(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 offindNeighborsFromVectorApproximate(q, k)andapproximate(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), thenmvn -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: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
Bug Fixes