Module 10 Lesson 5: Retrieval Pipelines
Connecting the dots. How a user's question travels through the vector store and back to the LLM.
The RAG Pipeline: Putting It All Together
We have the Embeddings, the Vector Store, and the Chunks. Now, we build the "Bridge" that connects the user to the answer. This complete workflow is called the Retrieval Pipeline.
1. The Full Lifecycle
Here is exactly what happens when you ask: "What is our company's policy on remote work?"
Phase A: Retrieval
- Question Embedding: The question is turned into a vector using
mxbai-embed-large. - Vector Search: The system finds the 3 chunks in your database that are closest to that vector.
- Context Assembly: The text from those 3 chunks is extracted into a string.
Phase B: Augmentation (The Secret Sauce)
The system builds a new, "Super-Prompt" for the LLM:
Answer the question based ONLY on the provided context.
### CONTEXT:
[Chunk 1 text]
[Chunk 2 text]
[Chunk 3 text]
---
QUESTION: What is our company's policy on remote work?
Phase C: Generation
- Inference: Ollama (Llama 3) reads this long prompt.
- Output: It sees that "Remote work is allowed on Fridays" in Chunk 2.
- Response: It tells the user: "Based on the handbook, you can work remotely on Fridays."
2. Why this is "Safe"
Look at Phace B. The model is Augmented. It is trapped inside the "Context" you provided. If you ask it about "The moon," and your chunks don't mention the moon, the model (if guardrailed correctly) will say "I don't know."
This is why RAG is the primary way we stop AI from lying (Hallucinating).
3. Improving the Pipeline: Re-Ranking
Sometimes the "Top 3" chunks aren't actually the best ones.
- The Problem: Vector search is "Vague" (Semantic).
- The Fix: You can pull 10 chunks, and use a small, ultra-fast model to "Re-Rank" them and pick the absolute best one before giving it to Llama 3.
4. Tools for Pipelines
You don't have to build this from scratch.
- Python: Use LangChain or LlamaIndex. They have a
VectorStoreRetrieverclass that does this 4-step process in one line of code. - No-Code: Tools like AnythingLLM or Open WebUI provide a graphical interface for this pipeline.
Key Takeaways
- The Pipeline is the glue that connects search to generation.
- Augmentation is the act of injecting search results into the prompt.
- The LLM acts as a Reasoning Engine that reads the search results, not a "Knowledge Engine" that remembers them.
- Use frameworks like LlamaIndex to automate this complex workflow.