Skip to content

Commit 92db102

Browse files
committed
Updates to ranking
1 parent 11b4568 commit 92db102

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
Vector search matches user queries with semantically similar content instead of exact word matches. However, you can get multiple results from a vector search that you want to filter and rerank to refine and reorder your search results.
1+
When you perform vector search, you get document chunks ranked by similarity scores. But similarity doesn't always equal relevance - sometimes the most mathematically similar chunks aren't the most useful for answering a user's question. Ranking and reranking help you understand and improve these results.
22

3-
Imagine the following scenario:
3+
:::image type="content" source="../media/reranker.png" alt-text="Diagram showing the reranking process: user query leads to multiple similar documents from vector search, then reranking selects the most relevant subset for the language model.":::
44

5-
:::image type="content" source="../media/reranker.png" alt-text="Diagram of a ranking scenario after retrieving relevant documents.":::
5+
This diagram illustrates the complete process: A user query searches your vector database and returns multiple semantically similar document chunks. However, only some of these chunks are truly relevant to answering the user's question. A reranker evaluates all the retrieved chunks and selects the most relevant ones to send to the language model for generating the final response.
66

7-
1. A user query comes in and is used to search your vector store for any relevant documents.
8-
1. Multiple documents are identified as being semantically similar to the user query.
9-
1. Only a subset of the documents are relevant. You can use a **reranker** to select the top three documents based on certain criteria.
10-
1. The three documents are provided as context for a language model to generate a response to the user.
7+
## Understanding similarity scores
118

12-
Reranking adjusts the initial ranking of retrieved documents to enhance the precision and relevance of search results. You can reorder documents based on the relevance scores with the goal to place the most relevant documents at the top of the list.
9+
Vector search ranks results using **similarity scores** that measure how mathematically similar document chunk vectors are to your query vector. These scores help determine which chunks are most likely to be relevant, but higher similarity doesn't guarantee the content will best answer the user's question.
1310

14-
When you use vector search to retrieve relevant documents, the similarity between two vectors is calculated with the **cosine similarity**. The higher the metric, the more similar two vectors are.
11+
For example, a query about "dog training methods" might return highly similar chunks about "pet care supplies" or "animal behavior theory" - these are topically related but may not contain the specific training techniques the user needs.
1512

16-
:::image type="content" source="../media/cosine-similarity.png" alt-text="Diagram of the cosine similarity between a query and document vector.":::
13+
## When and why to rerank
1714

18-
Reranking goes beyond just evaluating the cosine similarity between the query and document vectors. It supports a deeper semantic understanding by considering the actual relevance of the documents to the query. A reranker can select more relevant documents and reduce hallucinations.
15+
**Reranking** goes beyond basic similarity to evaluate actual relevance to the user's question. Instead of just looking at vector similarity, reranking considers factors like:
1916

20-
:::image type="content" source="../media/reranker-vectors.png" alt-text="Diagram of the reranking of multiple document vectors.":::
17+
- How well the content directly answers the query
18+
- The context and intent behind the user's question
19+
- The practical usefulness of the information
2120

22-
To use a reranker, you can use:
21+
This additional step can improve answer quality and reduce hallucinations, but it also adds processing time to your RAG pipeline.
2322

24-
- **Private** APIs, like [Cohere](https://cohere.com/rerank) or [Jina](https://jina.ai/reranker/?azure-portal=true).
25-
- **Open-source** rerankers, like [cross-encoders](https://www.sbert.net/docs/cross_encoder/pretrained_models.html?azure-portal=true), [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding?azure-portal=true), or [FlashRank](https://github.com/PrithivirajDamodaran/FlashRank?azure-portal=true).
23+
## Implementing reranking
2624

27-
Though rerankers can improve the accuracy of the final response of your Generative AI application, implementing rerankers adds complexity to the RAG pipeline and must be done with care.
25+
If the basic similarity search provided by Mosaic AI Vector Search isn't providing relevant enough results for your use case, you can implement reranking using:
26+
27+
- **APIs** like [Cohere](https://cohere.com/rerank) or [Jina](https://jina.ai/reranker/?azure-portal=true)
28+
- **Open-source models** like [cross-encoders](https://www.sbert.net/docs/cross_encoder/pretrained_models.html?azure-portal=true), [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding?azure-portal=true), or [FlashRank](https://github.com/PrithivirajDamodaran/FlashRank?azure-portal=true)
29+
30+
Keep in mind that reranking adds complexity and processing time to your RAG pipeline. Start with Mosaic AI Vector Search's built-in similarity search and consider reranking only if you need to improve result relevance for your specific use case.

0 commit comments

Comments
 (0)