RAG pipeline: a thin pgvector slice in a non-prod environment, measured end to end

in RAG evaluation

A RAG demo that answers three hand-picked questions well tells you nothing about whether it will answer your users correctly, or refuse when it should.

  1. Why put RAG in a fitness app?
  2. What did the slice build?
  3. What happens when someone asks a question?
  4. How do you know retrieval works?
  5. Are the answers true to the sources?
  6. What did the reviews catch?
  7. How was it built?
  8. What would it take to give it to members?
  9. Strong and weak points
  10. Summary

Why put RAG in a fitness app?

To practice RAG on a real product, and to find out whether members could use it. My fitness app had the pgvector extension turned on in an early migration, but nothing stored or queried a vector. The app also has docs worth asking about: how long to rest between heavy sets, when to add weight, how the app counts a paused set.

The question a member would ask is "how long should I rest between heavy squats?", and the answer should come from those docs with a citation, or not at all.

My first retrieval work, RAG over agent-created harness files, used SQLite and NumPy. This time I wanted the stack most RAG work runs on: Postgres with pgvector, LangChain, LangGraph and Langfuse.

So the goal was the thinnest path that works end to end: ingest, retrieve, answer with citations, and measure it. Two rules from the plan. Every number comes from a committed eval report. A tool that would only be there for its name gets cut, and LangSmith got cut that way.

Tool Used for
Django 5.2.17, Django REST Framework 3.18.3 the app, the ask endpoint, the AnswerLog table
Postgres + pgvector 0.5.1 the chunk table, HNSW cosine index
Voyage voyage-4-lite embeddings, called over httpx behind LangChain's Embeddings interface
LangGraph 1.2.22, langgraph-checkpoint-postgres 3.2.1 the answer graph, its checkpoints and the approval pause
langchain-anthropic 1.7.10, Claude Haiku 5.5 the answer step
Claude Opus 5.5 the faithfulness judge
Langfuse 5.2.0 (SDK) tracing every graph run
pytest, GitHub Actions the keyless recall gate, the nightly eval

What did the slice build?

Five parts, in the order a fact travels from a doc to a checked answer:

  1. Ingest. Three sources (a fitness-science doc, the app's domain doc and the prose of 50 seed exercises) cut by heading into 80 chunks. Each chunk carries a content hash, so a rerun re-embeds only what changed. The full ingest cost 7,938 tokens and $0.00016; a rerun with no change made 0 embedding calls.
  2. Store. One Django table with a pgvector column and an HNSW cosine index. I skipped LangChain's Postgres vector store and wrapped the Django table in LangChain's retriever interface instead, so migrations stay in Django.
  3. Answer graph. LangGraph: retrieve, answer, self-check, log, and a pause for human approval.
  4. Eval report. A 34-question golden set run through the live graph, scored for recall, faithfulness, refusals, citations, latency and cost.
  5. Recall gate. A CI test that fails when retrieval gets worse.
fitness docs3 sources, 80 chunks1 pgvector tableHNSW, cosine2 golden set34 approved questions answer graphcite or refuse3 recall gateCI, no API key5 eval reportcommitted numbers4
Figure 1. From fitness docs to a checked answer and a CI gate.

The golden set has no number because it isn't on the path. It's the test input for steps 3 to 5.

What happens when someone asks a question?

The graph either gives a cited answer or refuses, and it logs both. An API endpoint and a management command run the same graph.

question retrievetop 5 by cosine ✕ best ≥ 0.35? answerHaiku cites chunk keys self-checkcites only retrieved? log the asktokens, $, ms ✕ plan change? answer or refusal approvalwaits for a human yes no: refused, no model call no yes 1 2 3 4 5
  1. Retrieve the top 5 chunks by cosine. If the best one is under 0.35, refuse without calling the model.
  2. Claude Haiku answers and cites chunk keys, or says it can't answer.
  3. The server checks every cited key is among the retrieved chunks. If not, it refuses.
  4. Log the ask: tokens, dollars, latency, retrieved and cited keys, refusal reason.
  5. If the answer proposes a plan change, pause until a person approves.
Figure 2. What the answer graph does with one question.

Step 3 is the one I'd copy into any RAG app. The model doesn't get to decide what counts as a citation; the server compares sets. Step 5 is a real LangGraph interrupt with Postgres checkpointing, but the action behind it is a stub on purpose: no tool writes to a member's plan yet.

The 0.35 floor is a tuned number. At that floor, 0 of 29 answerable questions were cut before the model, and 2 of 5 off-topic ones (football, taxes) were refused for $0.

How do you know retrieval works?

By scoring it against a fixed answer key, beside a dumb baseline. The golden set holds 34 questions: 24 answerable from the docs, 5 about the member's own training history, and 5 the docs can't answer, like creatine or marathon heart rate. An agent drafted it from the corpus, and I approved it with one edit. The freeze command refuses a set nobody approved.

Retrieval recall@5 MRR
Vector (voyage-4-lite, HNSW) 0.946 0.824
Postgres full-text keyword 0.786 -

recall@5 is the share of questions whose right chunk is in the top 5. MRR (mean reciprocal rank) rewards it for being near the top.

The keyword baseline is there to keep the vector number honest. Its first version was an all-words AND query and scored 0.07, which made vectors look brilliant. Switched to OR, it scored 0.79. The freeze also refuses a golden set where keyword recall@5 reaches 0.9: if plain search already solves it, the set is too easy to prove anything.

The CI gate needs no API key. It scores recall from vectors frozen at approval time, and fails on a recall drop or on a corpus hash that no longer matches. Editing a fitness doc turns it red until someone pays for a re-freeze.

Keep the scale in mind. The corpus is about 5,000 words, so this tests correctness, and says nothing about scale. HNSW is there because it's the production index shape; exact search would be fast at 80 chunks. And a golden set drafted from the same docs flatters retrieval compared with real member questions.

Are the answers true to the sources?

Mostly. Where it fails, it refuses instead of making things up. A claim-level judge (Claude Opus 5.5, versioned prompt) splits each answer into claims and checks each one against the cited chunks. I described that judge pattern in LLM evals on a Pydantic AI agent.

The second live run, on 2026-11-18:

Metric Value
Faithfulness, mean over 24 answers 0.977
Unanswerable questions refused 5 of 5
Answers with valid citations 24 of 24
Answerable or history questions refused 5 of 29
Latency p50 / p95 7.2 s / 12.8 s
Cost per answer, mean $0.0004
Judge cost, whole run $0.42

The first run scored 0.966 faithfulness with 4 of 29 false refusals, so two runs agree within noise.

The weak number is false refusals. Three of the five are history questions, about a member's goblet squats, pull-up sets and calf raises. The model abstains because a member's workout history isn't a chunk it can cite. A prompt tweak won't fix that; citing history needs a design first.

Note the judge costs about 50 times the answers it grades. That's fine for 34 questions a night and the reason the eval has a cost cap.

What did the reviews catch?

One bug that made the index useless, and one privacy bug. Fresh reviewer agents read each wave's diff; a separate ship-check read the finished code.

Symptom Cause Fix
The HNSW index was never used ORDER BY distance, key (a tie-breaker) made Postgres scan and sort every row order by distance alone, fetch 5 extra rows, break ties in Python; a test runs EXPLAIN and needs the HNSW index
A deleted account's questions survived LangGraph checkpoint tables kept member history outside the app's deletion path retention, account-deletion purge and a prune command, with tests that query those tables
Keyword baseline at 0.07 all-words AND query OR query, 0.79
Provider errors counted as refusals metric code lumped them together excluded and counted separately
Three repo gates went red after wave 1 GDPR export, OWASP surface and judge import tests weren't in the lane's checks fixed on main; later lanes ran those tests themselves

Every test passed and recall was 0.946, because at 80 chunks a full scan is fast and correct. Only a check of what the database actually did showed the index was decoration.

How was it built?

As one mow run over three days, 2026-11-16 to 2026-11-18: four waves, six lanes. mow is my multi-agent workflow. It turns a plan into one brief per lane, builder agents work in their own git worktrees, and reviewer agents gate each wave.

W1AingestW2BanswerCrecallDtracingW3EjudgeW4Zlive run W1AingestW2BanswerCrecallDtracingW3EjudgeW4Zlive run
Figure 3. The run: four waves, six lanes.

Waves 1 to 3 were agent lanes; each needed one or two fix rounds after review. Wave 4 ran with me in the chat, because it needed my approval of the golden set, a paid API key, and real money. Two things changed there. Voyage rate-limited the key until it had a payment method. Self-hosted Langfuse is six containers, too heavy for the laptop, so dev and eval tracing moved to Langfuse Cloud (EU). A guard keeps real members' asks off the cloud account.

What would it take to give it to members?

A screen, a way to cite history, and four launch chores. Today the graph runs from the API and a command, and no member sees it. Before it ships:

Missing Why it blocks members
A chat screen there is no UI, only the endpoint
History citations 3 of the 5 false refusals are questions about the member's own workouts
Self-hosted Langfuse member asks may only be traced on a server I run; the cloud account is for evals
A retention job for the answer log every ask is stored with its question, and nothing deletes old rows yet
AI vendors in the privacy policy questions go to an embedding API and a model API, and the policy names neither
The nightly eval running on GitHub built, but the repo secret isn't set, so it has never run

None of these is RAG work. The retrieval and the checks are done; what's left is product work and privacy.

Strong and weak points

Strong:

  • Every number in this post traces to a committed JSON report.
  • The keyword baseline and the "too easy" refusal stop the golden set from flattering retrieval.
  • Citations are checked by the server, and off-topic questions are refused for $0.
  • The recall gate runs in CI with no API key.

Weak:

  • The corpus is about 5,000 words. Nothing here says how it behaves at scale.
  • The golden set came from the same docs it tests. Real member questions will score lower.
  • 5 of 29 answerable questions are refused, mostly history questions.
  • Tracing may cost latency: p50 was 2.6 s untraced and 7.2 s traced, one run each, plus one 148-second ask. Unmeasured, so unproven either way.
  • No member can use it yet.

Summary

  • Practice RAG on a real app with a real eval: a golden set, a keyword baseline and a judge tell you more than a demo.
  • Always score vector retrieval beside a keyword baseline, and check the baseline isn't broken (0.07 was).
  • Let the server check citations against the retrieved set; never trust the model's own.
  • Small-corpus tests pass with or without the index you think you're using. Check the query plan.
  • The model refusing is cheaper than the model inventing, but 17% false refusals is still the number to fix.
  1. Design how history gets cited, then re-run the eval to bring false refusals under 5 of 29.
  2. Build the member chat screen behind a self-hosted Langfuse.
  3. Measure tracing latency over many asks before deciding whether to keep it on the request path.