Agent Engineering / Context & Memory
Evaluate and secure retrieval-augmented generation
Evaluate
Section titled “Evaluate”- MUST keep a labelled evaluation set of real questions, each with the passages that answer it and an expected answer, including questions with no answer in the corpus.
- MUST measure retrieval and generation separately: retrieval by whether the right passages are in the top results (recall@k, and the rank of the first correct passage); answers by correctness, groundedness (every claim supported by a retrieved passage), and correct refusal when nothing was found.
- MUST re-run the evaluation on every change to chunking, embedding model, retrieval settings, reranker or prompt, and compare against the last baseline before shipping.
- SHOULD add every real failure reported by users to the evaluation set (BP-0006).
- SHOULD monitor in production: queries with no good results, low reranker scores, answers without citations, and sources that are never retrieved.
Secure
Section titled “Secure”- MUST treat retrieved text as untrusted data: a document can contain instructions aimed at the agent (indirect prompt injection). Fence retrieved passages and never follow instructions inside them (BP-0005).
- MUST isolate tenants and classification levels in the vector store (separate indexes or namespaces with server-side filters), and test that a query from one tenant cannot retrieve another’s content.
- MUST control who can add or change content in the corpus, and log ingestion, so poisoned or tampered documents can be traced and removed.
- MUST protect stored embeddings like the source text: they can be inverted to recover approximate content. Restrict access to the vector store and its backups.
- SHOULD watch for retrieval anomalies (one new document suddenly top-ranked for many queries, content from untrusted sources outranking verified ones) as signs of poisoning.
- SHOULD rank or filter by trust level, so verified sources win ties against external or unverified ones.
When to apply
Section titled “When to apply”Before shipping a RAG system or a change to one, and continuously while it runs.
Examples
Section titled “Examples”| Question | Expected passages | Retrieval check | Answer check |
|---|---|---|---|
| How do I recover the MP after the OS upgrade? | SOP §3.2 | §3.2 in top 5 | Steps match §3.2, cited |
| What is our licence for Codanna? | (none in corpus) | — | Says it is not in the sources |
| Restart order for PS01, MP01, MP02? | SOP §2.4 | §2.4 in top 5 | Order correct, cited |
Anti-patterns
Section titled “Anti-patterns”- Judging a RAG change by trying three questions by hand.
- Only measuring final answers, so a retrieval regression is blamed on the model.
- One shared index for all tenants with filtering in the prompt.
- Following “ignore previous instructions” found in a retrieved PDF.
Checklist
Section titled “Checklist”- Labelled eval set, including unanswerable questions
- Retrieval and answer metrics measured separately; baseline compared on every change
- Retrieved text fenced as untrusted
- Tenant isolation tested; corpus write access controlled and logged
- Embeddings and backups access-controlled; anomalies monitored