LLM and evaluation¶
The configured LLM, and the endpoints that measure retrieval on your own data. Pagelore uses the LLM only for its own work (contextual chunks, query transformations, graph extraction, test questions), never to answer questions. See LLM and Evaluation.
Paths are relative to /api/v1. The examples use BASE=http://localhost:8000/api/v1
and an API key in $KEY.
GET /llm/model¶
The configured LLM. Needs read.
Response: 200
| Field | Type | |
|---|---|---|
provider |
string | Such as openai, anthropic, gemini, ollama |
model |
string | |
max_tokens |
integer | The most tokens per reply (LLM_MAX_TOKENS) |
temperature |
number or null | null: the model's default |
structured_output |
string | How JSON replies are enforced: schema (a JSON schema), json (JSON mode) or prompt (asked for in the prompt) |
Errors: 409 when no LLM is configured (LLM_PROVIDER).
{"provider": "openai", "model": "gpt-4.1-mini", "max_tokens": 1024, "temperature": null,
"structured_output": "schema"}
POST /llm/check¶
Send a one-line request to the LLM and report whether it answered with
valid JSON, how long it took and the tokens used. No body. Needs write
(it spends tokens).
A failing LLM is reported in the body (ok: false and error), not as an
HTTP error, so you can see why. Fields that don't apply are left out.
Response: 200: the fields of GET /llm/model, plus:
| Field | Type | |
|---|---|---|
ok |
boolean | The model replied with the expected JSON |
latency_ms |
number | |
attempts |
integer | Calls it took to get valid JSON |
input_tokens, output_tokens |
integer | |
finish_reason |
string | As the provider reported it, such as stop |
error |
string | Why the check failed. API keys are masked |
Errors: 409 when no LLM is configured.
{"provider": "ollama", "model": "qwen3:8b", "max_tokens": 1024, "structured_output": "schema",
"ok": true, "latency_ms": 812.4, "attempts": 1, "input_tokens": 61, "output_tokens": 9,
"finish_reason": "stop"}
POST /projects/{project_id}/evaluation/questions¶
Write a synthetic test set. Pagelore samples chunks, spread over the
documents, and has the LLM write for each one a question that the chunk
answers, in other words. The chunk's character range in its document is
the relevant answer, so the set stays valid after the documents are
re-chunked. Review the questions, keep the good ones, and send them to
POST .../evaluate. Needs write and
an LLM.
Body (JSON, every field optional, unknown fields refused):
| Field | Type | Allowed values | Default | |
|---|---|---|---|---|
count |
integer | 1 to 200 | 20 |
Questions to write (one LLM call each) |
document_ids |
list of integers | 1 to 10000 | all | Only ask about these documents |
seed |
integer | random | Sample the same chunks again | |
min_chars |
integer | 0 to 100000 | 200 |
Skip chunks shorter than this (headings, fragments) |
instructions |
string | up to 1000 characters | Extra guidance for the LLM, such as "Ask as a new employee would, in a few words." |
Response: 200. Fields that don't apply are left out.
| Field | |
|---|---|
project_id |
|
questions |
The questions: {id, query, relevant, source}. id is q1, q2, ...; relevant is [{"document_id", "char_start", "char_end"}] (or [{"chunk_id"}] for a chunk without a character range); source is the chunk it came from: {chunk_id, document_id, chunk_index, file_name, citation, excerpt, answer}, to review it |
requested |
count |
skipped |
Sampled chunks the LLM found nothing to ask about |
model |
The LLM |
input_tokens, output_tokens |
Tokens used |
took_ms |
|
warnings |
For example, fewer chunks qualify than count, or the LLM failed on some chunks |
Errors:
| Status | When |
|---|---|
| 400 | The project has no indexed chunks to ask about |
| 404 | The project does not exist |
| 409 | No LLM is configured |
| 422 | A field is invalid |
| 502 | The LLM failed |
curl -X POST "$BASE/projects/1/evaluation/questions" -H "Authorization: Bearer $KEY" \
-H 'Content-Type: application/json' \
-d '{"count": 50, "seed": 7, "instructions": "Ask briefly, as a customer would."}' \
> questions.json
{
"project_id": 1,
"questions": [
{"id": "q1", "query": "How long do I have to send an item back?",
"relevant": [{"document_id": 31, "char_start": 18200, "char_end": 19150}],
"source": {"chunk_id": 912, "document_id": 31, "chunk_index": 14, "file_name": "terms.pdf",
"citation": "terms.pdf, page 6, Payments > Refunds",
"excerpt": "Refunds are issued within 14 days of a return...",
"answer": "Within 30 days of delivery."}}
],
"requested": 50, "skipped": 1, "model": "gpt-4.1-mini",
"input_tokens": 41200, "output_tokens": 2900, "took_ms": 21450.3, "warnings": []
}
POST /projects/{project_id}/evaluate¶
Run each question through retrieval with each config, and report hit rate,
MRR, nDCG, recall and precision at top_k, with latency. Use it to compare
modes, rerankers, chunking or contextual chunks on your own data. Needs
write. It needs no LLM, unless a config uses query_transform. A config
searches every document of the project, unless its options name a user:
then it searches only what that user (or those groups) may see, as
retrieval does. Compare configs that differ
only in user to see how document access changes the results.
Body (JSON, unknown fields refused):
| Field | Type | Allowed values | Default | |
|---|---|---|---|---|
questions |
list | 1 to 500 | required | The questions (below). The output of .../evaluation/questions can be sent as it is |
configs |
list | 1 to 10, unique names | vector, keyword and hybrid | Retrieval option sets to compare (below) |
top_k |
integer | 1 to 100 | 5 |
Results per question; the metrics are at top_k |
min_overlap |
number | more than 0, at most 1 | 0.5 |
A result covers a character range when they share this fraction of the shorter of the two, so re-chunked text still counts |
details |
string | none, misses, all |
misses |
Per-question results: none, the questions with no relevant result, or all |
Each question:
| Field | Type | Allowed values | |
|---|---|---|---|
id |
string | up to 200 characters | Optional; q1, q2, ... by default |
query |
string | 1 to 10000 characters | Required |
relevant |
list | 1 to 100 relevant items | Required: what answers it (below) |
source |
object | Ignored, so generated questions can be sent back unchanged |
Each relevant item (unknown fields refused) needs a chunk_id, a
document_id or a text:
| Relevant item | A result is 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 by min_overlap. Give both ends, with char_end greater; a range needs a document_id and can't have a text |
{"text": "notice period of 30 days"} |
Its text contains the quote (1 to 5000 characters). Words are compared: case, spacing, punctuation and Markdown are ignored |
{"document_id": 7, "text": "..."} |
It is from that document and contains the quote |
Each config:
| Field | Type | |
|---|---|---|
name |
string, 1 to 100 characters | Unique |
options |
object | Any retrieve option except query, vector and top_k: mode, alpha, fusion, rrf_k, keyword_match, rerank, rerank_candidates, filters, neighbors, diversity, return_parents, candidates, query_transform (without history), graph, ... Validated like a retrieve request. user ({id, groups}) searches as that user; each config can name a different one |
Response: 200. Fields that don't apply are left out.
| Field | |
|---|---|
project_id, question_count, top_k, min_overlap |
|
configs |
One report per config, below |
best |
The config with the highest nDCG (then MRR, then the fastest) |
took_ms |
|
warnings |
For example, relevant chunk ids that do not exist in the project |
Each config report:
| Field | |
|---|---|
name, options |
As sent |
metrics |
hit_rate (share of questions with a relevant result in the top top_k), mrr (mean reciprocal rank of the first relevant result), ndcg (mean nDCG at top_k, binary relevance, each relevant item credited once), recall (mean share of each question's relevant items found), precision (mean share of the top_k results that are relevant), latency_ms_avg, latency_ms_p95 (retrieval time per question; the query is embedded once, outside it) |
llm_tokens |
With query_transform: {"input", "output"} tokens for all questions |
warnings |
Retrieval warnings, such as documents still being indexed |
details |
With details misses or all: {id, query, hit, first_relevant_rank, recall, results}; each result is {rank, score, chunk_id, document_id, file_name, citation, relevant} |
Errors:
| Status | When |
|---|---|
| 404 | The project does not exist, or its collection is gone |
| 409 | The index can't be searched with the configured model, or a config asks for reranking or query_transform without a reranker or LLM configured |
| 422 | A question, item or config is invalid (unknown option, a duplicate name, query_transform.history, a bad user id or group name, ...) |
| 502 | The embedding provider, reranker or LLM failed |
curl -X POST "$BASE/projects/1/evaluate" -H "Authorization: Bearer $KEY" \
-H 'Content-Type: application/json' -d '{
"questions": [
{"id": "notice", "query": "How much notice must contractors give?",
"relevant": [{"text": "contractors must give 30 days notice"}]},
{"query": "Which offices allow remote work?",
"relevant": [{"document_id": 12}, {"document_id": 15}]}
],
"configs": [
{"name": "vector", "options": {"mode": "vector"}},
{"name": "hybrid", "options": {"mode": "hybrid", "alpha": 0.4}},
{"name": "hybrid+rerank", "options": {"mode": "hybrid", "rerank": true}},
{"name": "hybrid+graph", "options": {"mode": "hybrid", "graph": {}}},
{"name": "hybrid as ana", "options": {"mode": "hybrid", "user": {"id": "ana@acme.com"}}}
],
"top_k": 5,
"details": "misses"
}'
{
"project_id": 1, "question_count": 2, "top_k": 5, "min_overlap": 0.5,
"configs": [
{"name": "hybrid+rerank", "options": {"mode": "hybrid", "rerank": true},
"metrics": {"hit_rate": 1.0, "mrr": 1.0, "ndcg": 0.92, "recall": 1.0, "precision": 0.4,
"latency_ms_avg": 210.5, "latency_ms_p95": 260.1},
"warnings": [], "details": []}
],
"best": "hybrid+rerank",
"took_ms": 1650.2,
"warnings": []
}