RAG & Data Pipelines · 2 to 3 hours
Diagnose a missing document
Trace a missing policy exception through ingestion, eligibility, and context packing without weakening access rules.
Hands-on debugging
3 h
Overview
Diagnose missing documents and incomplete answers by tracing the ingestion and query stages. You will inspect chunk metadata, document revisions, context selection, and citation references without needing a model API.
Study time: 2 to 3 hours
Interview format: Debugging exercise with deterministic fixtures
By the end you can
- Trace a document through named ingestion and query stages using recorded evidence
- Tell eligibility, retrieval, context packing, and generation failures apart
- Correct a metadata failure without weakening access rules
- Explain how a context budget can drop required evidence, and fix it
- Validate citations by identity, resolution, and claim support
Prerequisites
Helpful background: Basic TypeScript and structured logging knowledge help.
This topic covers ingestion, grounding, citations, and the document lifecycle. Embeddings & Retrieval covers how candidates are found and ranked.
Trace evidence through named stages
Record stable identifiers at each boundary. A useful trace connects source revision, parsing run, chunk set, indexing acknowledgement, publication state, retrieval candidates, selected context, and final citation references.
Each stage answers a different question. Did the parser extract the relevant sentence? Did chunking preserve it? Was the chunk indexed? Was its revision published? Did filtering exclude it? Did retrieval return it? Did context packing keep it? Did generation use it correctly?
Trace content only when necessary and permitted. IDs, statuses, lengths, revision hashes, and failure codes can often identify the issue without copying private text into general logs.
Diagnose a missing policy
Worked example
The fictional current source is returns revision 3. It contains the standard return window and a custom-product exception.
| Stage | Observed evidence | Interpretation |
|---|---|---|
| Source store | Revision 3 exists and contains both sections | Source acquisition succeeded |
| Parser | Both sections appear in extracted text | Parser preserved the needed evidence |
| Chunk builder | Section 2 created as C2 | Relevant chunk exists |
| Index lookup | C2 exists with department procurement | Index contains the chunk |
| Query filter | User is in support and only support chunks are eligible | C2 is excluded by metadata |
| Context | Only section 1 appears | Generator lacks the exception |
The first correction is to verify the intended access policy. If procurement is the correct permission, the support user must not receive the chunk. If the department metadata was mistakenly assigned and the source is authorized for support, correct the metadata through the normal publication process. Removing the filter would bypass the access rule.
Chunk boundaries and source fidelity
Inspect the text actually indexed. A parser may preserve the words but reorder a table. A chunk may include “within 7 days” without the phrase “manufacturing defects.” The resulting fragment can support a misleading answer.
Compare chunking alternatives with fixtures that require headings, exceptions, tables, and adjacent paragraphs. Keep original-source locators so you can inspect the evidence at its origin. A generated contextual summary can help retrieval, but it introduces derived text that may itself be inaccurate. Preserve the original passage and distinguish any added summary from source evidence.
Measure token counts with the selected tokenizer when budgets are token-based. Character counts are useful diagnostics but do not establish actual model input length.
Publication and repeat processing
A retry should not create duplicate published chunks. A chunk key can include tenant, document, revision, pipeline configuration, and chunk position. Content hashes help detect repeated work, while a pipeline version captures changes to parsing or splitting behavior.
Build a complete revision in a staging state. Validate its expected chunk manifest before making it eligible for current queries. A partially indexed new revision should not silently replace a complete older one.
If processing the new revision fails, retain an explicit failure state and a documented freshness policy. Whether old content remains usable depends on the product and source requirements. Do not label an older revision as current merely because it is available.
A deterministic eligibility exercise
The following fixture uses a trusted access context and an authoritative published-revision map. The department list represents access grants for the exercise. Production authorization should be enforced by trusted services or database policies as appropriate.
The fixture types and the six chunks are below. Each chunk differs from C1 in one field.
type Chunk = {
id: string;
tenant: string;
document: string;
revision: number;
department: string;
state: "published" | "staged";
deleted: boolean;
tokens: number;
};
type Access = {
tenant: string;
departments: ReadonlySet<string>;
};
// Returns the first exclusion reason, checked in this order:
// "tenant", "deleted", "unpublished", "revision", "department".
// Returns null when the chunk is eligible.
declare function exclusionReason(
chunk: Chunk,
access: Access,
publishedRevision: ReadonlyMap<string, number>
): string | null;
const access: Access = { tenant: "alpha", departments: new Set(["support"]) };
const publishedRevision = new Map([["returns", 3]]);
const base: Chunk = {
id: "C1", tenant: "alpha", document: "returns", revision: 3,
department: "support", state: "published", deleted: false, tokens: 120
};
const chunks: Chunk[] = [
base,
{ ...base, id: "C2", department: "procurement", tokens: 100 },
{ ...base, id: "C3", tenant: "beta" },
{ ...base, id: "C4", revision: 2 },
{ ...base, id: "C5", state: "staged" },
{ ...base, id: "C6", deleted: true }
];Code exercise
Chunk eligibility
Implement exclusionReason so each fixture returns its first exclusion reason, or null when the chunk is eligible. Check tenant, deletion, publication state, revision, and department, in that order.
Expected
C1 is eligible. C2 is excluded by department, C3 by tenant, C4 by revision, C5 by publication state, and C6 by deletion.
Limitations
This helper evaluates one in-memory snapshot and returns the first exclusion reason. It does not implement concurrency, authentication, retrieval ranking, or protection against permission changes after the snapshot. A production revision lookup must also be tenant-scoped, as the supplied map is for the already-selected tenant.
Context budgets can cause a second failure
Worked example
Suppose C2 is confirmed to belong to support and republished with correct metadata. Both C1 and C2 now pass eligibility. Their declared teaching token counts are 120 and 100. A context evidence budget of 180 tokens cannot include both whole passages.
A greedy packer that includes C1 first leaves 60 tokens and drops C2. Increasing retrieval top-k does not fix this context-selection failure. Options include selecting the exception passage for the specific question, including a compact verified representation of both rules, or increasing the evidence budget if the full request still fits.
When a chunk is omitted, record its ID and omission reason. Avoid silently truncating a sentence that carries a critical exception. A packing algorithm that skips oversized chunks can use later smaller chunks, but it still needs evaluation for whether all required evidence survives.
Validate citations in layers
Build a request-local map from source labels to selected chunks and source revisions. The generator can reference those labels. Check that every returned label belongs to the map and resolve links through trusted application metadata.
For example, if the context contains S1 and S2, a reference to S9 is invalid even if a document with a similar title exists elsewhere. A reference to S1 may be structurally valid but semantically wrong for a claim about the custom-product exception in S2.
Define whether every factual claim needs support and how the UI associates claims with citations. Evaluate support and coverage. Counting citation markers alone can reward unsupported answers with many links.
Separate retrieval, packing, and generation evaluations
| Check | Example failure | Diagnosis |
|---|---|---|
| Relevant source exists | Exception absent from parsed text | Ingestion or parsing |
| Relevant chunk is eligible | Wrong department metadata | Publication or authorization metadata |
| Relevant chunk is retrieved | C2 absent from candidate set | Retrieval |
| Relevant chunk reaches model | C2 dropped for budget | Context packing |
| Answer uses evidence | Answer ignores supplied exception | Generation or instruction behavior |
| Citations support claims | Correct fact cites unrelated passage | Attribution |
A useful experiment substitutes a known-good context for the retrieved context. If the answer improves, investigate the upstream path. If it remains wrong, inspect generation behavior and the task instructions. Keep evaluation cases separate from prompt tuning cases.
Predict pipeline behavior for more fixtures
Predict the outcome
Predict pipeline behavior for more fixtures
For each fixture, decide what the pipeline should do before you reveal the expected behavior.
| Fixture | Expected behavior |
|---|---|
| Parser returns empty text | ? |
| Duplicate ingestion delivery | ? |
| New revision has only half its expected chunks | ? |
| Cited source label was never supplied | ? |
| Query requests another tenant's policy | ? |
| Both current passages are supplied but answer uses only the general rule | ? |
Completion checklist
- Reproduce the six eligibility outcomes.
- Explain both C2 failures: the department filter and the 180-token budget.
- Propose checks that locate a defect without weakening authorization.
Sources
- Microsoft RAG overview Describes combining retrieval with generation.
- Microsoft RAG design and evaluation guide Provides architecture and evaluation background.
- Azure document chunking guidance Discusses dividing documents into searchable units.
- Azure document-level access overview Describes access-aware retrieval patterns.
- Anthropic contextual retrieval Discusses supplying document context to otherwise isolated chunks.
The policy excerpts, traces, implementation exercises, targets, and rubrics are original synthetic teaching material. They describe a fictional application. Study times and readiness thresholds are editorial estimates. Provider-specific implementations must be checked against the selected service's current documentation.
Related on CodeSnatch
Lessons, problems, and articles that build the skills this question uses.
AI Engineering
Practice the same retrieval, packing, and generation split on a request trace, with rates over named denominators.
System Design
Covers traces, spans, and structured log fields, the tools for recording stable IDs at each pipeline stage.
AI Engineering
Enforce tenant, group, and deletion rules before ranking, and write tests so a fix never widens access.
DSA lesson
Shows when picking items greedily under a fixed capacity misses a better set, the same shape as packing passages.
Practice the interview question
Answer it in your own words before you look at the reference answer.
