Brief IA

RAG and Hybrid Search: The Future of Document AI

🔬 Research·Tom Levy·

RAG and Hybrid Search: The Future of Document AI

RAG and Hybrid Search: The Future of Document AI
Key Takeaways
1RAG, or Retrieval-Augmented Generation, combines document retrieval and AI to answer user questions.
2Hybrid search combines vector similarity and keywords to enhance the relevance of results.
3Making the RAG system agentic allows LLMs to better handle queries and optimize results.
💡Why it mattersThis approach significantly improves the efficiency of information systems, responding more accurately to user needs.
Le brief IA que lisent les pros

Le brief IA que les pros lisent chaque soir

Les 7 actus IA du jour, décryptées en 5 min. Gratuit.

Inclus dès l'inscription : notre sélection des meilleurs guides & comparatifs IA.

Choisis ton rythme

Gratuit · Pas de spam · Désabonnement en 1 clic

📄
Full Analysis

What is RAG?

The concept of Retrieval-Augmented Generation (RAG) represents a significant advancement in the field of document retrieval assisted by artificial intelligence. This method allows for the discovery of relevant documents within a vast corpus of information, which are then utilized by a language model (LLM) to answer user queries. In practice, RAG employs vector similarity to identify relevant segments within a corpus, subsequently passing these segments to the LLM to generate an accurate response.

Semantic similarity is a powerful tool for identifying the most relevant segments, as it enables understanding the meaning of words beyond their mere appearance. However, this method can encounter difficulties in certain situations, particularly when the user employs specific keywords or identifiers that need to be explicitly located. In such cases, vector similarity alone may not suffice, and a different approach is necessary to extract the most pertinent information.

Why Use Hybrid Search

Vector similarity is extremely effective at identifying relevant segments within a document corpus, even when the query contains errors or synonyms. For example, it can understand that a user searching for "elevator" might also mean "lift." However, it shows its limitations when it comes to searching for specific keywords or identifiers.

The main reason is that vector similarity does not assign sufficient weight to individual words or identifiers compared to other words. Consequently, key keywords or identifiers may get lost among other relevant words, making it difficult for semantic similarity to find the most pertinent segments.

In contrast, keyword search, such as that performed by the BM25 algorithm, is particularly effective at identifying specific terms. For instance, if a word appears only in one document and that word is included in the user's query, that document will be heavily weighted and included in the search results.

This is why a hybrid approach is recommended. By combining vector similarity and keyword search, it is possible to find more relevant documents, especially when the user employs keywords in their query.

How to Implement Hybrid Search

Implementing a hybrid search can be done in several ways. Here are the steps to follow if you wish to do it yourself:

  • Start by implementing vector retrieval through semantic similarity. Although this article does not cover the exact details of this process, it is essential for hybrid search.

  • Next, implement a keyword search algorithm, such as BM25. BM25 is often recommended because it is based on the TF-IDF model and offers a better formula for keyword search. However, the choice of the exact algorithm is not crucial, although BM25 is a good standard.

  • Apply a weighting between the similarity found through semantic similarity and the similarity from keyword search. This weighting can be adjusted based on the importance you assign to each method. If you have an agent performing hybrid search, you can also allow the agent to decide this weighting, as agents generally have a good intuition for when to use or prioritize one method over the other.

Tools like TurboPuffer offer integrated solutions for vector storage and keyword search. However, for a deeper understanding of the system, it is advisable to carry out a personal implementation.

Agentic Hybrid Search

Implementing hybrid search is a significant enhancement for any RAG system. However, to maximize the benefits, it is crucial to make the system agentic.

An agentic RAG system operates differently from a traditional system. Instead of retrieving relevant segments before using an LLM to respond, the segment retrieval function becomes a tool that the LLM can access directly. This grants the LLM greater autonomy, with several major advantages:

  • The agent can decide on the prompt to use for vector search. Thus, instead of solely using the user's exact prompt, it can rephrase the prompt to achieve better vector search results. Query reformulation is a well-known technique for improving RAG performance.

  • The agent can retrieve information iteratively, meaning it can first perform a vector search call, check if it has enough information to answer a question, and if not, it can retrieve even more information. This allows the agent to review the information it has gathered and, if necessary, obtain additional data, which will help it respond better to questions.

  • The agent can decide on the weighting between keyword search and vector similarity. This is incredibly powerful, as the agent generally knows whether it is searching for a keyword or semantically similar content. For example, if the user has included a keyword in their search query, the agent will likely tend to weigh the keyword search component of the hybrid search more heavily, leading to better results. This works much better than having a static number for the weighting between keyword search and vector similarity.

Today's leading LLMs are incredibly powerful and will be able to make all these judgments themselves. A few months ago, I would have doubted the necessity of granting the agent as much freedom as I have described in the points above, allowing it to select the prompt usage, retrieve information iteratively, and decide on the weighting between keyword search and semantic similarity. However, today, I know that the latest cutting-edge LLMs have become so powerful that this is entirely feasible and even something I recommend implementing.

Thus, by implementing both hybrid search and making it agentic, you can truly energize your RAG system and achieve results far better than what you would obtain with a RAG system based solely on vector similarity.

In this article, I discussed how to implement hybrid search in your RAG system. Additionally, I described how to make your RAG system agentic for significantly better results. The combination of these two techniques will lead to an incredible increase in the performance of your information retrieval system, and this can actually be implemented quite easily using coding agents like Claude Code. I believe that agentic systems are the future of information retrieval, and I encourage you to provide effective information retrieval tools, such as hybrid search, to your agents and let them do the rest of the work.

Brief IA — L'actualité IA en français

L'essentiel de l'actualité de l'intelligence artificielle, décrypté et expliqué chaque jour.