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.
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.
View as table
| Strategy | hit@1 | hit@3 | hit@5 | MRR@10 | Latency p50 |
|---|---|---|---|---|---|
| BM25 (keywords) | 55% | 70% | 78% | 0.644 | 1 ms |
| Dense embeddings | 65% | 90% | 95% | 0.784 | 3 ms |
| Hybrid (RRF) | 75% | 85% | 93% | 0.821 | 5 ms |
| Hybrid + rerank | 65% | 83% | 100% | 0.778 | 361 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.
| Metric | qwen2.5:7b | qwen2.5-coder:7b | openai/gpt-oss-20b | qwen/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 s | 14.3 s | 4.5 s | 16.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.
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.
| Model | Flagged by judge | Actually unfaithful | Judge score | After review |
|---|---|---|---|---|
| qwen/qwen3.8-27blive | 2 | 0 | 95% | 100% |
| openai/gpt-oss-20b | 4 | 1 | 90% | 98% |
| qwen2.5:7b | 4 | 2 | 90% | 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.
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.
| Reranker | hit@1 | hit@5 | MRR | p50 |
|---|---|---|---|---|
| ms-marco-MiniLM-L-6-v2shipped | 70% | 100% | 0.813 | 667 ms |
| ms-marco-MiniLM-L-12-v2 | 70% | 100% | 0.820 | 1.3 s |
| jina-reranker-v1-turbo-en | 75% | 90% | 0.804 | 719 ms |
| bge-reranker-base | 75% | 95% | 0.832 | 4.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.