# Search & retrieval

Web page: https://academy.memberpress.ai/courses/prompt-engineering-101/l19/

Lesson 19 of 19 in [Prompt Engineering 101](https://academy.memberpress.ai/courses/prompt-engineering-101/), 7 min.

Video: https://www.youtube.com/watch?v=qC75UGrCimo

Claude's training data ends at a fixed date. Your company's internal documentation was never in Claude's training data to begin with. Retrieval-Augmented Generation — RAG — is the pattern that bridges both gaps.

The idea is simple: instead of asking Claude to answer from memory, you find the relevant documents yourself and put them in the prompt. Claude answers from the documents. The answer is grounded in real text you control.

**The pattern in four steps**

Step 1: The user asks a question.

Step 2: Your system searches a knowledge base — a documentation site, a support ticket database, an internal wiki — and retrieves the top three to five most relevant chunks of text.

Step 3: You inject those chunks into the prompt as context, wrapped in delimiters.

Step 4: Claude reads the chunks and answers the question based on them.

The question Claude answers is about text you provided, not about what it learned during training. The answer is only as good as the retrieval step — if you retrieve the wrong chunks, Claude answers from the wrong context.

**The prompt structure**

```
Answer the following question using only the documents provided below.
If the answer is not in the provided documents, say "I don't have that information in the provided documents."
Do not use knowledge from outside the provided documents.

<document id="1">
[retrieved text chunk 1]
</document>

<document id="2">
[retrieved text chunk 2]
</document>

<document id="3">
[retrieved text chunk 3]
</document>

Question: [user's question]
```

The `id` attribute on each document tag is optional but useful — it allows Claude to cite which document supports each claim.

**The fallback instruction**

"If the answer is not in the provided documents, say 'I don't have that information.'" This instruction is required. Without it, Claude fills gaps with training knowledge, which defeats the purpose of grounding the answer.

**Evaluating retrieval quality**

The quality of the answer is bounded by the quality of retrieval. If Claude is producing wrong answers despite the grounding instruction, the retrieved chunks probably do not contain the relevant information. Check the retrieved chunks before Claude sees them. If the right information is not there, the retrieval step — not the prompt — needs to be fixed.

**If you get stuck**

If Claude is answering from its training data despite the grounding instruction, the instruction is probably buried at the end of the prompt. Move it to the top, before the documents.

If Claude is citing document IDs that do not match the claims it is making, it is hallucinating citations. Add: "Cite only documents that contain the exact information you are using. Do not cite a document unless you can quote the sentence that supports the claim."

**Cross-reference**

L12 (Avoiding hallucinations) covers the grounding technique used here. L18 (Tool use primer) covers search as a tool — the difference is that in tool use, the retrieval happens at query time during the conversation; in RAG, the retrieval happens in your system before the prompt is sent.

**Deliverable**

Find a short document from your work — a policy page, a support article, a product specification. Paste it into the prompt template from this lesson as a single document. Ask a question whose answer is in the document. Verify that Claude cites the document. Ask a second question whose answer is not in the document. Verify that Claude returns the fallback response rather than an answer from its training data.

## Try these prompts

- Answer using only the provided documents. If the answer isn't in the documents, say "I don't have that information."
- Retrieve the top 3 relevant sections from a knowledge base about [topic], then summarize them in 2 bullets.
