AI Model Wiki

    Skip to main content
    15 min read
    Lesson 4 of 6

    Advanced RAG Patterns & Optimization

    From the course AI Embeddings & Vector Databases

    Basic RAG (retrieve then generate) works but has well-known limitations. Advanced patterns address these systematically.

    Hybrid Search

    Combine vector similarity with keyword search (BM25) for the best of both worlds:

    • Vector search catches semantic matches ("automobile" ↔ "car")
    • Keyword search catches exact matches (product IDs, names, codes)
    • Reciprocal Rank Fusion (RRF) merges results from both

    Most production RAG systems use hybrid search. Weaviate and Qdrant support it natively.

    Multi-Query Retrieval

    A single user query might be ambiguous. Generate multiple query variations and retrieve for each:

    1. Original: "How does authentication work?"
    2. Variation: "What are the login methods available?"
    3. Variation: "How do users sign up and verify their identity?"

    Union the results for higher recall.

    Contextual Compression

    Retrieved chunks often contain irrelevant content. An LLM can extract only the relevant sentences before passing to the generator, reducing noise and token costs.

    Parent Document Retrieval

    Index small chunks for precise matching, but retrieve the larger parent document for context. This gives you the precision of small chunks with the context of large ones.

    Self-RAG

    The model decides whether it needs retrieval, retrieves if necessary, then self-evaluates the relevance of retrieved documents before generating. This prevents hallucinations from irrelevant retrievals.

    Evaluation Metrics

    Measure your RAG system with:

    • Retrieval precision@k: What fraction of retrieved documents are relevant?
    • Retrieval recall@k: What fraction of relevant documents were retrieved?
    • Answer faithfulness: Does the generated answer stay true to retrieved context?
    • Answer relevance: Does the answer actually address the question?

    Tools like RAGAS, DeepEval, and TruLens automate these evaluations.

    Key Takeaways

    • •Hybrid search (vector + BM25) outperforms either approach alone in production
    • •Multi-query retrieval improves recall by searching with query variations
    • •Parent document retrieval balances precision of small chunks with full context
    • •Evaluate with retrieval precision/recall and answer faithfulness/relevance
    0 of 6 lessons marked complete

    Progress is kept in this browser only.