Skip to content

Sherlock Holmes RAG Agent

Sherlock Holmes silhouette with magnifying glass

A chatbot that answers questions about the Sherlock Holmes canon — grounded only in the retrieved text, with every answer citing its sources. Built deliberately as a measured experiment: the goal was not the chatbot, but a defensible answer to “how do I know whether my RAG system is actually working — and why does it fail when it fails?”

The corpus: one novel and one short-story collection — 13 documents, ~148,000 words, all public domain. Small enough that retrieval quality can be inspected by hand, big enough that every failure mode shows up.


Building a RAG chatbot is easy. Knowing whether it actually works is hard.

It is surprisingly easy to demo a few successful answers and conclude the system works. But a system that has not been measured is a prototype, not a solution. The questions that matter — is the evidence being retrieved? is the model answering from the evidence? is the evaluator itself trustworthy? — only get answers with a real evaluation harness.

So the experiment was designed around measurement from the start: a grounded answer format, a categorized question set, an LLM judge, and manual calibration of the judge’s verdicts.


The agent answers only from retrieved passages, cites the specific chunk behind every claim, and refuses when the corpus doesn’t cover the question — a test of honesty, not retrieval skill.

flowchart TD
    A[Raw text files] --> B[Ingest<br/>load + normalize]
    B --> C[Chunk<br/>semantic + token-window]
    C --> D[Embed<br/>local model]
    D --> E[Store<br/>ChromaDB + metadata]
    E --> F[Retrieve<br/>query embed + top-k cosine]
    F --> G[Generate<br/>local LLM + cited context]
    G --> H[Cite + return<br/>story + chunk refs]
    J[User query] --> F
    H --> K[User answer + citations]
    K -.-> L[Eval runner<br/>30-question set + rubric<br/>LLM judge, manually calibrated]

Semantic-first chunking, token-capped with overlap. Documents split on natural boundaries first — paragraph breaks, chapter markers — then merged and trimmed to a ~400-token target with 50-token overlap. Pure fixed-window splitting would cut Holmes’s reasoning chains mid-sentence; pure paragraph splitting would produce fragments and multi-page monologues. The hybrid keeps deductions intact while staying inside a model-friendly window.

Citation-only prompting. The answer rules are strict: answer only from the provided passages, challenge a false premise when the chunks contradict it, cite every factual claim inline, and say exactly “I don’t have any source material that covers that” when nothing relevant was retrieved.

Local-first stack. Embeddings and generation both run on local models (Ollama) — no API keys, no cost, and the corpus never leaves the machine. ChromaDB for the vector store, Streamlit for the interface.

The Sherlock Holmes RAG agent chat interface: a Streamlit app answering a question with inline chunk citations

A 30-question harness spanning four categories, each probing a different capability:

Category What it tests Result
Factual single-hop Answer sitting in one passage 5/9 correct, 3 partial
Multi-hop Answer requiring pieces from multiple passages 2/6 correct, 2 partial
Cross-story consistency Comparing facts across stories 0/5 correct
Out-of-scope Refusing questions the corpus doesn’t cover 10/10 correct
Overall 17/30 correct (57%), 0% hallucination

Zero hallucination, 57% correct — and the gap between those numbers is where the findings live.

Retrieval was the dominant failure mode. Five of the six wrong answers traced to retrieval misses, not model failures: the right information existed in the corpus, but the chunk carrying it didn’t make the top-5. One question got the correct killer but the wrong weapon, because the chunk describing the actual weapon wasn’t retrieved and a pen-knife reference in another chunk was. A retrieval problem can look exactly like a generation problem until you check the evidence.

One fixed top-k doesn’t fit all questions. Cross-story consistency scored 0/5: with five retrieved chunks out of ~370, the system often received material from one story while the question needed two. Retrieval parameters should reflect question complexity.

Generation failures look different from retrieval failures. One question contained a false premise; the correct response was to challenge it. The model instead tried to satisfy the premise and produced unsupported examples. The evidence was there — the model misused it. Categorizing failures (retrieval / generation / evaluation) is what makes the next fix targeted.

Even the evaluator needs evaluation. The LLM judge misclassified one failure as a correct refusal — manual calibration caught it. A score is only as trustworthy as the methodology behind it.


Outcome Evidence
Measured, not assumed 30-question categorized harness; 0% hallucination and 57% correctness established on real runs
Failure modes separated and diagnosed Retrieval vs generation vs evaluation failures identified case by case — each demands a different fix
Honesty under pressure 10/10 correct refusals on out-of-scope questions — the system says “not in my source material” instead of inventing
A repeatable improvement loop Hypothesis → change one variable → evaluate → inspect failures → iterate
Local-first, zero-cost operation Local embedding and generation models; no API spend; corpus stays on the machine

The most valuable outcome wasn’t the 57% score — it was learning that hallucination was not the dominant problem. Getting the right evidence into the context in the first place was. That reframes how to improve any retrieval-based AI system: don’t start with “which model should I use?” Start with “how will I know my system is getting better?”

That discipline — build, measure, categorize failures, change one variable, measure again — is exactly what separates an AI demo from a system a team can iterate on with confidence. It is the same evaluation-first mindset behind the calibrated confidence and reconciliation gates in my other projects.