Skip to main content

Module api

Module api 

Source
Expand description

REST API over a Pipeline: document info and search in every retrieval mode.

Authentication is a static API-key list from config (RAG_API_KEYS), accepted as X-Api-Key: <key>, Authorization: Bearer <key>, or — for links a browser opens directly, where no header can be set — ?api_key=<key>. Auth is fail-closed: router errors when the key list is empty. GET /health is public.

Endpoints (all under auth except / and /health):

MethodPathDescription
GET/built-in search UI (public; static HTML)
GET/healthliveness probe (public)
GET/api/statsdocument / chunk counts
GET/api/documentsall documents with metadata + metrics
POST/api/documents?name=file.pdf + enrich flags, raw bytes body → ingest
GET/api/documents/{id}one document by id
GET/api/documents/{id}/markdownthe parsed Markdown (text/markdown)
DELETE/api/documents/{id}remove the document and all its chunks
GET/api/search?q=…&mode=hybrid&k=5 (also accepts POST)
POST/api/search{"query", "mode?", "top_k?", "answer?", "extend?"}

Search modes: vector, bm25, hybrid, multi-query, hyde. With answer=true the LLM synthesizes a grounded answer (needs OPENROUTER_API_KEY).

Functions§

router
Build the router. Errors if keys is empty (auth is fail-closed).
serve
Bind addr and serve until the process is stopped.