Skip to content

Commit d33bac8

Browse files
authored
Ref guide - Improve docs for Dense Vector reranking examples (#4532)
1 parent abcff76 commit d33bac8

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

solr/solr-ref-guide/modules/query-guide/pages/dense-vector-search.adoc

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,37 @@ Some use cases where `includeTags` and/or `excludeTags` may be more useful then
816816

817817

818818

819-
=== Usage in Re-Ranking Query
819+
[[vector-reranking]]
820+
== Usage in Re-Ranking Query
821+
822+
Dense vector similarity scores can be used to xref:query-guide:query-re-ranking.adoc[re-rank] first pass query results.
823+
Possible use cases include:
824+
825+
* Re-ranking approximate results from a quantized vector field using full fidelity float vectors.
826+
* Re-ranking lexical search results with dense vector similarity scores.
827+
828+
Details about using the ReRank Query Parser can be found in the xref:query-guide:query-re-ranking.adoc[Query Re-Ranking] section.
829+
830+
=== Re-Ranking with vectorSimilarity Function Query
831+
832+
The xref:query-guide:function-queries.adoc#vectorsimilarity-function[vectorSimilarity()] function can be used with the `{!func}` query parser to re-rank by vector similarity.
833+
When used as a function query, `vectorSimilarity()` computes the exact similarity for only the candidate documents selected for re-ranking, without traversing the index graph.
834+
835+
Here is an example of re-ranking a lexical query using a `DenseVectorField` named `vector`:
836+
837+
[source,text]
838+
?q=title:phone&rq={!rerank reRankQuery=$rqq reRankDocs=100 reRankWeight=1}&rqq={!func}vectorSimilarity(vector,[1.0,2.0,3.0,4.0])
839+
840+
NOTE: The default `reRankOperator` is `add`, which sums the first-pass score and the vector similarity score.
841+
Since these scores may differ in magnitude, you can adjust `reRankWeight` to control the balance between them, or use `reRankOperator=replace` to score re-ranked documents by vector similarity alone.
842+
843+
When using a quantized vector field type (such as `ScalarQuantizedDenseVectorField`), the KNN first pass scores are computed on the quantized vectors.
844+
Here is an example of re-ranking those results with exact float similarity scores, where `topK` matches `reRankDocs`:
845+
846+
[source,text]
847+
?q={!knn f=vector topK=100}[1.0,2.0,3.0,4.0]&rq={!rerank reRankQuery=$rqq reRankDocs=100 reRankWeight=1 reRankOperator=replace}&rqq={!func}vectorSimilarity(vector,[1.0,2.0,3.0,4.0])
848+
849+
=== Re-Ranking with knn Query Parser
820850

821851
Both dense vector search query parsers can be used to rerank first pass query results:
822852

@@ -834,8 +864,6 @@ the k-nearest neighbors(*in the whole index*) of the target vector to search.
834864
This means the second pass `knn` is executed on the whole index anyway, which is a current limitation.
835865
836866
The final ranked list of results will have the first pass score(main query `q`) added to the second pass score(the approximated similarityFunction distance to the target vector to search) multiplied by a multiplicative factor(reRankWeight).
837-
838-
Details about using the ReRank Query Parser can be found in the xref:query-guide:query-re-ranking.adoc[Query Re-Ranking] section.
839867
====
840868

841869

solr/solr-ref-guide/modules/query-guide/pages/query-re-ranking.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ In the example below, the scores for the top 1000 documents matching the query "
134134
q=phone&rq={!rerank reRankQuery=$rqq reRankDocs=1000 reRankWeight=1 reRankOperator=replace}&rqq={!func v=div(1,sum(1,price))}
135135
----
136136

137+
xref:query-guide:dense-vector-search.adoc[Dense vector fields] can also be used for re-ranking via the xref:query-guide:function-queries.adoc#vectorsimilarity-function[vectorSimilarity()] function query.
138+
This computes exact vector similarity only for the re-ranked candidate documents. See xref:query-guide:dense-vector-search.adoc#vector-reranking[Usage in Re-Ranking Query] for examples and details.
139+
137140

138141
=== LTR Query Parser
139142

0 commit comments

Comments
 (0)