PH AI Works

Clinical Knowledge Base — RAG Demo

Illustration of a clinical knowledge base: blood test tubes, a magnifying glass picking the one matching document, and a chat answer with verified source tags

Ask a question about a blood test. The system searches 52 checked summaries of blood markers (“biomarker briefs”). If the first search misses, a LangGraph agent rewrites the question and tries again. Every answer lists the briefs it used, and the system checks that each one really came from the search. If it can't answer reliably, it says so and shows you why.

Tested on 60 sample questions with known answers: the right brief came first 96% of the time, and 100% of out-of-scope questions were refused.

See the evaluation, including what still fails →

Demo only. The briefs use illustrative UK reference values and are not medical advice. Always consult a healthcare professional. Not affiliated with any clinical provider or product.
retrieval— hybrid scored lower in testing (90% vs 96%). Switch modes and ask again to compare.

How it is kept honest

The weak points of a typical RAG knowledge base, and how this demo handles each one.

  • Every brief follows one checked format

    Before a brief is added to the search index, code checks it against a fixed format (a Pydantic schema with set vocabularies). A brief with an error stops the import and names the file, instead of later producing a confident wrong answer.

  • Filters run before the search

    Briefs that are unapproved, not UK-based or in the wrong category are removed before any similarity search, on both the vector and keyword side. They are never candidates at all.

  • Citations checked, not trusted

    The model must list the ID (source_brief_id) of every brief it used. If it cites an ID that the search did not return, the answer is thrown away, so a made-up source becomes an error you can detect.

  • Declining to answer is a valid result

    A minimum score and an explicit "the briefs don't cover this" option let the system decline. The evaluation scores refusals separately, because a system judged only on finding answers will try to answer everything.

Stack: Next.js proxy (no provider keys) · FastAPI · LangChain retrieval · LangGraph agent · Pinecone serverless · Gemini embeddings and generation, swappable for OpenAI or Anthropic by config. The source code and a full write-up are on GitHub.