The most surprising thing about RAG production pipelines is that their reliability often hinges on what you don’t retrieve, not just what you do.

Let’s watch a RAG pipeline in action. Imagine a user asks, "What are the key features of the Q3 product launch?"

  1. User Query: "What are the key features of the Q3 product launch?"
  2. Embedding: The query is converted into a vector embedding.
  3. Vector Database Search: This embedding is used to find the most similar document chunks (embeddings) in a vector database containing product documentation, marketing materials, and internal reports.
    • Example Retrieval: The system might retrieve chunks like:
      • "Q3 Product Launch: Feature A enhances user engagement by 20%."
      • "The new dashboard provides real-time analytics on user adoption."
      • "Marketing campaign for Q3 focuses on scalability and ease of use."
  4. Context Augmentation: These retrieved chunks are prepended to the original query, forming an augmented prompt for the LLM.
    • Augmented Prompt: "Context: Q3 Product Launch: Feature A enhances user engagement by 20%. The new dashboard provides real-time analytics on user adoption. Marketing campaign for Q3 focuses on scalability and ease of use. \n\n Question: What are the key features of the Q3 product launch?"
  5. LLM Generation: The LLM processes this augmented prompt and generates an answer.
    • LLM Output: "The key features of the Q3 product launch include Feature A, which is designed to enhance user engagement, a new dashboard for real-time analytics on user adoption, and a marketing focus on scalability and ease of use."

This entire flow relies on the retrieval step accurately pulling the most relevant information.

The problem RAG solves is grounding LLM responses in specific, up-to-date, or proprietary data, preventing hallucination and enabling domain-specific knowledge. Internally, it’s a two-stage process: retrieval (finding relevant data) and generation (using that data to answer). The "retrieval" stage is where the magic (and potential failure) happens.

The exact levers you control are primarily:

  • Embedding Model: The choice of model (e.g., text-embedding-ada-002, all-MiniLM-L6-v2, Cohere’s embed-english-light-v2.0) dictates how semantically similar documents are represented.
  • Chunking Strategy: How you split your source documents (e.g., fixed-size chunks with overlap, sentence splitting, semantic chunking) profoundly impacts retrieval accuracy.
  • Vector Database Configuration: The indexing method (e.g., HNSW, IVF), distance metric (e.g., cosine similarity, dot product), and search parameters (k for top-k retrieval) directly influence what gets returned.
  • Re-ranking/Filtering: Post-retrieval steps can refine the retrieved set based on secondary criteria or LLM-based scoring.
  • Prompt Engineering: How you structure the augmented prompt for the LLM.

A crucial, often overlooked, aspect is how the absence of certain retrieved information can signal to the LLM that the answer isn’t available. If your RAG pipeline is configured to retrieve documents about "Product A" but the user asks about "Product B," and no relevant chunks for "Product B" are found, the system should ideally indicate that it cannot answer. This requires careful tuning of retrieval thresholds and potentially using a "no answer" response mechanism within the LLM prompt.

The next concept you’ll likely grapple with is optimizing the trade-off between retrieval recall (finding all relevant documents) and precision (finding only relevant documents) without overwhelming the LLM’s context window.

Want structured learning?

Take the full Rag course →