Curio: every retrieval technique had to beat the eval.
Curio is a NotebookLM-style learning workspace I built. Each retrieval technique in it sits behind a feature flag and stayed only if an ablation showed it helped. This page covers what each one bought, measured on a golden set, plus a prompt-injection eval that 45 attacks failed to beat.
- Hit@5 1.00 from 0.933, vector only
- MRR 0.983 from 0.796
- 1.00 refusal accuracy, 0 false refusals
- 0 / 45 prompt injections landed
By Rohit Raj · · Source on GitHub · Live demo
Summary
- Starting from plain vector search, I added four techniques one at a time: query rewriting, hybrid search fused with reciprocal rank fusion (RRF), Cohere rerank, and a relevance gate. Each change was measured on the same golden set.
- Rerank made the biggest jump: MRR went from 0.85 to 0.98, and the right passage was in the top 5 for every answerable question.
- The relevance gate refuses before any model call. It refused all 10 unanswerable questions and none of the 60 answerable ones.
- Two techniques, HyDE and chunk-size tuning, did not earn a place. Retrieval had already hit the dataset’s ceiling, so both stay switched off behind flags.
- A prompt-injection eval (5 surfaces × 3 attacks × 3 runs, scored in code with a canary string) ended 0 / 45 hijacked.
What Curio is
You add PDFs, websites, YouTube videos or notes to a notebook and chat with them. Every answer is cited to the page, timestamp or section, or Curio says the answer isn’t in your sources. There’s also a second mode: give it a topic and a level, and it finds trusted resources, builds a learning path from what they agree on, and teaches each module as a cited lesson.
The stack is Next.js and Express in TypeScript, Neon Postgres with pgvector, Inngest for step-based ingestion jobs, Upstash Redis, Cloudflare R2, Cohere for rerank and Langfuse for tracing. The thing it’s built to show is retrieval quality that’s measured, not assumed.
The retrieval pipeline
question
→ understand one model call: route + standalone rewrite + split multi-part questions
→ search vector + keyword per query, in parallel → RRF fusion (~40 candidates)
→ rerank Cohere rerank against the question and each part → top 8
→ gate best rerank score < 0.70 → "not in your sources", no model call
→ answer numbered context → streamed answer citing [n]
→ check drop any [n] that doesn't point at a passage the model was given
Every step has its own flag in the server config, so any combination can be run as an ablation with one command.
The golden set
The dataset is 7 documents on machine-learning fundamentals: 2 PDFs, 2 websites, 2 YouTube videos and 1 note, 238 chunks in total. It has 60 answerable questions across four categories and 10 questions the sources can’t answer.
Relevance is judged by location (page, timestamp window or heading path), not by chunk ID. That way two different chunking strategies can be compared fairly. Answers are scored by an LLM judge with fixed prompts, averaged over 2 runs. A full answer eval costs about $0.21, and a retrieval-only run costs under a cent, so it’s cheap to run on every change.
The ablation
Each row adds one technique to the row above it.
| Config | Hit@5 | MRR | Faithfulness | Correctness (1–5) | Citation acc. | Refusal acc. | False refusals |
|---|---|---|---|---|---|---|---|
| Vector only | 0.933 | 0.796 | 0.976 | 4.50 | 0.832 | 0.90 | 0.008 |
| + query rewrite | 0.950 | 0.814 | 0.956 | 4.59 | 0.867 | 0.95 | 0 |
| + hybrid search (RRF) | 0.967 | 0.845 | 0.963 | 4.73 | 0.865 | 0.95 | 0 |
| + rerank (Cohere) | 1.000 | 0.983 | 0.968 | 4.78 | 0.847 | 0.95 | 0 |
| + relevance gate 0.70 | 1.000 | 0.983 | 0.990 | 4.74 | 0.842 | 1.00 | 0 |
| Final pipeline, re-run | 1.000 | 0.983 | 0.969 | 4.72 | 0.884 | 1.00 | 0 |
| + sub-queries, reranked and gated per part | 1.000 | 0.983 | 0.980 | 4.72 | 0.893 | 1.00 | 0 |
Every result file in the repo records its git commit, config, models, cost and each question’s retrieved chunks.
What each technique bought
Query rewrite
Follow-up questions like “Is it deterministic?” mean nothing out of context. Rewriting them into standalone questions raised correctness on follow-ups from 3.50 to 4.67 and their MRR from 0.54 to 0.73.
Hybrid search with RRF
Vector search tends to find the first half of “compare X and Y” and miss the second. Fusing keyword and vector results with reciprocal rank fusion raised MRR on multi-part questions from 0.55 to 0.81. Answers scoring 4 or more went from 1 in 12 to 8 in 12.
Cohere rerank
Rerank put the right passage in the top 5 for every answerable question, taking MRR from 0.85 to 0.98. Its calibrated 0–1 scores matter for another reason too: they’re what make the relevance gate possible.
Relevance gate
Search always returns something, so “never invent an answer” has to be enforced before the model sees weak matches. If the best rerank score is below 0.70, Curio answers “not in your sources” without calling the model at all. It refused all 10 unanswerable questions and none of the answerable ones.
Sub-queries, reranked and gated per part
One compare question got refused in live use. Scored as a single query, no passage matched both halves. Now each part is searched, reranked and gated separately. The parts score 0.86–0.93 where the whole question scored 0.76–0.84. Citation accuracy rose to 0.893 and follow-up correctness to 4.83, still with no false refusals. Multi-part correctness is noisy on only six questions, so I don’t read much into its movement.
What didn’t make it
HyDE and chunk-size tuning were both tried. Retrieval was already at the dataset’s ceiling, so neither could show a gain, and neither was adopted. They stay behind flags, switched off. That’s the point of the rule: complexity that doesn’t pay for itself on the eval stays out.
Prompt injection: 0 of 45
Curio reads untrusted text all day: PDFs, web pages, transcripts. Any of them could contain “ignore your instructions and…”. Every prompt fences that text as data. To check the fencing works, the injection eval plants attacks on 5 surfaces, with 3 attacks each, run 3 times. That’s 45 attempts.
Scoring is done in code, not by a judge model. Each attack tries to make the model print a canary string, so a hijack can be detected exactly. Result: 0 / 45 hijacked, and 45 / 45 responses stayed on task.
Other evals
- Lesson faithfulness: 0.936. That’s supported factual claims divided by all factual claims, across 6 lessons (Python, Git) and 171 claims.
- Learning-path coverage: 0.82. A Python beginner path compared against the core sections of the official tutorial. This was a single run. The full three-topic run is still to do.
Design decisions that made the evals trustworthy
- pgvector inside Postgres, not a separate vector database. Chunks live next to their source, so indexing and deleting each happen in one transaction, and a half-indexed source can’t exist.
- Atomic ingestion. The API never does the processing itself. An Inngest job extracts, chunks (about 500 tokens with 15% overlap), embeds, then replaces the chunks and marks the source
READYin one transaction. Every source endsREADYorFAILEDwith a readable reason. - A deterministic citation check. Models sometimes cite passages they were never given. Any
[n]that doesn’t point at a real passage is dropped before the answer is saved. - Citations stored as snapshots, so re-indexing a source never breaks an old answer.
- Every technique behind a flag, kept only if the eval improves. That rule is what produced the ablation table above.
What I’d tell another team building RAG
- Build the golden set before you add techniques. Without it, every change is a guess.
- Judge relevance by location, not chunk ID, so you can change chunking and still compare.
- Put rerank in early. It improves ranking, and its scores give you a gate.
- Enforce refusal in code, before the model call. Prompting the model to say “I don’t know” is not enough.
- Score injection attacks with a canary in code, so the result doesn’t depend on a judge model.