Module 4 · Case studies I · Chapter 16 · Free
Case study: enterprise search over 40,000 company documents
- Enterprise search is retrieval (Chapter 5) plus one hard rule: permissions filter candidates before ranking.
- Every answer cites the documents it used, and refuses when its sources conflict.
- Freshness, cost and trust are design choices here, not settings you tune later.
The picture: a locked library. The librarian checks your badge before fetching, never after handing you the book.
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.
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.
- Set the context and requirements with the design method.
- Walk one question through the architecture, step by step.
- Name the patterns used, and why each one earns its place.
- Face the tradeoffs, the failures, and the cost and latency.
- 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:
- Corpus: 40,000 documents across a wiki, shared drives, tickets and PDFs (illustrative mix), many access-controlled.
- Job: an employee asks a question in chat and gets a short answer with links to the documents behind it.
- Non-negotiable: nobody sees a document they cannot open in the source system.
- Freshness: a changed document appears in search within a day.
- Eval plan: per-department golden sets from day one (Chapter 11), not one average score.
Think of it as a library with locked rooms. The catalogue card for a locked room is itself locked.
Where the picture breaks down:
- A library badge is checked once at the door. Here, permission is checked per document, per question.
- Books do not change overnight. Documents do, so the catalogue needs daily rebuilding.
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.
- Wiki pages, drive files, tickets and PDFs are copied into one index. Each chunk carries the access list from its source system.
- "What is our policy on carrying laptops through customs?" arrives with the asker's identity, not just the words.
- The system builds the asker's access filter from their groups. This filter is part of the search itself, not a step after it.
- Keyword and vector search run together, inside the filter. A restricted travel memo cannot be a candidate, even by accident.
- A reranker orders the allowed candidates. The current travel policy and the customs guide rise to the top.
- The model gets only those sources and must answer in a fixed shape: answer text plus the document ids it used (Chapter 6).
- "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
| Pattern | Where 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
- Freshness within a day, not minutes. Reindexing every few minutes costs far more than a daily sync. The requirement said a day, so the savings went to permission sync checks.
- Refuse on conflict. When sources disagree, the answer says so and links both. Picking one silently is how a stale policy becomes company truth.
- Shorter answers. Citing every claim makes answers plainer. A confident paragraph with no source fails the product's whole point.
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.
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
- Filter after ranking. No: snippets and counts leak. Filter inside the search, before ranking.
- Cache by question. No: cache by question plus permission group, or do not cache.
- Vector search alone. No: exact codes and names need the keyword side. Use hybrid.
- One golden set for everyone. No: departments ask different questions. Eval per department.
- Pick a side in a conflict. No: refuse, link both sources, and let a human settle it.
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.
- The case: Aldercroft Group (invented), 2,400 staff, 40,000 documents, chat answers with citations.
- Permissions are law: access filters apply inside the search, before ranking, and the model only sees allowed sources.
- Hybrid search plus rerank handles both meaning and exact codes. Structured output enforces answer plus citations.
- Eval runs per department. Caching is scoped per permission group, never per question alone.
- Tradeoffs: freshness within a day, refusal on conflict, plainer cited answers.
- Illustrative cost: about $0.023 per answered question; a full reindex about $1.60 in embedding.
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".