Code lab 14.1 – Query expansion
The code for this lab can be found in the CHAPTER14-1_QUERY_EXPANSION.ipynb
file in the CHAPTER14
directory of the GitHub repository.
Many techniques for enhancing RAG focus on improving one area, such as retrieval or generation, but query expansion has the potential to improve both. We have already talked about the concept of expansion in Chapter 13, but that was focused on the LLM output. Here, we focus the concept on the input to the model, augmenting the original prompt with additional keywords or phrases. This approach can improve the retrieval model’s understanding as you add more context to the user query that is used for retrieval, increasing the chances of fetching relevant documents. With an improved retrieval, you are already helping to improve the generation, giving it better context to work with, but this approach also has the potential to produce a more effective query, which in turn also helps the LLM deliver an improved...