Evaluation¶
Measure retrieval on your own documents before you choose a search
mode, a reranker, a chunking setup or llm_context. What helps on one
corpus can hurt on another, so it is better to measure than to guess.
It takes two steps:
flowchart LR
A["1. questions<br/>(LLM-written, or yours)"] --> B["review, keep the file"]
B --> C["2. evaluate<br/>configs side by side"]
C --> D["metrics + misses"]
D -. change chunking / llm_context,<br/>re-process .-> C
1. Get test questions¶
Let the LLM write them¶
With an LLM configured, Pagelore samples chunks, spread across the documents. For each one, the LLM writes a question the chunk answers, in other words than the chunk uses:
curl -X POST localhost:8000/api/v1/projects/1/evaluation/questions \
-H 'Content-Type: application/json' -d '{"count": 50, "seed": 1}' > questions.json
{
"project_id": 1,
"questions": [{
"id": "q1",
"query": "How much did ACME's revenue grow in Q3?",
"relevant": [{"document_id": 4, "char_start": 18200, "char_end": 19150}],
"source": {"citation": "report.pdf, page 12", "excerpt": "...",
"answer": "revenue grew 12% year on year"}
}],
"requested": 50, "skipped": 2,
"model": "gpt-5-mini", "input_tokens": 41200, "output_tokens": 3100,
"took_ms": 18234.0, "warnings": []
}
| Option | Default | |
|---|---|---|
count |
20 |
Questions to write, 1 to 200. Each is one LLM call |
document_ids |
all | Only ask about these documents |
seed |
random | Sample the same chunks again |
min_chars |
200 |
Skip chunks shorter than this (headings, fragments) |
instructions |
Extra guidance for the LLM, up to 1000 characters. For example: "Ask as a new employee would, in a few words." |
- The answer is a character range of the document, not a chunk id, so the questions stay valid after you re-chunk.
source.answeris the passage's own words that answer the question, as the LLM copied them. It isnullwhen they are not found in the passage. Use it to review the question, or as atextquote.skippedcounts sampled chunks the LLM found nothing to ask about. A chunk whose reply fails is replaced by another one, with a warning.- Requests run in parallel, up to
LLM_CONCURRENCY.
Review the questions
Generated questions are a starting point. Read them, remove the bad ones (too vague, answerable from anywhere, or wrong), and keep the file. The same file should be reused for every comparison.
| Status | When |
|---|---|
| 400 | The project has no indexed chunks to ask about |
| 404 | The project does not exist |
| 409 | No LLM is configured |
| 502 | The LLM failed |
Write them yourself¶
A question is a query and a list of relevant items (1 to 100). Each item
is one of these:
| Relevant item | Counts a result as relevant when |
|---|---|
{"chunk_id": 412} |
It is that chunk (or a parent that covers it) |
{"document_id": 7} |
It comes from that document |
{"document_id": 7, "char_start": 1200, "char_end": 1650} |
It overlaps that range of the document's text (see min_overlap) |
{"text": "notice period of 30 days"} |
Its text contains the quote |
{"document_id": 7, "text": "..."} |
It is from that document and contains the quote |
{"questions": [
{"id": "notice", "query": "How long is the notice period for contractors?",
"relevant": [{"text": "contractors must give 30 days notice"}]},
{"id": "vpn", "query": "VPN setup on Linux",
"relevant": [{"document_id": 12}, {"document_id": 15}]}
]}
Quotes compare words only: case, spacing, punctuation and Markdown are
ignored. char_start / char_end are the same offsets that chunk metadata
reports, so you can copy them from GET .../documents/{doc}/chunks.
2. Evaluate¶
Run every question through retrieval with each config:
curl -X POST localhost:8000/api/v1/projects/1/evaluate -H 'Content-Type: application/json' \
-d '{"questions": [...], "top_k": 5, "configs": [
{"name": "vector", "options": {"mode": "vector"}},
{"name": "hybrid", "options": {"mode": "hybrid"}},
{"name": "hybrid+rerank", "options": {"mode": "hybrid", "rerank": true}}]}'
{
"project_id": 1, "question_count": 48, "top_k": 5, "min_overlap": 0.5,
"configs": [{
"name": "hybrid+rerank",
"options": {"mode": "hybrid", "rerank": true},
"metrics": {"hit_rate": 0.92, "mrr": 0.81, "ndcg": 0.84, "recall": 0.92,
"precision": 0.2, "latency_ms_avg": 182.4, "latency_ms_p95": 260.1},
"details": [{"id": "q17", "query": "...", "hit": false, "recall": 0.0,
"results": [{"rank": 1, "citation": "...", "relevant": false}]}]
}],
"best": "hybrid+rerank",
"took_ms": 9120.5
}
| Option | Default | |
|---|---|---|
questions |
1 to 500. Generated questions can be sent back as they are (source is ignored) |
|
configs |
vector, keyword, hybrid |
1 to 10 configs, each a unique name and options |
top_k |
5 |
Results per question. Every metric is at top_k |
min_overlap |
0.5 |
How much a result must overlap a character range (see below) |
details |
misses |
Per-question results: none, misses (questions with no relevant result) or all |
A config's options take every option of
/retrieve except query, vector and
top_k: mode, alpha, fusion, keyword_match, rerank, filters,
neighbors, diversity, return_parents, ... Unknown or invalid options
are rejected with the config's name.
- Each query is embedded once and shared by all configs, so
latency_ms_*measures retrieval, not embedding. - Evaluation itself needs no LLM. A config with a
query_transformdoes: it makes one LLM call per question, its latency includes that call, and it reports the tokens used inllm_tokens({"input", "output"}).historyis not accepted there. - A config with
graphuses the project's knowledge graph; build it first. bestis the config with the highest nDCG, then MRR, then the fastest.
Metrics¶
| Metric | Meaning (at top_k) |
|---|---|
hit_rate |
Share of questions with at least one relevant result |
mrr |
Mean of 1 / rank of the first relevant result |
ndcg |
Ranking quality: relevant results near the top score higher. Binary relevance; each relevant item is credited once |
recall |
Mean share of each question's relevant items that were found |
precision |
Mean share of the returned results that are relevant |
latency_ms_avg, latency_ms_p95 |
Retrieval time per question |
When is a result relevant?¶
- Character range: the result overlaps it by at least
min_overlapof the shorter of the two. So a re-chunked passage that still holds most of the answer counts. - Chunk: the result is that chunk.
- Quote: the result's text contains the quote's words, in order.
- Parents: a parent passage (small-to-big) counts for every chunk it covers.
Common comparisons¶
These change the stored chunks, so they can't be configs. Evaluate, re-process, and evaluate again with the same questions:
H='Content-Type: application/json'
curl -X POST localhost:8000/api/v1/projects/1/evaluate -H "$H" -d @eval.json > before.json
curl -X PATCH localhost:8000/api/v1/projects/1 -H "$H" \
-d '{"chunking": {"llm_context": true}}'
curl -X POST localhost:8000/api/v1/projects/1/reindex -H "$H" -d '{"all": true}'
curl -X POST localhost:8000/api/v1/projects/1/evaluate -H "$H" -d @eval.json > after.json
Because answers are character ranges or quotes, the questions stay valid across chunkings.
To compare Pagelore's native extraction with Docling on your files, see Native vs Docling.