RAG

Answers grounded in your documents

Retrieval-augmented generation lets a model answer from a company's own documents instead of from memory. The work is in the parts you don't see: clean ingestion, honest refusals, and citations you can check. Here is a public example, built and evaluated end to end.

Retrieval-augmented generation

Data Science Docs Assistant

Ask a question about pandas, NumPy, SciPy, scikit-learn, matplotlib, or Plotly. The assistant searches 1,040 pages of reference docs, answers only from what it finds, and cites the library, section, and page. If the docs don't cover a question, it says so.

1,040

Reference pages indexed

100%

Right source in top 5

15 / 15

Out-of-scope questions refused

97%

Answers judged faithful

Data Science Docs Assistant

Ask about pandas, NumPy, SciPy, scikit-learn, matplotlib or Plotly. Answers cite the reference docs.

How do I make a pivot table in pandas?

Use DataFrame.pivot_table to reshape and aggregate in one step:

df.pivot_table(index="region", columns="year",
               values="sales", aggfunc="sum")

Sources

pandas 3.1.0 · Reshaping and pivot tables · p. 100
What is the capital of France?
I couldn't find this in the documentation with enough confidence.

Static preview of the deployed app. Try it live here or in a new tab.

How it works

Step 1

Clean ingestion
PyMuPDF extraction, chosen after pypdf glued 14,341 words together. Running headers become library, version, and section metadata, and stray font glyphs are mapped back to text.

Step 2

Chunk and embed
Page-level chunks, embedded with OpenAI text-embedding-3-large at 1,536 dimensions and stored in Supabase pgvector behind an HNSW index.

Step 3

Retrieve
The question is embedded and matched against the top 5 chunks, optionally filtered to a single library from the sidebar.

Step 4

Two-layer refusal
A similarity gate refuses weak matches before any LLM call, at no cost. Then the model must confirm the context actually answers the question before it writes a word.

Step 5

Cited answers
Structured output streams token by token. Citations are built in code from stored metadata, never written by the model, so a cited page always exists.

Measured, not assumed

A 72-question evaluation set (57 answerable, 15 deliberately out of scope) decided the chunking strategy and the refusal threshold. A stronger model graded the answers blind.

MetricResult
Hit rate @ 10.842
Hit rate @ 51.000
MRR0.899
Refusals15 / 15
Faithfulness0.970
PythonLangChainOpenAISupabase pgvectorStreamlitpytest

Have documents your team keeps searching by hand?

Policies, manuals, contracts, product docs. The same pipeline (clean ingestion, cited answers, and a refusal when the answer isn't there) works on your own knowledge base.

Talk through a RAG project