Ancla

Measured, not claimed.

40 questions with known answers and 6 that the docs can't answer, run against 120 pages (1,272 chunks) of the FastAPI docs at commit 52159d7. Updated Oct 5, 2026.

Right page in the top 5
100%
40 answerable questions
Answers supported by sources
100%
Human-reviewed (LLM judge: 95%)
Expected facts covered
93%
Hand-written reference facts
Correct refusals
100%
6 questions the docs can't answer

Retrieval: does the right page reach the model?

Four strategies on the same questions. A hit means a chunk from the expected page was retrieved. The model sees the top 5, so hit@5 is the number that matters most; reranking gets it to 100% at the cost of about 361 ms on a laptop CPU.

First result is right
Top-ranked chunk comes from the expected page
BM25 (keywords)55%
Dense embeddings65%
Hybrid (RRF)75%
Hybrid + rerank65%
Right page in top 5
What the language model actually gets to read
BM25 (keywords)78%
Dense embeddings95%
Hybrid (RRF)93%
Hybrid + rerank100%
Mean reciprocal rank
Rewards ranking the right page higher
BM25 (keywords)0.64
Dense embeddings0.78
Hybrid (RRF)0.82
Hybrid + rerank0.78
View as table
Strategyhit@1hit@3hit@5MRR@10Latency p50
BM25 (keywords)55%70%78%0.6441 ms
Dense embeddings65%90%95%0.7843 ms
Hybrid (RRF)75%85%93%0.8215 ms
Hybrid + rerank65%83%100%0.778361 ms

Answers: grounded, cited, and honest about gaps

Every model gets the same retrieved sources and the same prompt. Local models run through Ollama on a laptop; hosted ones use free API tiers. Faithfulness and fact coverage are scored by an LLM judge (qwen2.5:7b, local); citations and refusals are checked deterministically.

Metricqwen2.5:7bqwen2.5-coder:7bopenai/gpt-oss-20bqwen/qwen3.8-27b
Faithfulness
Every claim is supported by the retrieved sources
90%90%90%95%
Fact coverage
Share of expected facts the answer states
91%88%94%93%
Citation rate
Answers that cite at least one source
100%35%98%100%
Correct refusals
Says it can't answer when the docs don't cover it
100%100%100%100%
False refusals
Refuses a question the docs do answer
0%0%0%0%
Latency p50
End to end. Hosted models include free-tier rate-limit waits during the batch run
11.6 s14.3 s4.5 s16.7 s

Follow-up questions

"How do I test them?" means nothing to a search index. Before retrieval, an LLM rewrites the follow-up into a standalone question using the conversation. Measured on 12 two-turn conversations, rewritten by qwen/qwen3.8-27b.

Right page in top 5
Searching with the follow-up as written vs. rewritten
Follow-up as written67%
Previous question + follow-up92%
LLM rewrite (shipped)100%
First result is right
Top-ranked chunk comes from the expected page
Follow-up as written50%
Previous question + follow-up67%
LLM rewrite (shipped)83%

Example: "Can I also use them from inside a dependency?" becomes "Can I use BackgroundTasks from inside a dependency in FastAPI?". As written, the right page was not in the top 10.

Checking the judge

I read every answer the judge marked as unfaithful. Most flags were the judge confusing "unsupported" with "incomplete". The real failures were invented code and one inverted piece of advice. Human-corrected scores below.

ModelFlagged by judgeActually unfaithfulJudge scoreAfter review
qwen/qwen3.8-27blive2095%100%
openai/gpt-oss-20b4190%98%
qwen2.5:7b4290%95%

Real outputs, including failures

Grounded and completeHow do I run some code after the response has already been sent to the client?

There are two main ways: 1. **Background Tasks** — You can define background tasks to be run *after* returning a response [2]. 2. **Dependencies with `yield`** — By default (with `scope="request"`), the exit code after `yield` is executed **after** the response is sent to the client [1][4]. ```python from fastapi import BackgroundTasks, FastAPI app = FastAPI() async def send_email(email: str): ... @app.post("/contact") def contact(email: str, background_tasks: BackgroundTasks): background_tasks.add_task(send_email, email) return {"message": "Email will be sent in the background"} ``` Background tasks are useful for operations like sending email notifications or processing data where the client doesn't need to wait for completion [2].

Flagged by the judgeHow do I allow my React frontend running on another domain to call my API?

To allow a frontend on a different origin to call your API, you need to configure **CORS (Cross-Origin Resource Sharing)** on your backend [4]. The browser sends an HTTP `OPTIONS` preflight request to your backend, and if the backend sends the appropriate headers authorizing the communication from that origin, the browser will let the frontend's JavaScript send its request [4]. Your backend must have a list of **allowed origins** that includes the origin of your frontend (e.g., `http://localhost:8080`) [4]. The sources explain the concept but do not include the specific FastAPI code for configuring CORS middleware.

Unsupported per judge: The sources do not include the specific FastAPI code for configuring CORS middleware.
Correct refusalHow do I deploy FastAPI to Kubernetes using Helm charts?

I couldn't find this in the FastAPI documentation.

Choosing the reranker

No free cross-encoder won on every metric. The smallest one is the only option that put the right page in the context window for every question, and it is the fastest. Measured with 20 candidates; production reranks 12, which keeps hit@5 at 100% and halves CPU time on a 1 vCPU serverless function.

Rerankerhit@1hit@5MRRp50
ms-marco-MiniLM-L-6-v2shipped70%100%0.813667 ms
ms-marco-MiniLM-L-12-v270%100%0.8201.3 s
jina-reranker-v1-turbo-en75%90%0.804719 ms
bge-reranker-base75%95%0.8324.2 s

Known limits

  • The question set is small and hand-written, so a single question moves a metric by 2.5 points.
  • The judge is a 7B local model. It is cheap and reproducible, but was wrong on most of its flags, so headline faithfulness is human-reviewed.
  • Free API tiers cap throughput. The fallback chain and answer cache cover demo traffic, not production load.
  • Embeddings are English-only. Questions in other languages retrieve worse.
  • Relevance is scored per page, not per section.