Save up to 40%Choose an ASKtoAI annual plan.

Compare Plans
Contextual Retrieval Anthropic
Artificial Intelligence

Introduction to Contextual Retrieval: A Revolution in Information Access

Anthropic’s Contextual Retrieval Revolutionizes Information Access, Improving RAG Accuracy by 49%. A Breakthrough for Contextually Aware AI.

In the vast landscape of AI, Anthropic stands out once again with an innovation that promises to transform the way we interact with large knowledge bases. Contextual Retrieval represents a significant advance in Retrieval-Augmented Generation (RAG) technology, offering an elegant solution to one of the most persistent problems in AI: the loss of context during information retrieval.

The Context Dilemma in Traditional RAG Systems

Traditional RAG systems have revolutionized the ability of language models to access vast amounts of information. However, these systems suffer from a significant limitation: context loss . When documents are broken into smaller fragments for easier retrieval, the larger context in which this information is embedded is often lost. This can lead to inaccurate or misleading responses, especially when dealing with complex or nuanced information.

For example, imagine a system that needs to answer questions about financial reports. A snippet might contain the information "revenue grew 3% from the previous quarter," but without the context of the specific company or time period, this information loses much of its value.

Contextual Retrieval: An Innovative Solution

Anthropic’s Contextual Retrieval addresses this problem in an ingenious way. Instead of simply breaking documents into fragments, the system adds a short explanatory context to each fragment before incorporating it into the knowledge base. This context is generated using AI, specifically Claude, Anthropic’s advanced language model.

The process works like this:

  1. The document is divided into fragments.
  2. For each fragment, Claude generates a short context (50-100 tokens) that explains the fragment's position and significance within the larger document.
  3. This context is placed before the original fragment.
  4. The contextualized fragment is then incorporated into the knowledge database.

This approach allows to maintain the critical context even when retrieving single pieces of information, significantly improving the accuracy and relevance of the responses generated by the system.

Impact and Performance

The results obtained with Contextual Retrieval are impressive. According to tests conducted by Anthropic:

  • Using Contextual Embeddings reduced the failure rate in retrieving the first 20 fragments by 35% (from 5.7% to 3.7%).
  • By combining Contextual Embeddings and Contextual BM25 , the failure rate was reduced by 49% (from 5.7% to 2.9%).

These improvements translate directly into more accurate and relevant responses from AI systems, with potential applications across a wide range of industries, from customer support to legal analysis, from scientific research to enterprise knowledge management.

Implementation and Practical Considerations

Implementing Contextual Retrieval requires some important considerations:

  1. Fragment Boundaries : The choice of fragment size, fragment boundaries, and overlap can significantly affect retrieval performance.
  2. Embedding Model : While Contextual Retrieval improves the performance of all embedding models tested, some models may benefit more than others. Anthropic found Gemini and Voyage embeddings to be particularly effective.
  3. Custom contextual prompts : While the generic prompt provided by Anthropic works well, you can achieve even better results with prompts tailored to specific domains or use cases.
  4. Number of fragments : Adding more fragments to the context window increases the chances of including relevant information, but it can also distract the model. Anthropic has found that using 20 fragments provides the best performance, but it is recommended to experiment to find the optimal balance for each specific use case.

Further Improvements: Reranking

To further push the performance of Contextual Retrieval, Anthropic has experimented with adding a reranking phase. This process involves:

  1. Perform an initial retrieval to obtain potentially relevant fragments (Anthropic used the first 150).
  2. Pass these fragments, along with the user query, through a reranking model.
  3. Assign each fragment a score based on its relevance and importance to the query.
  4. Select the highest scoring fragments (Anthropic used the top 20).

The results were remarkable: Contextual Retrieval with reranking reduced the failure rate in retrieving the first 20 fragments by 67% (from 5.7% to 1.9%).

Conclusions and Future Perspectives

Contextual Retrieval represents a significant advancement in RAG technology, offering an elegant solution to the context loss problem. By combining contextual embeddings, contextual BM25, and reranking, Anthropic has demonstrated that it is possible to dramatically improve the accuracy and relevance of retrieved information.

This advancement paves the way for more intelligent, contextually aware AI systems that can provide more accurate and useful answers across a wide range of applications. From customer support to complex document analysis, from personalized tutoring to scientific research, the potential applications of Contextual Retrieval are vast and promising.

As the technology continues to evolve, we can expect further refinements and improvements in this area. The challenge going forward will be to balance performance increases with cost and latency considerations, especially for real-time applications.

In conclusion, Anthropic’s Contextual Retrieval represents an important step towards more intelligent and contextually aware AI systems, promising to transform the way we interact with vast knowledge bases and opening up new possibilities in numerous application fields.

Marco esposito

Marco Esposito

25/09/2024

to top icon