Trail content
8 minEnglish narration, Portuguese subtitlesPodcast (RSS)
Chapters
  1. 0:00Opening
  2. 1:05The idea
  3. 1:38How it breaks
  4. 2:46Why it happens
  5. 3:24A challenge
  6. 4:11The treatment
  7. 5:14When to keep RAG
  8. 6:26In production
  9. 7:04Wrap-up
Transcript

Opening

A legal assistant answers questions about one services contract. Eighteen pages. About twelve thousand tokens.

The team built it the way the tutorials show. Split the contract into small chunks, turn each chunk into an embedding, store them in a vector database. For each question, retrieve the four most similar chunks, and let the model answer.

Then a user asks. Can I terminate without a penalty if the supplier delivers late? The search brings back the termination clause. It doesn't bring back the penalties clause, which sits on another page and says contractual default, not late delivery.

The model answers yes, no penalty. Clause fourteen point three says the opposite. And here's the detail that makes this a smell. The whole contract fit comfortably in the model's context. In this lesson, you'll learn to spot when retrieval is a bet you didn't need to make.

The idea

Here's the core of it. The search finds chunks that look like the question. It doesn't find the chunks you need to answer it.

Delivers late sounds close to deadlines and termination. The penalties clause talks about default, and in vector space it sits far away. So the model answers from a fifth of the contract, and it doesn't know what was left out.

When the whole document fits, let the model that read everything decide what's relevant. Not a search that only read the question.

How it breaks

Let's walk the pipeline.

It starts with material that's small and complete. One contract, every clause in it.

Then it gets split. And the split separates clauses that depend on each other. The rule is on page four, the exception is on page eleven.

The chunks become vectors, and go into the database.

For each question, the search picks a few. And it misses when the words don't match, even when the meaning does.

And the model answers from a fraction of the material, with full confidence. Nothing in the prompt tells it that clause fourteen exists.

So, the signs. The total content is small, tens of pages, and would fit whole in the context window.

There's chunking, embeddings and a vector database, for a handful of documents.

The wrong answers trace back to the search missing the right passage. Especially questions that combine distant parts of the document.

And the team spends more time tuning chunk sizes than solving the user's problem.

Why it happens

Nobody builds this out of carelessness. There are good reasons.

RAG became the default answer for AI over documents. It's the first architecture every tutorial shows.

Context windows grew. What needed retrieval a few years ago now fits whole, with room to spare.

It was designed for future scale. What if there are a thousand contracts? Maybe there will be. Today there's one.

And the cost of context was misjudged. Sending the whole document on every question sounds expensive, until you count prompt caching.

A challenge

Here's one for you. The assistant misses a question because the exception clause didn't come back from the search. A colleague proposes going from four chunks to eight per question. The whole contract is twenty four chunks. What do you say?

Eight chunks fixes this question. The next one may depend on the ninth. You're still betting that the search is right, for material that already fit whole.

And swapping the embedding model doesn't solve it either. A better embedding brings similar words closer. It doesn't connect a clause to an exception that looks nothing like the question. With twelve thousand tokens, send everything, and measure it on the eval.

The treatment

The treatment is the next lesson's refactoring. Replace RAG with direct context. Send the whole document, and use prompt caching so you don't pay full price for reading it on every question.

One detail decides whether the cache works. The document has to sit at the start of the prompt, byte for byte the same on every call.

The question comes after. If the question comes first, the start of the prompt changes every time, and the cache never hits.

A team learned that the hard way. They switched to the whole contract, and the bill went up far more than expected. The trace showed the question sitting in front of the contract. The fix wasn't going back to RAG. It was moving one line.

What you get back is worth it. The model sees the links between clauses. There's no chunking, no index, no retrieval to tune. And the citations get more precise, because the model sees each clause with its number and its page.

When to keep RAG

Now the other side. This isn't a rule against RAG.

If the material doesn't fit, or grows fast, you need retrieval. A knowledge base of four thousand articles that changes every week, with hybrid search, is not this smell. There, retrieval pays for itself.

Access control is the subtle one. An HR handbook with thirty pages fits easily. But if each employee may only see the section for their own role, sending everything shows the model sections that person must not see. Filtered retrieval, or a context built per role in code, is how you enforce the permission.

And if caching doesn't apply to your traffic, and the question volume is very high, work out the cost per question before you decide.

And the common mistake runs the other way too. A forty page manual, questions about isolated sections, retrieval almost always right, low cost. Small material alone isn't a reason to rebuild it. Run both versions on the eval. If direct context is more accurate at the same cost, switch. If they tie, keep the one that's simpler to maintain.

In production

What to watch. In the eval, tag every wrong answer by cause. Was the right passage in the prompt or not? If most errors are passages that never arrived, that's this smell, in numbers.

Keep a set of questions that need two distant sections, like the rule and its exception. Those are the ones chunking breaks first.

And after the switch, watch the cache hit rate in the trace. A rate near zero means something in the start of the prompt is changing. A date, a user name, or the question in the wrong place.

Wrap-up

So here's the idea to take with you. Retrieval is a bet that the search will find what the answer needs. When the document fits in the window, you don't have to place that bet. Give the model the whole thing, and let it decide what matters.

In the next lesson, we'll do the refactoring step by step, safely, with the cache in the right place: replace RAG with direct context. See you there.

SmellDispensables

RAG for Small Data

RAG Desnecessário

RAG for Small Data is an AI code smell, a sign of trouble in LLM systems, in the Dispensables group. A vector search pipeline for 20 pages that fit entirely in the context.

Element
21/37
Level
Beginner
Read
3 min
Updated
On this page 7
  1. 01Signs and symptoms
  2. 02Reasons
  3. 03Cost of ignoring
  4. 04Treatment
  5. 05Payoff
  6. 06When to ignore
  7. 07Is it this smell?
  8. ··Quick answers

Signs and symptoms

A legal assistant answers questions about an 18-page services contract. The architecture (anonymized):

contract.pdf (18 pages, ~12,000 tokens)
  -> split into 500-token chunks
  -> embeddings in a vector database
question -> retrieve the 4 most similar chunks -> model answers

Question: “Can I terminate without a penalty if the supplier delivers late?”. The search brought back the termination clause, but not the penalties clause, which sat on another page and said “default” instead of “late delivery”. The model answered “yes, no penalty”. Clause 14.3 said the opposite.

The whole contract fit comfortably in the model’s context.

Signs of RAG for Small Data:

  • The total content is small (tens of pages) and would fit whole in the context window.
  • The pipeline has chunking, embeddings, and a vector database for a handful of documents.
  • Wrong answers happen because the search missed the right passage.
  • Questions that require combining distant parts of the document fail.
  • The team spends more time tuning chunking than solving the user’s problem.
flowchart LR
  D(["1. 18-page contract"]):::io --> C["2. Split into chunks"]:::tool
  C --> V[("3. Vector database")]:::store
  Q(["Question"]):::io --> S["4. Retrieve 4 chunks"]:::tool
  V --> S
  S --> M(["5. Model sees 20% of the contract"]):::llm
  1. The material is small and complete.
  2. It gets split, and the split separates clauses that depend on each other.
  3. The chunks become vectors.
  4. The search picks a few, and misses when the words do not match.
  5. The model answers from a fraction of the material, without knowing what was left out.

The search finds chunks that look like the question. It does not find chunks needed to answer. “Delivers late” is close to the deadlines and termination clauses. The penalties clause talks about “contractual default” and sits far away in vector space. When the whole document fits, the model that read everything decides what is relevant, not the search that only read the question.

Check +20 XP on first tryThe legal assistant misses a question because the exception clause did not come back from search. A colleague proposes going from 4 to 8 chunks per question. The contract has 24 chunks in total. What do you say?

Reasons

  • RAG became the default for “AI over documents”. It is the first architecture tutorials show.
  • Context windows grew. What needed retrieval a few years ago now fits whole.
  • Designed for future scale. “What if there are a thousand contracts?” Maybe there will be; today there is one.
  • Context cost misjudged. Sending the whole document seems expensive, before counting prompt caching.

Cost of ignoring

  • Wrong answers when retrieval misses the relevant passage, especially for questions that span sections.
  • Complexity without return. Chunking, embeddings, an index, and reranking to maintain.
  • Low trust. The user does not know whether the answer considered the whole document.

Treatment

Refactoring Choose it when
Replace RAG with Direct Context The material fits comfortably in the window. Send the whole document and use prompt caching so you do not pay for reading it on every question. Target: Prompt Caching.

For the cache to hit, the document has to sit at the start of the prompt, identical on every call. The question comes after. If the user’s question is first, the prefix changes every time and the cache never hits.

Check +20 XP on first tryThe team swapped RAG for the whole contract in the prompt. The bill rose much more than expected. The trace shows the user's question comes before the contract in the prompt. What is the diagnosis?

Payoff

  • The model sees the whole document, including the links between clauses.
  • Fewer parts: no chunking, no index, no retrieval tuning.
  • With prompt caching, low cost and latency per question after the first.
  • More precise citations, because the model sees each passage’s page and clause.

When to ignore

  • The material does not fit or grows fast. Thousands of documents, or a base that changes daily, need retrieval. See RAG.
  • Per-passage access control. If each user may only see parts of the material, filtered retrieval is how you enforce the permission.
  • Very high question volume without caching. If caching does not apply to your case, work out the cost per question before deciding.

Is it this smell?

Check +20 XP on first tryA knowledge base has 4,000 articles and grows every week. The team uses RAG with hybrid search. Is this RAG for Small Data?

Check +20 XP on first tryAn assistant answers questions about a 40-page manual. Questions are about isolated sections, and retrieval is almost always right. Cost per question is low. Is it worth switching?

Check +20 XP on first tryThe system sends the whole contract on every question, with no caching, and each user asks 30 questions per session on average. What is the fix?

Check +20 XP on first tryAn HR app answers questions about a 30-page internal handbook. Each employee may only see the section for their own role. Is this RAG for Small Data?

Quick answers

What is RAG for Small Data?

RAG for Small Data is an AI code smell, a sign of trouble in LLM systems, in the Dispensables group. A vector search pipeline for 20 pages that fit entirely in the context.

How do you fix RAG for Small Data?

With Replace RAG with Direct Context. Each refactoring has safe step-by-step mechanics with an eval before and after.

Where does RAG for Small Data show up in practice?

In the real-world scenarios Legal assistant.

Go further

Relations

Refactorings that treat it 1
Shows up in scenarios 1
Part of the tracks 1
Search