Applied AI Architect study guide covering retrieval modes, hybrid retrieval, Reciprocal Rank Fusion (RRF), cross-encoder reranking, untrusted context & refusal gates, Agentic RAG & memory, GraphRAG, Google Cloud RAG, federated vs. ingested architectures, ACL security, semantic caching, and evaluation.
Test Yourself: RAG Practice Quiz →Retrieval-Augmented Generation (RAG) pairs an LLM's parametric knowledge with an external retrieval system. At query time it finds the relevant passages, injects them into the prompt and asks the model to answer only from that context, with citations. The model is grounded on private, current data without fine-tuning, and every claim can be traced to a source.
Fine-tuning is a semester of study that teaches a student how to think and speak like a specialist. RAG hands that student an open-book exam with exactly the right pages bookmarked.
| Approach | Best For | Update Speed | Cost per Query | Traceability |
|---|---|---|---|---|
| Fine-tuning | Tone, format, behavior, output schemas | Hours to weeks (retrain) | Low inference, high training | None: facts can't be traced to weights |
| Long-context stuffing | Whole-document reasoning on a small corpus | Instant | High: grows with prompt size | Coarse |
| Context caching | Reusing a large, fixed prefix | Minutes | Lower (cached input discount) | Coarse |
| RAG | Facts from large, changing, permissioned reference corpora | Seconds to minutes (index update) | Low: ~1.5k–3k relevant tokens | Exact (doc, chunk, page) |
| Live tool call (API / SQL) | Live transactional state (order status, stock levels, account balances, booking availability) | Real-time (system of record) | Low (1 API/DB call) | Exact (record ID + timestamp) |
Cost grows linearly with input tokens, time to first token grows with prompt length, recall degrades well before the advertised window is full ("lost in the middle"), and you cannot apply per-user ACLs or exact citations to one giant prompt. The production answer is often both: RAG narrows millions of documents to a few full sections (tens of thousands of tokens), then a long-context model reasons across them without fragmenting the evidence into tiny chunks.
Information retrieval offers two complementary scoring families; production RAG usually runs both and fuses the rankings (see Retrieval):
| Retrieval Mode | How It Scores Relevance | Strong On | Weak On |
|---|---|---|---|
| Dense vector (semantic) | Embeds query and chunks into one vector space; ranks by cosine or dot-product distance | Paraphrase, synonyms, cross-lingual intent | Exact identifiers, rare tokens, negation |
| Sparse keyword (BM25) | Term overlap weighted by term frequency, inverse document frequency, and length normalization | Product codes, error IDs, names, legal citations | Paraphrased or vocabulary-mismatched questions |
| Hybrid | Runs both in parallel, then fuses ranks with Reciprocal Rank Fusion (RRF) | Mixed natural-language plus identifier queries | Extra latency and two indexes to maintain |
More context is not automatically better: accuracy and recall degrade as token count grows (context rot), so curate what enters the prompt instead of filling the space available. On Claude 4.5 and newer models, a request whose input plus max_tokens exceeds the window is accepted and stops with stop_reason: model_context_window_exceeded if generation reaches the limit; earlier models return a validation error unless the model-context-window-exceeded-2025-08-26 beta header is sent.
Compare three cost drivers before choosing:
RAG supplies reference facts, fine-tuning shapes behavior, long context does deep reasoning over a pre-filtered set, and tool calls fetch live transactional state.
Nearest-neighbor scores rank how close a passage's meaning is to the query; they carry no information about whether the passage is current. An indexed copy of a mutable record (an order, a price, a balance) is a snapshot frozen at ingestion time, so it can never be authoritative. Keep reference knowledge in RAG and query live state through API/SQL tools against the system of record.
| Phase | Steps | Key Rule |
|---|---|---|
| Offline: ingest and index | Parse → chunk → attach metadata (doc_id, page, date, acl) → embed → store vectors, text, and metadata |
Expensive work happens once, so online queries stay fast |
| Online: retrieve and generate | (Rewrite) → embed the query → hybrid search for top-K → rerank to top-N → build the prompt → generate with citations | Embed queries with the same model and version as the corpus |
Understanding the progression from Naïve to Modular RAG clarifies where pre-retrieval, post-retrieval, and agentic orchestration sit:
| Paradigm | Shape | Adds | Weakness |
|---|---|---|---|
| Naïve | index → retrieve → generate |
Basic chunking + vector search | Noisy context, low precision and recall |
| Advanced | Linear, with pre- and post-retrieval stages | Query rewriting, hybrid search, reranking, compression | Fixed one-shot path |
| Modular | Composable, non-linear modules | Routing, iteration, memory, agentic loops | More complexity, latency, and evaluation cost |
Agentic RAG isn't a fourth official paradigm. It's an implementation of modular RAG in which an agent orchestrates the modules.
Bad parsing corrupts everything downstream, and silently: if a table is dropped or a scan is misread, the LLM won't complain—it will invent plausible facts.
pypdf) work for clean, digital, single-column PDFs. They return nothing on scans and scramble tables.pypdf unless configured otherwise).| Chunking Strategy | How It Works | Use When |
|---|---|---|
| Recursive character / fixed-size (baseline) | Split on paragraphs, then lines, then words | Default starting point for uniform text lacking structural markers |
| Overlap | Neighboring chunks share ~10–20% | Facts that span boundaries |
| Semantic | Split where embedding similarity between sentences drops (topic shift) | Long, continuous narrative prose where fixed windows slice ideas in half |
| Structure-aware | Split Markdown by headings, source code by AST/function/class, and legal docs by clause; keep tables whole | Codebases, docs with markup, manuals, tables |
| Parent-child (hierarchical) | Embed small children (128–256 tokens), return the larger parent (1–2K tokens) | Precise matching and full context (clause-numbered contracts, policy docs) |
| Proposition | An LLM rewrites text into atomic facts | High-precision factual lookup |
A chunk must fit the embedding model's input limit (2,048 tokens for gemini-embedding-001 and text-embedding-005). Because autoTruncate=true by default, longer chunks are silently truncated, and their tail is never searchable.
| Index-Time Enrichment | What It Adds | Problem It Fixes |
|---|---|---|
Metadata (source, date, acl, region, is_latest) |
Structured fields on every chunk | Filtering, recency, access control |
| Contextual headers (contextual retrieval) | Document title, section path, and a short summary prepended before embedding and BM25 | Ambiguous chunks ("Revenue grew 12%": of whom, when?) |
| doc2query | LLM-generated questions each chunk answers | Question vs. passage wording gap |
| SPLADE | Learned expansion terms in a sparse vector | BM25's blindness to synonyms |
parent_id on each child, deduplicate by parent, and ACL-check the parent too.An embedding is a dense vector (typically 768–3,072 dimensions) in which texts with similar meaning sit close together, regardless of wording. Don't just say vector search "stores embeddings"—its role is Stage 1 semantic recall, retrieving conceptually matching passages even when the user's wording shares zero keywords with the document wording (bridging the vocabulary gap where BM25 returns zero hits). The embedding model sets the ceiling on semantic recall: downstream prompt engineering can't rescue a poor vector space.
| Concept | What to Know |
|---|---|
| Same model both sides | Query and corpus vectors must come from the same model and version. Otherwise scores still compute, but rankings are near-random. |
| Task types (Vertex AI) | RETRIEVAL_DOCUMENT (+ title) for chunks, RETRIEVAL_QUERY for queries. Unset defaults to RETRIEVAL_QUERY, so the corpus gets query-style vectors. |
| Current models | gemini-embedding-001 (3,072 dims) and text-embedding-005 (768 dims); output_dimensionality truncates (Matryoshka), then renormalize. |
| Similarity vs. distance | Cosine similarity (higher = closer; equals dot product on unit-normalized vectors) vs. semantic distance (lower = closer, e.g., 1 - cos or L2). Watch cutoff direction: similarity >= τ vs. vector_distance_threshold <= d_max. |
| Domain fit | Benchmark on your labeled queries; leaderboards are only a shortlist. Add BM25 or an adaptor for jargon. |
| ANN Index | How It Works | Strength | Trade-Off |
|---|---|---|---|
| Exact k-NN | Compare with every vector | 100% recall | Linear cost; unusable past ~10⁵ vectors |
| HNSW | Multi-layer proximity graph | Best recall vs. latency | High RAM |
| IVF | k-means clusters; search the nearest n_probe |
Fast partitioning | Recall drops if n_probe is too small |
| PQ | Compress sub-vectors to codebook IDs | Large memory savings | Lossy ranking |
| ScaNN | Google's anisotropic quantization | Highest QPS; powers Vertex AI Vector Search and AlloyDB AI | Tuning required |
ef_search and IVF n_probe. Higher means more recall and more latency.float32 (1×) → float16 (½) → int8 (¼, default at 100M+ vectors) → PQ (~10–30× smaller) → binary (1/32). Pair heavy compression with oversample + full-precision rescoring.Core ANN libraries (ScaNN, Meta FAISS) power three deployment tiers:
pgvector, AlloyDB AI, BigQuery, Redis, Elasticsearch) keeping vectors and relational rows in one ACID system without dual-write sync lag."ANN recall" (agreement with exact k-NN, fixed with ef_search / n_probe) isn't "retrieval recall" (agreement with human relevance labels, fixed with chunking, embeddings, and hybrid search). Diagnose which one is failing.
Match the index to query diversity. Hybrid retrieval justifies its added compute and rank-fusion step whenever traffic blends exact identifier or clause lookups (sparse BM25) with broad conceptual questions (dense vector). Frame the architecture as a three-way balance across quality, latency, and ongoing maintenance (the operational burden of keeping indexes synchronized as the corpus scales). Both searches run in parallel over the same metadata-pre-filtered corpus, and their ranked lists are merged via RRF.
| Dimension | Dense (Vector) | Sparse (BM25) |
|---|---|---|
| Matches | Semantic recall: meaning, synonyms, paraphrases (when user wording ≠ document wording) | Lexical recall: exact terms, IDs, SKUs, error codes, clause numbers, names |
| Misses | Rare exact strings (ERR-409, §4.2(b)) |
Synonyms ("car" vs. "automobile") |
| Score Scale | Cosine in [-1, 1] | Unbounded [0, ∞) |
Both use RRF, but fuse different lists. Hybrid search fuses retrievers (BM25 + dense) for one query. RAG-Fusion fuses results from several LLM-generated query variants.
| Aspect | Bi-Encoder (Vector Search — Stage 1) | Cross-Encoder (Reranker — Stage 2) |
|---|---|---|
| Input | Query and document encoded separately | Query + document encoded together (full cross-attention) |
| Speed | Fast: document vectors precomputed, ANN lookup | Slow: one transformer pass per (query, chunk) pair |
| Role & Funnel Size | Stage 1 Recall over millions (top K ≈ 50–100 per retriever) | Stage 2 Precision: re-score RRF-fused pool (~100–150 → final top N ≈ 3–10) |
| Examples | SBERT, DPR, Vertex AI embeddings | Vertex AI Ranking API, Cohere Rerank, BGE-Reranker |
Stop adding chunks when the cross-encoder relevance score falls below a calibrated threshold τ, and abstain immediately if even the top-1 chunk falls below τ. In interviews/exams, never say "re-rank with list"—say "fuse parallel BM25 and dense lists via RRF, then re-score the fused candidates with a pairwise cross-encoder reranker."
acl_groups) and excluding stale data (is_latest = true). Vertex AI: restricts / numeric_restricts.<document> tags with its Source ID and effective_date. Instruct the LLM to treat <document> blocks strictly as untrusted passive data, never executable instructions.tools → system → messages in order, keep static tool definitions, system instructions, and pinned docs in the cached prefix, and place dynamically retrieved RAG chunks + the user query at the uncached tail (never inject per-query chunks or timestamps into system).| Defense Layer | Technique |
|---|---|
| Retrieval | Pre-filtered hybrid search + cross-encoder reranking, measured with Recall@K |
| Pre-generation refusal gate | If top cross-encoder score < τ, short-circuit and return a deterministic refusal ("No relevant documents found") |
| Context & security isolation | Deduplicate; pre-filter stale versions (is_latest = true); pass effective_date to surface conflicts; wrap chunks in <document> tags as untrusted data |
| Post-retrieval screening gate | Run a classifier on fetched passages and tool payloads prior to prompt assembly; fail closed on classifier error; cap chunks and tokens |
| Prompt & output | Closed-world rule + explicit refusal instruction; low temperature; structured output with required citations checked in code |
| Groundedness verification | Claim-level entailment check: NLI model, LLM judge Faithfulness, or Vertex AI Check Grounding API (support_score 0–1) |
| Post-generation refusal gate | Below groundedness threshold → block answer and fall back to safe refusal (showing closest sources) or human review |
| Citation Level | Mechanism | What It Guarantees |
|---|---|---|
| Level 1 (Weakest) | Free-text [n] brackets |
Nothing: numbers can be invented |
| Level 2 | Cite chunk IDs from the supplied set | The source exists (IDs checked in code) |
| Level 3 | Exact quote spans | The quoted text exists (substring check) |
| Level 4 (Strongest) | Native grounding metadata | Claim-to-source mapping from the API: Gemini groundingMetadata (chunks + supports), Claude Citations API (returns source spans without billing output tokens for quoted text) |
"The answer has citations, so it's grounded." A citation proves the source exists, not that it supports the sentence. Always check entailment (sampled, or on every response for high-stakes flows). Refusal is a first-class safety feature enforced both before generation (reranker threshold τ) and after generation (groundedness check).
A fixed pipeline fails silently when retrieval returns the wrong chunks. Agentic RAG places retrieval inside the reasoning loop so the agent decides when to search, what to query, whether the returned passages are trustworthy, and when to retry or switch tools.
effective_date, doc type, authority) to drop superseded or low-trust hits (e.g., discarding an old blog post when a current policy doc is present).| Agentic Pattern | Mechanism | Fixes |
|---|---|---|
| Corrective RAG (CRAG) | A grader labels retrieval Correct / Ambiguous / Incorrect; Incorrect triggers query rewrite + web search | Answering when the local index lacks the facts |
| Self-RAG | The generator emits reflection tokens: [Retrieve], [IsRel], [IsSup], [IsUse] |
Needless retrieval and unsupported claims |
| Adaptive RAG | A complexity router picks no retrieval, single-step, or iterative multi-hop | Over-paying on simple queries, under-retrieving on hard ones |
StateGraph carrying typed question / documents / generation state across deterministic retrieve → grade/rewrite → generate nodes for predictable control flow.ReActAgent or Google ADK Agent wrapping a hybrid + cross-encoder reranked retriever as a callable QueryEngineTool.trajectory_* metrics; ADK tool_trajectory_avg_score).| Memory Layer | What It Holds | Scope | Typical Backing Store |
|---|---|---|---|
| Short-term | Current turn history and active working context | Single session | In-memory message list |
| Episodic | User preferences, past sessions, prior trajectories ("what was tried") | Cross-session | Key-value / session store; auto-extracted via Vertex AI Memory Bank, Mem0 (auto fact extraction), or Zep (session-aware auto-summarization + entity extraction) |
| Semantic | Permanent domain knowledge searched by meaning | Cross-session / global | Vector store (Chroma locally; Vertex AI Vector Search, Qdrant, Pinecone, Weaviate, or pgvector in prod); keep separate collections for user preferences vs. domain facts |
Read → Refine → Repeat) & Salience Decay
Read → Refine → Repeat in the prompt: For long-horizon tasks, equip the agent with read/write tools backed by a section-keyed Markdown file (e.g., scratchpad.md). Instruct the agent to write its plan upfront, condense noisy tool calls into a few lines of state after each step, and explicitly re-read the scratchpad before acting—otherwise it ignores its notes and reacts only to the last chat message.scratchpad.md and edit the plan directly rather than fighting the model with long corrective chat prompts; the agent picks up the aligned state on its next read, and can also resume from the file after a crash.GraphRAG stores entities (nodes) and relationships (edges) next to—or instead of—vectors. Where vector similarity only floats topically related paragraphs to the top, a property graph (e.g., Neo4j queried via Text-to-Cypher in LlamaIndex PropertyGraphIndex or LangChain GraphQA) traverses explicit relational chains (Person -[:WORKS_ON]-> Project <-[:FUNDS]- Org) in a single deterministic hop, and builds corpus-wide summaries ("main themes across all Q3 filings") via community summaries. For purely relational queries (org charts, supply chains, legal discovery), traverse the graph directly rather than relying on vector similarity.
| Dimension | Vector RAG | GraphRAG | Hybrid (Vector + Graph) |
|---|---|---|---|
| Strength | Local semantic match | Multi-hop entity chains (org charts, supply chains, legal/financial links), global summaries | Explicit relations + grounded passage quotes |
| Cost | Low to moderate | High (entity/relation extraction, rigid schema & graph upkeep, higher latency) | Highest (two stores to sync) |
Embeddings are bad at SUM, AVG, sorting, and joins. Route quantitative questions to Text-to-SQL: retrieve the relevant schema → generate read-only SQL → execute → put the exact result in the prompt. BigQuery and AlloyDB AI can also combine SQL filters and vector search in one query. For choosing between parameterized query tools and NL2SQL, and the guardrails for model-written SQL, see Knowledge engineering: structured data tools.
Multimodal embeddings put text and images in one shared vector space, so a text query can retrieve architecture diagrams, charts, or schematics, which a multimodal generator (such as Gemini) then reads together with the text.
This guide stays vendor-neutral. Google Cloud's managed retrieval services (Agent Search, RAG Engine, Vector Search 1.0 and Agent Retrieval, Grounding with Google Search, the Ranking and Check grounding APIs, and in-database vectors) are covered in depth in the Agent Platform guide: Grounding & Retrieval. Quick decision map:
| Google Cloud Option | Choose When |
|---|---|
| Agent Search (formerly Vertex AI Search) | Turnkey managed RAG: connectors, parsing, chunking, hybrid retrieval and native ACLs with the least engineering |
| RAG Engine | Code-first managed pipeline when you need control over parsing, chunking, embeddings and the vector DB |
| Vector Search 1.0 / Agent Retrieval | Custom embeddings and ANN at large scale inside your own pipeline (you build parsing, storage and ACL restricts) |
BigQuery · AlloyDB / Cloud SQL (pgvector) |
In-database vectors: BigQuery for analytics; AlloyDB/Cloud SQL for operational data |
| Grounding with Google Search | Current public web facts (ADK google_search tool) |
Older material refers to PaLM 2, Matching Engine and Vertex AI Search. Those are now Gemini, Vector Search and Agent Search on Gemini Enterprise Agent Platform.
| Dimension | Ingested RAG (Copy into Your Index) | Federated Retrieval (Query Live Sources) |
|---|---|---|
| Freshness | Behind by the sync interval; needs change capture | Live (as fresh as each source's own index) |
| Access Control | ACLs replicated onto chunks; must stay in sync | Source enforces native permissions per user token |
| Revocations | Must be propagated; the lag is an exposure window | Immediate |
| Data Copies | Another copy of sensitive data to secure | No copy, but query text goes to each third party |
| Quality & Ranking | Best: your parsing, hybrid search, and reranker over one index | Limited by each source's search; scores aren't comparable across sources |
| Latency & Availability | Predictable; independent of sources | Fan-out: tail latency = slowest source; outages drop sources |
| Operations | Pipelines, re-embedding, migrations | Many APIs, OAuth tokens, quotas, schema changes |
Asked about quality and latency? Ingest. Asked about not copying data or live permissions/state? Federate. Both? Propose the hybrid: ingest stable, high-value corpora with ACL pre-filtering + live top-N permission re-check, and federate volatile or permission-complex systems. (Vertex AI Search connectors support both.)
Decide authorization before the prompt is built: once a restricted chunk reaches the model, no system prompt instruction reliably stops it from leaking through paraphrase.
| ACL Strategy | How It Works | Strength | Weakness |
|---|---|---|---|
| Early binding | ACL groups copied onto chunk metadata; pre-filter in search | Fast; always K authorized results | Only as current as the last sync |
| Late binding | Check each candidate against the source at query time | Always current | Slower; can return zero results |
| Hybrid (Recommended) | Pre-filter + live re-check of the final top-N only | Fast and current | More moving parts |
| Threat / Defense Layer | Architectural Control (Cheap & Fast First) |
|---|---|
| 1. Deterministic filters (~1 ms) | At ingestion and query time, strip hidden text, HTML comments, and zero-width characters; apply regex for known attack patterns. |
| 2. Small classifier (Model Armor) | Screen the user prompt and every retrieved chunk/tool payload before prompt assembly. Fail closed: halt if it errors or times out. |
| 3. Isolated generation | Wrap chunks in <document> delimiters as untrusted data; cap chunks and tokens per request. |
| 4. Output checks | PII/DLP filtering, citation validation, and grounding check before the answer is returned. |
| Confused deputy / excessive agency | Least privilege at the tool registry: read-only tools and credentials for RAG agents; no send/write tools. A system-prompt instruction is not a control. |
| Index poisoning (fake documents injected) | Ingestion approval, provenance verification, write-audit logs. |
| Cascading injection in multi-agent flows | Validate payloads at every agent handoff. |
| Update Mode | Typical Lag | Use For |
|---|---|---|
| Full rebuild | Hours | Small corpora, embedding-model changes |
| Incremental batch | Minutes to hours | Most documents (policies, wikis) |
| Streaming upsert/delete | Seconds | Fast-changing reference content (new tickets, KB articles), revocations (Vertex AI STREAM_UPDATE, required by RAG Engine) |
doc_id + chunk index), and delete all of a document's old chunks before inserting the new version (preventing orphan chunks).is_latest in metadata and pre-filter on it; run periodic reconciliation jobs.Embed the incoming query and, if it's close enough to a past query, return the stored answer (~15 ms instead of ~1.2 s).
[COMPANY] revenue in [PERIOD], keeping real values as exact-match keys so Q3 is never served for Q4.LRU only decides which entry to drop when the cache is full; a popular, outdated answer stays hot indefinitely. Pair LRU (a size policy) with a TTL or version-hash keys (a freshness policy). Provider prefix (KV) prompt caches are keyed on exact prefix bytes, so edited chunks simply miss: they bound cost, not correctness.
| Eviction / Invalidation Policy | Mechanism | Controls | Use For |
|---|---|---|---|
| TTL (time to live) | Entry expires a fixed time after it was written | Freshness (bounded staleness) | Content with a known update cadence |
| LRU (least recently used) | Evicts the coldest entry when capacity is reached | Memory size only, not freshness | Bounding cache cost under heavy traffic |
| Version-hash keys | Key includes the index version and content hashes of cited chunks; any change forces a miss | Instant invalidation on re-index or embedding-model migration | Corpora that are re-chunked or re-embedded |
| Event-driven purge | Document-update webhooks or CDC events delete entries citing the changed chunk | Near-real-time freshness | Policies, pricing, legal content |
| Online Pipeline Step (Cache Miss) | Typical Latency | Main Optimization Lever |
|---|---|---|
| Auth + group resolution | 20–50 ms | Cache group membership (short TTL) |
| Cache lookup | 10–30 ms | A hit skips everything below |
| Query rewrite | 0 or 300–500 ms | Gate it: only for follow-ups or ambiguous queries |
| Query embedding | 30–80 ms | Same-region endpoint |
| Parallel BM25 ‖ ANN | 60–150 ms | ef_search / n_probe, shard by tenant |
| Cross-encoder rerank | 100–250 ms | Fewer candidates (150 → 75), GPU batching |
| LLM time to first token | 500–1,200 ms | Fewer chunks (smaller N), prompt-cached prefix, smaller model; stream |
| Metric Type | Metric | Focus & What It Diagnoses |
|---|---|---|
| Reference-required (Offline Golden Set) | Recall@K, Precision@K, MRR, nDCG@K | Retrieval: Did we find the right chunks in the top K (headline metric), and are they ranked well? |
| Reference-required (Offline Golden Set) | Context Recall, Answer Correctness | End-to-End (Ragas): Alignment with ground-truth answers in the golden set |
| Reference-free (Online) | Faithfulness (Groundedness) | Generation: Are answer claims entailed by retrieved context? (NLI, LLM judge, or Vertex Check Grounding API support_score) |
| Reference-free (Online) | Context Relevance, Answer Relevance | Generation: Does context support the query, and does the answer address the question without drift? |
| Reference-free (Online) | Refusal Accuracy (Abstention) | Safety: Share of unanswerable/unsupported queries where the system cleanly refuses instead of guessing |
Default to the fastest deterministic check and escalate only when subjective judgment is needed:
Lock in pass/fail migration thresholds ahead of any model or index cutover, broken down by document category rather than relying on a blended mean.
| Symptom / Scenario | Root Cause → Correct Architectural Fix | Tempting Wrong Answer |
|---|---|---|
| Answer misses half a table or condition | Severed context → structure-aware or parent-child chunking, overlap | Bigger LLM |
| "What about him?" retrieves nothing useful | Conversational query → query rewriting with chat history | Raising top-K |
Exact codes or SKUs (ERR-742) not found |
Dense-only search → hybrid search (BM25 + dense) with RRF | Larger embedding model |
| High Recall@100, poor top-3 precision | Bi-encoder imprecision → cross-encoder reranking | Bigger chunks |
| Fact buried in a long prompt is ignored | Lost in the middle → fewer, better chunks at start and end | Longer context window |
Long sessions degrade, then stop with model_context_window_exceeded |
Context rot and window exhaustion → curate context, compaction, check stop_reason |
Bigger window |
| Confident answer beyond the sources | Gap filled from memory → context-only rule + abstain + grounding check | Fine-tuning on the documents |
| Multi-hop / relationship question fails | Flat chunk search → query decomposition, agentic loop, or GraphRAG | Raising top-K |
| Agent loses its plan or recalls stale preferences | Cluttered context, no decay → external scratchpad.md with Read → Refine → Repeat + memory decay |
Bigger window |
| Outdated or deleted content still returned | Ghost or orphan chunks → delete-before-insert, CDC tombstones, reconciliation job | Post-filtering results |
| Wrong live order status, stock, or balance | Mutable state in a vector index → live API/SQL tool on the system of record | Re-embedding with a larger model |
| Quality drifts with no code change | Corpus drift or an unpinned model alias → pin model versions, rerun golden evals, reindex | Bigger model |
| Rankings suddenly near-random | Query/index embedded with different models → same model and version; atomic blue/green migration | Retuning ef_search |
| User sees a document they shouldn't | Post-filter, stale ACLs, unscoped cache → pre-filter + live top-N re-check + ACL-scoped cache keys | "Don't reveal restricted data" prompt |
| Instruction hidden in a retrieved doc hijacks the model | Only user input screened → fail-closed chunk screening, delimiters, read-only tools | Input guardrail only |
| High RAG Triad scores, answers incomplete | Triad has no recall → measure Recall@K on a golden set | Tuning the generator |
| Cached answer for the wrong entity or date | Unmasked semantic cache → entity masking + cross-encoder intent check + webhook invalidation | Exact-string cache |
| Popular cached answer stays outdated after a policy update | LRU-only cache (size policy, no freshness) → TTL + version-hash keys + event-driven purge | Larger cache capacity |
A comprehensive walkthrough of the RAG production architecture, retrieval pipelines, and enterprise trade-offs.
Listen to the RAG audio deep dive or view the study guide, slide deck, and architecture infographic.
Q1. Why should live order status, inventory counts, or account balances never be served from a RAG vector index?
Q2. Why can't raw BM25 and dense cosine similarity scores be added together directly, and how does Reciprocal Rank Fusion (RRF) solve this?
Q3. Why is post-filtering unacceptable for enforcing document ACLs or excluding superseded revisions (is_latest = true)?
Q4. Input guardrails inspect the user's prompt before search. Why does that leave an enterprise RAG or agent workflow vulnerable, and what is the fix?
Q5. A semantic answer cache uses LRU eviction only. After a pricing policy changes, users keep receiving the old answer. Why, and what fixes it?
Q6. When evaluating a cheaper generator model for migration, overall Faithfulness is 0.86 (vs. 0.94 flagship), but two complex legal document classes score 0.72 against a 0.85 per-stratum floor. What should the architect do?