0
RAG Engineering
Phase 3Module 6 of 18

Retrievers

Raw vector search isn't always enough. Retrievers add intelligence: query transformation, multi-step retrieval, filtering, and combining multiple search strategies. The retriever is often the bottleneck for RAG quality.

A retriever is like a research assistant — you don't just ask them to 'find books in the library.' You ask them to understand your question, search multiple sections, filter by date, and bring back the most relevant pages.

Visual Workflows

Start here — study each diagram, then use + / to zoom if needed.

100%
Loading diagram...

Scroll inside the frame · use + / − to zoom

Key Takeaways

  • 1.Retrievers are components that fetch relevant documents from a knowledge base given a user query — the 'R' in RAG that determines what context the LLM sees.
  • 2.Retriever types: vector (embedding similarity), keyword (BM25/TF-IDF), hybrid (combine vector + keyword), multi-query (generate multiple search queries from one question), parent-document (retrieve small chunks, return larger parent context), and contextual compression (retrieve broadly, then filter to relevant sentences).
  • 3.Framework integration: LangChain Retriever interface, LlamaIndex retrievers.
  • 4.Key config: top_k, score_threshold, search_type, filters.

Real Example

Scenario

A multi-query retriever takes 'How do I deploy the API?' and generates 3 search queries: 'API deployment steps', 'Docker deployment guide', 'production deployment checklist'. Searches for all 3, deduplicates, and returns the best combined results.

What you would do

In RAG Engineering, apply Retrievers to this scenario: A multi-query retriever takes 'How do I deploy the API?' and generates 3 search queries: 'API deployment steps', 'Docker deployment guide', 'production deployment checklist'. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

Practice Task

Open the Code Walkthrough below and run it locally. Change one parameter related to Retrievers (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

Code Walkthrough

Highlighted lines show where Retrievers happens in the code.

Retrievers
1from langchain.retrievers import MultiQueryRetriever  # import dependencies2from langchain_openai import ChatOpenAI, OpenAIEmbeddings  # import dependencies3from langchain_chroma import Chroma  # import dependencies4
5llm = ChatOpenAI(model="gpt-4o-mini")6embeddings = OpenAIEmbeddings()7vectorstore = Chroma(embedding_function=embeddings)8
9retriever = MultiQueryRetriever.from_llm(10    retriever=vectorstore.as_retriever(search_kwargs={"k": 5}),11    llm=llm,12)13
14docs = retriever.invoke("How do I set up authentication?")15for doc in docs:16    print(f"[{doc.metadata.get('source')}] {doc.page_content[:100]}...")  # show output for debugging

Cheat Sheet

Quick recap

quick ref
  • as_retriever(search_kwargs={k:5})
  • MultiQueryRetriever for recall
  • Hybrid = vector + BM25
  • Parent-document for context
  • Filter with metadata
  • Test retrieval independently

Common Mistakes

  • Only using basic vector search without query transformation
  • Not evaluating retriever quality separately from generation
  • top_k too low — missing relevant documents
  • Ignoring metadata filters for time-sensitive content