Skip to content

    Forward Deployed Engineer

    Patterns: Retrieval, Hybrid Search and Documents

    Three AI design patterns for answering from documents: retrieval with citations, hybrid keyword and vector search, and a document-processing pipeline.

    By Published 9 min read

    • fde
    • solution-architect
    • patterns
    • rag
    • retrieval
    Share

    This lesson is part of AI Solution Architect: Design Method and Patterns. Enroll for free, then sign in, to read it in full.

    What you'll learn: three patterns for answering from documents (retrieval with citations, hybrid retrieval, and a document-processing pipeline): when to use each, how it fails, how to evaluate it and what it costs.

    At a glance

    Figure 1. The answer patterns around the policy library

    Answering from the policy library: retrieval, hybrid search and ingestionOrchestrator to Retriever (question); Retriever to Document store (current versions); Orchestrator to Model gateway (passages, ids); Worker to Document store (ingest)Orchestrator: asks, then citesOrchestratorasks, then citesModel gateway: answer with citationsModel gatewayanswer withcitationsRetriever: 4 cited, 5 hybridRetriever4 cited, 5 hybridDocument store: 62 policies, versionedDocument store62 policies,versionedWorker: 6 ingestion pipelineWorker6 ingestionpipelinequestioncurrent versionspassages, idsingest

    How to read this: the Retriever searches only current versions in the Document store, the Orchestrator gives the model the passages with their ids, and a Worker keeps the store correct in the background.

    • Retrieval with citations answers from the current text and shows where each claim came from.
    • Start with keyword search; add vectors only when your golden set (fixed test questions with known right answers) shows misses.
    • A document pipeline decides which version is current before any search.

    Scenario

    Composite scenario, not a real company. At Lumen Industrial Supply, a fictional distributor, agents answer 3,360 policy questions a month (illustrative) from 62 documents. Nine exist in several versions, and an old version is still searchable on the intranet. The policy owner's demand: never misquote or invent policy. A return question needs P-RET-01 version 3 (30 days), not the superseded version 2 (14 days).

    What you will be able to do

    • Choose among cited retrieval, hybrid retrieval and a document pipeline.
    • Name the metadata that makes "current version only" enforceable.
    • Say how each pattern fails and how to measure it.

    Prerequisites

    Core ideas

    Pick a pattern from the requirement

    Figure 2. Which answer pattern fits

    flowchart TD accTitle: Choosing an answer pattern accDescr: If the answer is not in documents, fetch it from a system instead. If the documents change or have versions, add a document-processing pipeline first. Then if keyword search meets the target on the golden set, use cited keyword retrieval; otherwise use hybrid retrieval. A{"Answer lives in documents?"} -- no --> X["Fetch from a system: previous page"] A -- yes --> B{"Documents change or have versions?"} B -- yes --> P["Add a document-processing pipeline"] B -- no --> C P --> C{"Keyword search meets the target on the golden set?"} C -- yes --> K["Retrieval with citations, keyword only"] C -- no --> H["Hybrid retrieval with citations"]

    How to read this: add the pipeline before search whenever versions exist.

    Cited retrieval Hybrid Pipeline
    Solves Answers you can check Missed paraphrases Wrong or stale versions
    Needs Metadata, citation check Embeddings, vector index Parser, version rule
    Cost grows with Passages per request Documents and queries Changes to documents
    Check with Golden questions Same set, both ways Counts and a test

    Pattern 4: Retrieval with citations

    • When to use: answers must come from changing documents and the user must be able to check the source.
    • When not to: the answer is a field in a system (fetch it), or a few short, stable pages fit in the prompt.
    • Structure: the Retriever to Document store to Model gateway path in Figure 1.
    • Failure modes: a superseded passage retrieved; an answer saying more than the passage; a citation that does not support the claim; an answer where it should refuse.
    • How to evaluate: golden questions with the expected policy id and version; judge retrieval (right passage returned?) apart from the answer (cited and supported?); include questions the library cannot answer.
    • Cost profile: one model call with the question plus a few passages; passages are the main cost.
    • Minimal build: metadata per document (policy id, version, effective date, status); search filtered to current versions inside the query; three to five passages passed in with ids; code checks every cited id was supplied; refuse below a relevance floor.
    • Used in the Order and Policy Assistant: yes: the core of policy answers and the defence against the version 2 trap.

    Pattern 5: Hybrid retrieval

    • When to use: users ask by exact terms (a policy id) and by meaning, and keyword search alone misses on your golden set.
    • When not to: keyword search already meets the target; vectors add an index, embedding cost and a second thing to evaluate.
    • Structure: the Retriever in Figure 1: two ranked lists merged into one.
    • Failure modes: a merge that buries a good exact hit; near-identical versions scoring alike; an index that lags the documents.
    • How to evaluate: run the same golden set with keyword alone and with hybrid; adopt it only if the gain justifies the cost.
    • Cost profile: embeddings for every document and query, plus a vector index to host and refresh.
    • Minimal build: keyword first; list its misses; add vector search; merge the lists with a simple rule such as reciprocal rank fusion; rerun the golden set (search for RAG).
    • Used in the Order and Policy Assistant: not in the MVP (minimum viable product, the first release). Policy questions use ids and fixed phrases, so keyword search starts; vectors only if evaluation shows a need.

    Pattern 6: Document-processing pipeline

    • When to use: documents arrive or change and must be parsed, checked, labelled and stored before anything uses them.
    • When not to: a small one-off set you can load by hand, or content that is already structured data.
    • Structure: the Worker to Document store path in Figure 1.
    • Failure modes: a superseded version indexed as current; a parser dropping tables; an unnoticed failed run; missing metadata hiding a document.
    • How to evaluate: document counts in and out match, a spot check of parsed text against the source, and a test that fails if a superseded document is returned.
    • Cost profile: off the request path; mostly engineering and storage; model calls only to extract fields, once per change.
    • Minimal build: a loader, a parser, a required-metadata check, a version rule (the latest version whose effective date has passed is current, older ones are marked superseded) and a report of changes (ingestion).
    • Used in the Order and Policy Assistant: yes, small: load the 62 documents, mark superseded versions, report the nine multi-version policies. No model is needed to start.

    In the interview: "How do you stop the assistant quoting an outdated policy?" A strong answer puts the version decision in metadata, filtered inside the search, with a test that fails if a superseded version is returned.

    Worked example

    Assumptions: illustrative question and passages. P-RET-01 version 3 says 30 days with a 15 percent restocking fee for opened non-defective items; version 2 (superseded) says 14 days.

    Step Without a version filter With a version filter and citations
    Search "return window days" v2 and v3 both match; v2 may rank first Only v3 is searchable
    Passages sent Possibly v2 v3 with id P-RET-01 v3
    Answer to "opened pump, 20 days" May say 14 days: outside the window 30 days, inside; 15 percent fee if not defective; cites P-RET-01 v3
    Check None Code confirms the cited id was supplied
    NOTE

    "Can we extend a warranty to 36 months?" Assume no passage covers extensions. Only P-WAR-02 (12 and 24 months) is found and it does not answer, so the assistant refuses and names it as the nearest policy.

    Spot the flaw. A team indexes all 62 documents including old versions and writes in the prompt: "If several versions match, use the most recent one." What is wrong?

    Answer

    The version decision is left to the model, which cannot be tested reliably. Mark each document's status at ingestion, filter to current versions inside the search, and test that a superseded one is never returned.

    Decision exercise. Agents search by policy id (P-WAR-02) and by phrases such as "how long is the cover on a pump". Choose and justify:

    • (A) vector search only.
    • (B) keyword first, measure on the golden set, add vectors only if paraphrased questions miss.
    • (C) hybrid from day one.
    Model answer

    Choose B. Ids and fixed phrases suit keyword search, which is simple and easy to evaluate. A can miss exact ids; C pays for embeddings before any evidence of need.

    Practice task

    Add to your pattern shortlist (artifact 2, second part) three rows for cited retrieval, hybrid retrieval and the document pipeline: yes or no, one sentence of reason, how you would evaluate it.

    Decide first, then reveal.

    Answer patterns: what would catch it (interactive when JavaScript is on)

    An answer cites an id that was never among the passages sent to the model. What catches this?

    • A prompt line telling the model not to invent ids
    • Agents noticing it in the pilot
    • Code that confirms every cited id was supplied
    Answer

    Code that confirms every cited id was supplied. Code can compare cited ids with the supplied ones. A prompt line is a request, not a check.

    P-WAR-02 gets a new version whose effective date is next month. Today an agent asks about warranty length. Which version is searchable?

    • The new version, because it is the latest
    • The one whose effective date has passed
    • Both, and the model picks
    Answer

    The one whose effective date has passed. Current means the latest version whose effective date has passed, decided by metadata, not by the model.

    A new policy file is loaded and its tables are missing from the searchable text. What would have caught it?

    • A spot check of the parsed text against the source
    • Adding vector search so tables are found by meaning
    • A prompt line telling the model to read tables carefully
    Answer

    A spot check of the parsed text against the source. The pipeline compares parsed text with the source. Vectors cannot find dropped text.

    Exercise

    For the 62 policy documents (9 with several versions), write the metadata fields, the rule that marks a version superseded, and one test that must fail if a superseded version is returned.

    Acceptance criteria: the fields include policy id, version and effective date; the rule uses metadata, not the model; the test names a concrete question and the expected id and version. Done when someone else could implement both from your note.

    Hint 1: what identifies "current"

    Use the version rule in pattern 6.

    Hint 2: a test that can fail

    Pick the return-window question. The expected answer is version 3; the test fails if any version 2 passage is retrieved.

    Common mistakes

    • Letting the model choose among versions instead of filtering by metadata.
    • Adding vector search first, with no golden set to show a need.
    • Citing ids the model made up, because no code checked them.
    • Evaluating retrieval and the answer together, so you cannot tell which failed.

    Knowledge check

    1. Why filter by version inside the search query, not afterwards in the prompt?

    A superseded passage in the prompt can still be quoted. Filtering inside the search means an old version is never a candidate.

    2. When is keyword search enough?

    When users search by exact terms such as policy ids and fixed phrases, and your golden set shows it finds the right passage. Vectors would add cost with no measured gain.

    3. Why evaluate retrieval separately from the answer?

    A wrong answer from a missing passage is fixed in search or ingestion; if the passage was there, in the prompt or the checks. Measuring them together hides which failed.

    4. What should the assistant do when the library does not support an answer?

    Refuse clearly and name the closest policy found. A confident guess is worse, because an agent may repeat it to a customer.

    5. Why run a document pipeline off the request path?

    Parsing, checking and versioning are slow and needed only when a document changes. Doing them in advance keeps the agent's request fast.

    You can now

    • Add the second part of your pattern shortlist to your design pack.
    • Choose among cited retrieval, hybrid retrieval and a document pipeline.
    • Define metadata and a rule that enforce "current version only".
    • Name each pattern's failure mode and how to measure it.

    Further reading

    Last verified: 2026-11-03

    Next

    Patterns: act safely and at scale

    Enroll to keep reading

    Lesson 3 of 6 · AI Solution Architect: Design Method and Patterns

    Three AI design patterns for answering from documents: retrieval with citations, hybrid keyword and vector search, and a document-processing pipeline.

    In the rest of this lesson

    • Practice task
    • Exercise
    • Common mistakes
    • Knowledge check
    • You can now
    • Further reading

    Enrolling is free. It unlocks every lesson in AI Solution Architect: Design Method and Patterns, tracks your progress across devices and keeps your quiz scores. The newsletter is optional.

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments