Deployed Lab

Module 4 · Case studies I · Chapter 16 · Free

Case study: enterprise search over 40,000 company documents

15 min1 clickable picture1 hands-on lab1 predict, 2 quick quizzes, 5-question final quiz5-min video review
In 30 seconds

The picture: a locked library. The librarian checks your badge before fetching, never after handing you the book.

Case file

Company: Aldercroft Group, an invented engineering firm, stated as made up, with 2,400 staff.

Product: a chat tool that answers staff questions from company documents, with sources.

Users: all 2,400 staff, asking a few questions each per week (illustrative).

Hard constraints: permissions are law; every answer cites its documents; the index stays fresh within a day.

The cold open

Aldercroft Group is invented. In this story, its first search pilot indexed everything and filtered permissions at display time. For three days, search snippets showed lines from a restricted pay review file to staff who could never open it. Nobody downloaded the file. The snippets alone were the leak.

The pilot was shut down. The rebuild started with one rule: a document a person cannot open must never enter their results, not even as a snippet or a count.

The plan for this chapter
  1. Set the context and requirements with the design method.
  2. Walk one question through the architecture, step by step.
  3. Name the patterns used, and why each one earns its place.
  4. Face the tradeoffs, the failures, and the cost and latency.
  5. Redesign the system when the requirements change.

Next: what Aldercroft actually needed, before any technology.

Step 1: Context and requirements first

Chapter 4 set out the design method: requirements, constraints, patterns, tradeoffs, eval plan. Applied briefly here:

Think of it as a library with locked rooms. The catalogue card for a locked room is itself locked.

Where the picture breaks down:

Next: the architecture, walked through with one real question.

Step 2: The architecture, one question end to end

The question: "what is our policy on carrying laptops through customs?" Press Next and follow it to a cited answer.

Enterprise search architecture Source systems sync into a permission-tagged index. A question is permission-checked, searched with hybrid search over allowed documents only, reranked, answered by a model, and returned with citations. Source systemswiki, drives, PDFs Search indextagged with access Employee chatasks a question Permission checkwho may see what Hybrid searchallowed docs only Rerankbest sources first Answer modelcites its sources daily sync answer plus citations
  1. Wiki pages, drive files, tickets and PDFs are copied into one index. Each chunk carries the access list from its source system.
  2. "What is our policy on carrying laptops through customs?" arrives with the asker's identity, not just the words.
  3. The system builds the asker's access filter from their groups. This filter is part of the search itself, not a step after it.
  4. Keyword and vector search run together, inside the filter. A restricted travel memo cannot be a candidate, even by accident.
  5. A reranker orders the allowed candidates. The current travel policy and the customs guide rise to the top.
  6. The model gets only those sources and must answer in a fixed shape: answer text plus the document ids it used (Chapter 6).
  7. "Declare the laptop, carry the company letter" plus links to the two sources. If sources conflict, it says so instead of answering.

Two points carry the case: the filter travels with the query, so no code path searches everything; and the model never sees a document the asker cannot open, so it cannot quote one.

Next: the patterns behind the picture, one by one.

Step 3: Patterns used and why

PatternWhere it appears, and why
Permission-aware retrieval (Ch. 5)Access filters applied BEFORE ranking. Ranking only ever sees documents the asker may open.
Hybrid search plus rerank (Ch. 5)Keyword search catches exact terms like project codes; vector search catches meaning; the reranker orders the merged list.
Structured output (Ch. 6)The answer-plus-citations shape is a schema, so code can check that every claim carries a real document id.
Eval loop (Ch. 11)Per-department golden sets. Finance and field staff ask different questions, so one average score would hide a broken department.
Caching (Ch. 12)Cache scoped per permission group, never per question alone. Two staff with different access must never share a cached answer.

Guardrails (Chapter 10) add citation checks and a refusal path. Fallbacks (Chapter 14): if the reranker fails, use the hybrid order, never an unfiltered search.

Predict first:

The cache key ignored access, so the second asker inherits the first asker's permissions. Cache keys here include the permission group, which is why the table scopes caching per group.

Next: what the team gave up on purpose.

Step 4: Tradeoffs taken

Each tradeoff swaps a visible quality (speed, fluency) for an invisible one (safety, trust).

Next: what broke in production, and the fix each failure forced.

Step 5: What broke

1. A departed employee's folder leaked. Their shared folders kept an old group tag, so their files surfaced for that whole group. Fix: permission sync runs before every index build, and folders of departed staff are quarantined until claimed.

2. Two policy versions mixed. Old and new travel policies were both retrieved, and the answer blended them. Fix: version and date metadata, retrieval prefers the current version, and the Step 4 conflict rule refuses when versions still clash.

3. A project code found nothing. Staff searched a code like "AC-2417" and got no results. Vector search treated the code as words about a topic. Fix: hybrid search, so the keyword side matches the exact code.

None of the three failures was the model writing badly. All were retrieval and data problems, which is typical for search systems.

Next: the bill, and how long an answer takes.

Step 6: Cost and latency, worked with real arithmetic

All figures in this section are illustrative. Prices: embedding at an illustrative $0.02 per million tokens, model input at an illustrative $3 per million tokens, output at an illustrative $15 per million.

Indexing: 40,000 documents at an average of 2,000 tokens each is 80,000,000 tokens. 80,000,000 ÷ 1,000,000 × $0.02 = $1.60 for a full rebuild. A daily sync touching 5 percent of documents costs about $0.08 a day in embedding, plus storage and compute.

Per question: the model call sends about 6,000 input tokens (question plus top sources) and returns 300. Input: 6,000 ÷ 1,000,000 × $3 = $0.018. Output: 300 ÷ 1,000,000 × $15 = $0.0045. Total about $0.023 per answered question, before search and rerank compute.

Monthly: at an illustrative 20,000 questions a month, 20,000 × $0.023 = about $460 a month in model cost.

Latency: an illustrative budget: permission check 50 ms, hybrid search 200 ms, rerank 300 ms, model first token 800 ms. Total to first token about 1.35 seconds, p95 about 2.5 seconds when the model is slow. Streaming (Chapter 13) makes that wait feel shorter; it does not change the total.

At this scale the model call dominates cost; indexing is nearly free by comparison. Spend engineering time on retrieval quality and caching.

Next: the lab, ending with the redesign exercise.

Step 7: Hands-on lab, design it on paper, then redesign it

Why this exercise: case studies stick when you make the decisions yourself.

Lab: Aldercroft Group (invented) has 40,000 documents across a wiki, shared drives, tickets and PDFs, many access-controlled, and 2,400 staff asking questions in chat. This lab runs in your browser and needs JavaScript enabled.

Field note, November 2026

In production search systems, the failures teams report most are stale permissions and stale documents, not bad model wording. That is a pattern from practice, not a measured statistic. A daily permission sync check and a visible "last updated" date on sources are cheap, useful habits.

Mix-ups to avoid

Chapter quiz

Five questions. Score 70% or more to mark this chapter complete.

Review this chapter in 5 minutes

Watch the whole chapter recapped: permission-first retrieval, hybrid search with citations, per-department eval, and redesigning when requirements change.

Decision rule: if a design step can show a person a document they cannot open, the filter is in the wrong place. Move it earlier.

Review

Glossary

Permission-aware retrieval
Search that filters by the asker's access before ranking. Example: a ward-only policy never appears for other staff.
Access filter
The rule set, built from a user's groups, that limits which documents a search may return.
Hybrid search
Keyword and vector search run together and merged. Example: a project code and a plain question both work.
Rerank
A second ordering pass over search results to put the best sources first.
Citation
A link from an answer claim to the document it came from.
Golden set
A fixed set of questions with known good answers, used to test quality. Example: one set per department.
Index sync
The job that copies changed documents and permissions into the search index.
Permission group
A set of staff who share the same access, used to scope filters and caches.
Structured output
An answer forced into a fixed shape, such as text plus citation ids, that code can check.

Next: "Case study: a coding agent that ships small pull requests".