Repository navigation
Add full precision rescoring for quantized vector search - #1051
Merged
Merged
Conversation
Add KnnQuery.rescore_vector.oversample, which collects ceil(k * oversample) hits using the quantized vector scores, rescores them with the full precision vectors, and returns the top k. This uses Lucene's RescoreTopNQuery with FullPrecisionFloatVectorSimilarityValuesSource, wrapped in VectorRescoreQuery to preserve vector diagnostics. Add ExactVectorQuery.full_precision to score with the full precision vectors instead of the quantized vectors, allowing full precision rescoring through a QueryRescorer. Both options are only supported for float vector fields.
Add VectorRescoreQueryTest unit tests. Add VectorFieldDefTest coverage for the oversampled k and num candidates of the built query, rescoring through a KnnRetriever, and profiled rescore searches. Add NrtKnnFloatVectorQuery.getTopHits to inspect the oversampled k. Fix VectorRescoreQuery.toString, which threw a NullPointerException from FullPrecisionFloatVectorSimilarityValuesSource.toString when the values source is created without a similarity function. Document why RescoreTopNQuery is wrapped instead of using createFullPrecisionRescorerQuery.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds the option to rescore quantized KNN vector search hits using the full precision vectors. This is the same idea as Elasticsearch's
rescore_vector.For
hnsw_scalar_quantizedfields, both the HNSW graph search and the hit scores come from the quantized vectors. The full precision float vectors are still stored in the index. A common way to recover accuracy is to oversample the quantized search, rescore those candidates with the full precision vectors, and return the topk.Changes
KnnQuery.rescore_vectorNew
RescoreVectormessage with anoversamplefactor:ceil(k * oversample)hits, capped at thenum_candidateslimit of 10000.num_candidatesis raised to this value if it is lower.kare returned with full precision similarity scores.oversamplemust be>= 1.0, or0(default) to disable rescoring. A value of1.0re-ranks the topkwithout collecting extra hits.similarityThresholdandboostare applied to the rescored score.knnqueries and multi-retrieverKnnRetriever, since they share the same query building path.Implementation uses Lucene's
RescoreTopNQuerywithFullPrecisionFloatVectorSimilarityValuesSource. The newVectorRescoreQuerywrapper:WithVectorTotalHits, so vector diagnostics keep workingMatchNoDocsQuerywhen the filter matches no documentsExactVectorQuery.full_precisionExactVectorQueryscores withFloatVectorValues.scorer(), which uses the quantized vectors when the field has a quantized vector search type. The newfull_precisionflag switches toFloatVectorValues.rescorer(), which uses the full precision vectors. It defaults tofalse, so existing behavior is unchanged.This also allows full precision rescoring of any first pass query through the existing rescorer API:
Only supported for float vector fields.
Other
docs/vector_search.rstwith a "Rescoring Quantized Vector Search" section. Also corrected theKnnQueryproto snippet.Testing
New tests in
VectorFieldDefTest, using a 4 bit quantized field:k.oversample = 1.0, normalized cosine, boost, similarity threshold, filter, filter matching no documents, and thenum_candidateslimit cap.oversamplevalues and for byte fields.ExactVectorQuerywithfull_precisionmatches brute force full precision results. Without it, scores are quantized.