Loading notes...
Loading notes...
RAG • Chapter 8
RAG engineering module on Advanced RAG.
Basic RAG (Naive RAG) often fails when user queries are short or vaguely worded. Advanced RAG techniques modify the retrieval process to improve semantic matching.
Advanced System Mechanics
HyDE (Hypothetical Document Embeddings) uses an LLM to generate a fake, hypothetical answer to the user's query, and then embeds that fake answer to search the vector database. Because the fake answer looks more like a target document than a short query does, retrieval accuracy skyrockets. Parent Document Retrieval involves chunking documents into small pieces for highly accurate search, but returning the larger 'parent' chunk to the LLM to provide full surrounding context.
Implementation Blueprint
# Conceptual HyDE Implementation
def hyde_retrieval(query, llm, vector_db):
# 1. Generate hypothetical document
hypothetical_doc = llm.generate(f"Write a paragraph answering: {query}")
# 2. Search vector DB using the hypothetical document's embedding
# instead of the user's raw query
results = vector_db.similarity_search(hypothetical_doc)
return results