Exploring the LLM Twin’s advanced RAG techniques
Now that we understand the overall flow of our RAG inference pipeline, let’s explore the advanced RAG techniques we used in our retrieval module:
- Pre-retrieval step: Query expansion and self-querying
- Retrieval step: Filtered vector search
- Post-retrieval step: Reranking
Before digging into each method individually, let’s lay down the Python interfaces we will use in this section, which are available at https://github.com/PacktPublishing/LLM-Engineers-Handbook/blob/main/llm_engineering/application/rag/base.py.
The first is a prompt template factory that standardizes how we instantiate prompt templates. As an interface, it inherits from ABC
and exposes the create_template()
method, which returns a LangChain PromptTemplate
instance. Even if we avoid being heavily reliant on LangChain, as we want to implement everything ourselves to understand the engineering behind the scenes, some...