Personal project by Ulf Fäldt Reifenberg · December 2026 · not affiliated with the EU or any company · not legal advice
One retrieval, or a loop?
Does an agentic retrieval loop built with LangGraph answer questions about the EU AI Act more accurately than a single retrieval, and what does it cost in model calls and tokens?
Loading…
Headline result
45 questions: 33 answerable (15 from one passage, 18 that need a second passage that the first one points to) and 12 that the Act does not answer. Counts, with 95% bootstrap intervals over questions in brackets. Temperature 0, one run per cell.
single: BM25 top 5 passages, one model call. loop: LangGraph graph, up to 3 retrievals, a grading call after each, then the same answer call. single, k=8: BM25 top 8 passages, one call, chosen because it sends about as many input tokens as the 8B loop (1,256 against 1,317 per question), as a control for "more context". The 70B loop sent more (1,724), so for 70B this control has about 27% fewer tokens than the loop.
Trace explorer
Pick a question to see what each setup retrieved, what the grader decided, and how the answer was graded. Passages are the first 200 characters only; the full text is at EUR-Lex.
Paired differences
Same questions, same model: loop minus the comparison arm, in percentage points, with 95% paired bootstrap intervals (10,000 resamples). "Loop wins / loses" counts questions where only one of the two was right. An interval that includes 0 means this test cannot tell them apart.
What it costs
Means per question, bootstrap 95% interval in brackets. Neurons are Cloudflare's billing unit, metered by this project from token counts and published per-model rates. Seconds are model-call time only, replayed from the original uncached call, and include network round trips from one machine; they are rough.
Setup
- Corpus. Regulation (EU) 2024/1689, English text, from the Publications Office copy of the Official Journal text (EUR-Lex). 113 articles and 13 annexes, split at numbered paragraphs (long ones at sub-points) into 604 passages of at most 1,500 characters. Recitals are not included. The text is not republished here.
- Questions. 45, written by the author from the text, each with a regular expression for the key figure or term. Every gold answer was checked programmatically against the passage that holds it. Unanswerable questions were checked for absence of the answer terms. The answer should be
NOT_IN_SOURCEfor those. - Retrieval. BM25 in pure Python (k1 1.5, b 0.75, short stopword list, crude plural strip). No embeddings, no reranker. Untuned.
- Models. Llama 3.1 8B (the
-fastvariant) and Llama 3.3 70B (fp8-fast) on Cloudflare Workers AI, temperature 0. Same answer prompt and grading in every arm. - Loop. A LangGraph
StateGraphwith three nodes,retrieve,gradeandanswer, and one conditional edge aftergrade. The grader returns JSON: which new passages are relevant, whether the kept ones are enough, an article or annex cited in them to follow, or a rewritten query. Hard cap: 3 retrievals. If nothing is graded relevant the loop answersNOT_IN_SOURCEwithout a model call. - Serving. A FastAPI app (
POST /ask,/healthz) wraps both arms, with 13 pytest tests that run with a stubbed model. The code is not published; this page and the traces are.
What this does and does not show
- One corpus and 45 questions written by one person who knew where the answers are. Intervals are wide: one question is 2 to 3 percentage points.
- Grading is by pattern on the key figure or term. A correct answer in unexpected words counts as wrong, and a pattern can match a wrong answer. Gold answers were read and checked against the text, but the patterns were not tuned against model output.
- Prompts, retrieval settings, passage size and the cap of 3 retrievals were set once and not tuned. A different grader prompt could change the loop's result a lot.
- The unanswerable questions were easy: every setup abstained on all 12, so this test says nothing about abstention under pressure.
- No reranker, no embeddings, single-turn only, no LangSmith tracing. The loop uses prompted JSON, not native tool calling.
- One run per cell at temperature 0. Hosted models can change behind the same name, so a rerun later may differ.
- The 8B loop stopped after the first retrieval in 44 of 45 questions, so the 8B loop was mostly a single retrieval of 4 passages with a filter. That is a finding about this 8B grader prompt, not about loops in general.