Improving RAG: Self Querying Retrieval

KEEP IN TOUCH | THE GEN AI SERIES

Rahul S
3 min readFeb 11, 2024

Let’s address a big issue when building RAG systems.

We cannot depend on semantic search for every retrieval task. Semantic search makes sense only when we are after meaning and intent of words.

But in case, we are doing a search on things that are in the database, like we might want just want to perfom a look-up task, using Semantic search is illogical. It can even give inaccurate results, and uses unnecessary computing power.

This issue is generally seen when dealing with excel files or financial data. For those cases, LangChain provides a utility called Self Querying Retrieval.

What we do is simple. We insert a ‘step’ between the retrieval and the input. So,

  • the person types in the query
  • we use a language model to reformat the query to get semantic elements of the query
  • we also convert the query so we can do searches on metadata.

To reiterate, the idea is rather simple. If we are looking for a movie, and we want to look at the year, we will go to the…

--

--