Skip to content
Agent Engineering / Context & Memory

Retrieve context with hybrid search, filters and reranking, and cite it

  • BP-0028
  • v1.0.0
  • draft
  • guideline
  • role: implementer
  • role: researcher
  • role: any
  • stage: build
  • stage: operate
  • updated 2026-11-24
  • reviewed 2026-11-24
  • next review 2027-05-24
  1. MUST enforce access control in the retrieval layer, before ranking: filter by the caller’s tenant, groups and classification server-side. Never retrieve first and ask the model to hide what the user may not see.
  2. MUST use hybrid retrieval: keyword (BM25) and semantic (embedding) search together. Keyword search finds exact identifiers, error codes and names that embeddings miss; semantic search finds paraphrases.
  3. SHOULD retrieve a wider candidate set (for example the top 50–150) and rerank it with a reranking model, then pass only the best few passages (for example 5–20) to the model.
  4. MUST apply metadata filters the question implies (product, version, date range, language, document type) instead of hoping ranking sorts them out.
  5. MUST cite every claim in the answer to the passage it came from (source and section), and quote exactly where wording matters.
  6. MUST say when retrieval found nothing relevant, or found conflicting sources, instead of answering from general knowledge as if it were sourced.
  7. SHOULD prefer the newest version when sources conflict, unless the question asks about a specific version, and say that a conflict existed.
  8. SHOULD rewrite or decompose vague or multi-part questions into focused queries before retrieving, and retrieve again when the first results do not answer the question.
  9. SHOULD keep retrieved text compact in context: passages, not whole documents; drop them once the answer is drafted (BP-0011).
  10. SHOULD use a structured index instead of text retrieval where one exists: a code index for symbols (BP-0010), a database query for records.
  11. MAY skip retrieval and load the whole source when it is small enough to fit comfortably in context; RAG is for corpora that do not.

Any agent answering from a document corpus, knowledge base or memory store.

  1. Resolve the caller’s identity and access labels.
  2. Derive filters and focused queries from the question.
  3. Run keyword and semantic search with the access and metadata filters; merge the candidates.
  4. Rerank; keep the best passages.
  5. Answer with citations; flag gaps and conflicts.

Good answer shape: “Restart the SMS_EXECUTIVE service, then check the MP status page [SOP sccm-upgrade §3.2, modified 2026-11-10]. The older runbook says to reboot the server instead [runbook mp-recovery §2, 2024-03-01]; the SOP is newer.”

Bad: an answer with no sources, mixing a 2019 procedure with the current one, from a tenant the user cannot access.

  • Vector-only search that cannot find “error 0x80070005”.
  • Stuffing the top 50 chunks into the prompt unranked.
  • Access filtering in the prompt.
  • Confident answers when nothing relevant was retrieved.
  • Access enforced server-side before ranking
  • Hybrid keyword + semantic search; metadata filters applied
  • Wide candidate set reranked; few passages passed
  • Every claim cited; gaps and conflicts stated