Compliance Retrieval Engine

Applied AI · hybrid RAG · verified citations

Questions about SOPs. Answers you can audit.

Ask a question about the sample procedures below. The engine finds the governing passages with vector and keyword search, fuses and re-ranks them, and lets a language model answer only by quoting the text. Every quote is checked against the stored document before you see it, and if the documents do not say it, the engine says so.

Learning how it works? Under each answer, the walkthrough explains every stage with the numbers from your own question, and links to the code that does it. A map shows where your question landed among the stored chunks, and why the nearest one is not always the passage that answers.

FastAPI · PostgreSQL + pgvector (HNSW) + tsvector (GIN) · RRF · cross-encoder re-ranking · constrained JSON

Ask the corpus

What is in the corpus

How a question is answered

  1. Embed. The question becomes a vector with a local embedding model (a small ONNX model).
  2. Hybrid retrieval. One SQL statement runs a pgvector cosine search (HNSW index) and a PostgreSQL full-text search (GIN index) and fuses both with Reciprocal Rank Fusion, keeping the top 50 chunks. Keyword search catches identifiers such as 21 CFR Part 11 that embeddings blur.
  3. Re-rank. A cross-encoder (a small ONNX model) reads the question and each candidate together and keeps the best 3.
  4. Generate. A language model answers under a strict JSON schema: an answer, a confidence score, and quotes copied character for character from the passages, or an explicit "insufficient context".
  5. Verify. The server looks for every quote in the stored chunk, takes the page number from the database, and drops anything that does not match. An answer that claims to be grounded but has no quote that passes is withheld.

Before any of this, at ingestion, each chunk is stored with a situational preamble (document title, section, pages), following Anthropic's Contextual Retrieval pattern, so a sentence such as "the limit is 10 ppm" stays findable on its own.

Rank fusion lab

The lab needs JavaScript.

Concepts, one at a time

Each idea in a few sentences, with the file that implements it.

The glossary needs JavaScript.