rerank() function.
rerank()
The rerank() function is called on the query instance and accepts the following parameters:
The model to use for reranking. Currently, only
cohere/rerank-v3.5 is supported.The query text to rerank against. Uses arguments from
semantic_similarity() function if not specified.List of fields to use for reranking. Uses fields from
semantic_similarity() function if not specified.topk_multiple
Multiple of top-k to rerank. For example, if
topk=10 and topk_multiple=2, reranker takes 20 results from the original query and returns the top 10 results.Lexical scoring with reranking
Consider the following example for searching documents with the"how to reset a router" query:
"1" is ranked higher because:
- It contains
"how","to","reset","router"(some of which match the query directly). - Phrases like
"how to reset router"appear close together.
"2" is ranked lower because:
- Although it describes a true factory reset, it doesn’t include the exact phrase
"how to reset a router"but includes"how to reset your device". - The term
"router"might not appear (assume it uses"device").
using rerank() to boost relevant results
Let’s apply thererank() passing the "how to reset a router" query matching against the "content" field to rerank the results:
rerank() function, the relevance of the results is improved - the actual guide on how to reset a router is ranked higher,
even though keyword "router" does not appear in the "title" field.