Single logo
  • Courses
  • Blog
  • About
Join free on SkoolJoin free on Skool

In this topic

AI Engineering
  • The AI Stack in One Picture: Six Layers Every AI Product Is Built From
  • Tokenization: What an LLM Actually Sees When You Type
  • LLM Tokens, Context Windows and Cost: What One Question Really Costs
  • What an LLM Can and Cannot Do: One Prediction Loop, Its Strengths and Its Gaps
  • Structured LLM Output with Pydantic: Describe the Shape Once, Check Every Reply
  • Temperature, Top-p and Sampling: Why the Same Prompt Gives a Different Answer
  • Open vs Closed LLMs: Cost, Control, Privacy and Capability, Decided per Workload
  • Streaming and Error Handling for LLM Calls: Show the First Word Early, Retry Politely, Fail Calmly
  • Practice: Build a CLI Chat Tool with Memory, Commands, Error Handling and a History Cap
  • Explicit Criteria vs Vague Prompts: Turn Every Adjective Into a Check a Script Can Run
  • Few-Shot Prompting Done Right: How Many Examples, How Different, What Order, and the Leak That Lies
  • Prompt Caching: Keep the Start of Every Request Identical and Pay for the Long Part Once
  • Prompt Versioning and Testing in a Repo: Prompt Files, a Registry, a Hash per Answer and Tests That Gate
  • Context Engineering: What Belongs in the Context Window, Turn by Turn
  • Context Engineering for a Long-Running Agent: Clear, Compact, Take Notes, Prove It
  • What an Embedding Actually Is: Meaning as Numbers, Search by Closeness, and Where Hand-Made Numbers Break
  • The RAG Pipeline Explained: 7 Stages From Documents to a Cited Answer
  • Similarity Search: Finding the Closest Vectors with NumPy and NearestNeighbors
  • Why RAG Exists: The Problem It Solves, Compared With Pasting Everything and Fine-Tuning
  • Real Embedding Models: an Open Model or a Provider API, Then Search, Duplicates and Recommendations
  • Chunking Strategies for RAG: Fixed Size, Sentences or Headings, Measured on One Handbook
  • Vector Databases Hands-On: The Same Search in Chroma and pgvector
  • RAG Prompt Assembly and Citations: Number the Blocks, Fit a Token Budget, Check Every Claim
  • Hybrid Search: BM25 Plus Dense Embeddings, Merged With Reciprocal Rank Fusion
  • Reranking With a Cross-Encoder: When the Second Pass Helps, and When It Doesn't
  • Retrieval Evals: Score the Retriever With Recall@K, MRR and nDCG Before Blaming the Model
  • Choosing a Vector Index: Flat, HNSW or IVF-PQ, a Memory Estimate, and Filters That Starve Small Customers
  • Citations and Abstention in RAG: What a Citation Proves, and When the Right Answer Is "It's Not in the Documents"
  • Embedding Migration With Zero Downtime: Two Indexes, a Dual-Write Backfill, a Shadow Check and a Flag
  • Cosine, Dot Product or Euclidean Distance: Why Three Measures Pick Three Winners, and the One Fix
  • Choosing an Embedding Model: Dimension, Context Length, Domain and Cost, Tested on Your Own Questions
  • Loading and Parsing Real Documents for RAG: PDF Headers, Wrapped Lines, Tables and HTML Chrome, Scored
  • Where Naive RAG Fails: Five Ways the Simplest Retriever Hands the Model the Wrong Pages
  • RAG Generation Metrics: Faithfulness, Groundedness and Relevance, One Claim at a Time
  • Context Engineering for a Long-Running Agent: Clear, Compact, Take Notes, Prove It
  • What LangChain Is For, and When to Skip It: Five Standard Parts, One Pipe, and a Decision Table
  • Why Chains Break: No Branch, No Retry, No Pause, and the Same Refund Assistant as a LangGraph Graph
  • LangGraph Nodes, Edges and State: Build Your First Graph, Route With a Conditional Edge, and Read the Run Three Ways
  • Human-in-the-Loop and Checkpointing in LangGraph: interrupt, a SQLite Save Slot and Command(resume=...)
  • Multi-Agent Patterns: Hub and Spoke in LangGraph, With Short Briefs, Owned Tools and a Retry the Hub Decides
  • A Research Agent in LangGraph: Plan, Search, Read, Write, and a Check Node That Rejects Citations Nobody Read
  • From ML Metrics to LLM Evals: Same Ruler, New Targets
  • Why You Cannot Ship an LLM Feature Without an Eval: Five Parts, Three Graders, One Tiny Eval
  • Building a Golden Dataset for LLM Evals: Cases, a Schema, a Coverage Table and a Seeded Split
  • Retrieval Evals: Score the Retriever With Recall@K, MRR and nDCG Before Blaming the Model
  • Regression Testing an LLM Bot in CI: A Golden Set, Two pytest Gates and GitHub Actions
  • Testing a RAG Bot Before It Ships: Slices, a Release Gate per Slice, and the Week After
  • RAG Generation Metrics: Faithfulness, Groundedness and Relevance, One Claim at a Time
  • LLM-as-Judge: Write a Rubric, Check Every Verdict, and Trust the Grader Only After Kappa Says So
  • RAGAS and Custom Evals: Framework Faithfulness Plus Your Own Citation and Required-Fact Checks, Behind One Gate
  • Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
  • Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
  • Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
  • A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
  • Caching for AI Apps: Four Layers, What Goes in Each Key, and How a Delete Travels
  • Semantic Caching: Why a Similarity Threshold Can't Stop Confident Wrong Answers
  • LLM Model Routing: Rules, a Classifier or a Cascade, Judged on Cost per Win and Every Topic
  • Cutting p95 and Cost in Half for an LLM App: Read the Bill, Match the Lever, Guard Success
  • Observability and Tracing for LLM Apps: A Span per Stage, Redaction First, Bad Traces Become Tests
  • Guardrails for an LLM Agent: Check What Comes In, What It Wants to Do, and What Goes Out
  • Embedding Migration With Zero Downtime: Two Indexes, a Dual-Write Backfill, a Shadow Check and a Flag
  • Design a Multi-Tenant RAG Assistant, Part 1: Requirements, Rough Numbers and a Contract
  • Design a Multi-Tenant RAG Assistant, Part 2: Tenant Isolation, a Scoped Cache and Walking an Outage
  • A 500 MB PDF Takes 50 s to Answer, Get It to 2 s: Measure First, Then Promise Per Path
  • A 500 MB PDF From 50 s to 2 s, the Fast Path: Queue, Status, Streaming and an Acceptance Test That Fails
  • Guardrails for an LLM Agent: Check What Comes In, What It Wants to Do, and What Goes Out
  1. Blog
  2. /
  3. AI Engineering
  4. /
  5. Retrieval and RAG

Where Naive RAG Fails: Five Ways the Simplest Retriever Hands the Model the Wrong Pages

A naive retriever (300-character chunks, cosine, top 2, no minimum score, every file in the folder) fails five ways on one handbook: PTO never finds annual leave, the ethics line is cut in half, the 2023 edition comes back at 0.70 next to today's 0.73, a two-part question gets one fact, and parking returns chunks at 0.22 anyway.

Chaand Sheikh

·27 November 2026Retrieval and RAG

What you will learn

  • Build the simplest RAG retriever and name each shortcut it takes
  • Reproduce five failures: different words, a cut sentence, an old version, a two-part question and nothing to find
  • Read every failure in the retrieved chunks before the model writes a word
  • Match each failure to the fix it points at

Before you start

  • The RAG Pipeline Explained
  • Chunking Strategies for RAG

The simplest RAG retriever works in a demo and fails in production. In this article we build that retriever on purpose, ask it five questions about a small company handbook, and watch it hand the model the wrong pages five different ways.

The useful part: every one of these failures is visible in the retrieved chunks, before the model writes a single word. That's where you look first.

The new intern at the filing cabinet

Picture a new intern at the filing cabinet. Fast, eager, and takes every request literally.

  • You ask for the PTO rules, but the folder says "annual leave", so the intern finds nothing.
  • The answer starts at the bottom of one page and ends on the next, and the intern brings only one page.
  • Last year's binder is still on the shelf, and it comes back too.
  • Your question needed two folders, and the intern brings one.
  • When nothing fits, the intern never says no. Something always comes back.

Naive RAG is exactly this intern, and the model then answers from whatever it was handed.

naive_rag.py: the simplest retriever

Two files, the current Brightfield handbook and an archived 2023 edition that was never removed from the folder, give us 22 chunks. They're embedded with all-MiniLM-L6-v2 and compared with cosine. No API key is needed.

"""A naive RAG retriever: fixed-size chunks, plain cosine, top k, no checks.
Every shortcut here is one of the failure modes in fails.py."""
import pathlib
import re

import numpy as np
from sentence_transformers import SentenceTransformer

HERE = pathlib.Path(__file__).parent
model = SentenceTransformer("all-MiniLM-L6-v2")


def load(name):
    text = (HERE / name).read_text(encoding="utf-8")
    text = re.sub(r"^#.*\n", "", text, flags=re.M)          # drop the headings
    return re.sub(r"\s+", " ", text).strip()


def chunk(text, size=300):
    # cut every 300 characters, wherever that lands
    return [text[i:i + size] for i in range(0, len(text), size)]


def build(files=("handbook.md", "handbook-2023.md")):
    chunks = [(f, c) for f in files for c in chunk(load(f))]
    vecs = model.encode([c for _, c in chunks], normalize_embeddings=True)
    return chunks, vecs


def search(index, question, k=2):
    chunks, vecs = index
    scores = vecs @ model.encode([question], normalize_embeddings=True)[0]
    top = np.argsort(-scores)[:k]
    # no minimum score: the top k always go to the model
    return [(*chunks[i], round(float(scores[i]), 2)) for i in top]

Five shortcuts, and each one becomes a failure:

  1. load drops the headings, so chunks lose their section names.
  2. chunk cuts every 300 characters, even in the middle of a sentence.
  3. build indexes every file in the folder, including the 2023 handbook.
  4. search keeps only the top two chunks.
  5. There's no minimum score. Whatever comes back always goes to the model.

fails.py asks five questions, each with the words the answer needs, and prints what comes back with a verdict:

CASES = [
    ("1 words differ", "What is our PTO allowance?", "twenty-five days"),
    ("2 cut in half", "Who do I call about harassment at night?", "ethics line, which is open at all hours"),
    ("3 two versions", "How many unused leave days can I carry over?", "up to five unused days"),
    ("4 needs two pieces", "What do I get for meals on a trip and for courses each year?", ["forty euros", "one thousand euros"]),
    ("5 nothing to find", "What is the parking policy?", None),
]

Failure 1: the words differ

What is our PTO allowance? The answer needs "twenty-five days" from the annual leave section. The top chunk is about the learning budget, at 0.42. The second is the meal allowance, at 0.31. Missed: annual leave never shows up.

The handbook never uses the word PTO. A small embedding model doesn't link the two, so the right section scores too low.

Failure 2: the answer is cut in half

Who do I call about harassment at night? The answer is the confidential ethics line, "which is open at all hours". Now look where the 300-character cut fell:

end of one chunk:   ... If you see or experience a problem, speak to your manager, the
start of the next:  people team or the confidential ethics line, which is open at all hours ...

The retriever brings back the start of the code of conduct (0.35) and a security chunk (0.23). Missed: the ethics line isn't in the top two, because neither half carries the whole answer.

Failure 3: two versions disagree

How many unused leave days can I carry over? Today's answer is "up to five unused days". The current handbook comes first at 0.73. But right behind it, at 0.70, is the 2023 edition: twenty days of leave and up to ten unused days to carry over.

The answer is found, but the 2023 version is sent too. The model now sees two different rules for the same question, and nothing tells it which one is current.

Failure 4: it needs two pieces

What do I get for meals on a trip, and for courses each year? This needs two facts from two sections: forty euros a day, and one thousand euros a year. The top chunk (0.35) is mostly about remote work, and only its last words start the expenses section, cut off at "A daily meal a". The second chunk (0.31) has the learning budget.

Missed: 1 of 2 facts. With k=2, a half-relevant chunk took the second seat, and forty euros never came back.

Failure 5: there is nothing to find

What is the parking policy? The handbook has no answer at all. The retriever still returns two chunks: the meal allowance at 0.22 and remote work at 0.19.

Nothing relevant, but chunks are still sent. The best score is only 0.22, and the model gets these chunks anyway. A confident, made-up answer is now just one step away.

Where each failure enters the naive pipeline every filein the folder cut every300 chars cosine, top 2no minimum model 3 old version0.70 next to 0.73 2 cut in half"...manager, the" 1 words differPTO vs annual leave 4 needs two piecesk=2 gets 1 of 2 facts 5 nothing to findbest 0.22, still sent
Each shortcut in naive_rag.py lets one failure in. Scores are from the lecture's run of fails.py.

Five failures, five directions

Put all five side by side. Each one points somewhere different, and none of them is "use a bigger model":

QuestionNaive resultDirection
PTO allowanceMissedMatch words too: keyword or hybrid search, query rewriting
Ethics line at nightMissedChunk on sentences and sections, with some overlap
Carry-over daysFound, but the 2023 version is sent tooMetadata: a version or date, and filter out archived files
Meals + coursesMissed (1 of 2 facts)Retrieve more, then rerank, or split the question
ParkingNothing relevant, but chunks are still sentA minimum score, and permission to say "I don't know"

Each direction has its own article: hybrid search, chunking strategies, metadata filters in a vector database, reranking, and citations and abstention.

Common mistakes

  • Blaming the model first. In all five cases the model never had a chance; the wrong chunks were already in the prompt. Check retrieval first.
  • Indexing a whole folder blindly. Archived and draft files compete with the current ones, at almost the same score.
  • Cutting by character count. A 300-character knife doesn't know where a sentence ends.
  • A tiny fixed k. Two seats is not enough for a question that needs two sections and gets one half-relevant chunk.
  • No floor. Without a minimum score, "nothing found" silently becomes "here are two random chunks".

Quick recap

  • Different words, cut sentences, old versions, two-part questions and missing answers all break naive retrieval.
  • Every one of them shows up in the retrieved chunks, before the model writes a word.
  • So the first check is always: does the top k hold the words the answer needs?

Try it yourself

Run python fails.py and read all five verdicts. Then change one setting: k=5 in search(), or remove handbook-2023.md from build(), and see which cases recover. Finally, add a question of your own, with the words its answer needs.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in AI Engineering · 33 of 66

Previous
Loading and Parsing Real Documents for RAG: PDF Headers, Wrapped Lines, Tables and HTML Chrome, Scored
Next post
RAG Generation Metrics: Faithfulness, Groundedness and Relevance, One Claim at a Time

Related course on Udemy

Become an AI Engineer: LLMs, RAG, Agents and MCP

Build real AI systems in Python: LLM APIs, RAG, evals, agents and MCP.View on Udemy ↗: Become an AI Engineer: LLMs, RAG, Agents and MCP (paid course, opens in a new tab)

Related posts

What an Embedding Actually Is: Meaning as Numbers, Search by Closeness, and Where Hand-Made Numbers Break

A customer types "I cannot log in" and keyword search finds nothing, although a password-reset article exists. Turn meaning into numbers by hand, find the nearest point with math.dist, build a three-topic toy embedder that finds the right article at 1.00, and watch it score 0.00 on "I can't get into my account".

The RAG Pipeline Explained: 7 Stages From Documents to a Cited Answer

Ingest, chunk, embed, store, retrieve, rerank and generate, in one Python file. Follow one question through a 26-chunk employee handbook to an answer that cites its source.

Similarity Search: Finding the Closest Vectors with NumPy and NearestNeighbors

Ask one question of a whole collection of vectors: which items are closest to this one? Normalise, score every row with one matrix multiply, keep the top k or everything above a threshold, and check it with NearestNeighbors.

Why RAG Exists: The Problem It Solves, Compared With Pasting Everything and Fine-Tuning

A smart model has never read your company's files, and they change every month. Three ways to give it the facts: paste everything, fine-tune, or retrieve only the right pieces. Follow a refund-policy question through all three and see why RAG wins when documents change.

On this page

  • The new intern at the filing cabinet
  • naive_rag.py: the simplest retriever
  • Failure 1: the words differ
  • Failure 2: the answer is cut in half
  • Failure 3: two versions disagree
  • Failure 4: it needs two pieces
  • Failure 5: there is nothing to find
  • Five failures, five directions
  • Common mistakes
  • Quick recap
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Become an AI Engineer: LLMs, RAG, Agents and MCP

Build real AI systems in Python: LLM APIs, RAG, evals, agents and MCP.View on Udemy ↗: Become an AI Engineer: LLMs, RAG, Agents and MCP (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.