Reference

KAI RAG API

Hybrid-retrieval RAG over your indexed documents. Answers include bracketed citations, per-claim verification verdicts, and a composite confidence score. Requests are scoped to a workspace by the `kai_guest_id` cookie.

Authenticate with an x-api-key header, or configure a server-side GOOGLE_API_KEY. Requests are scoped to the workspace in the kai_guest_id cookie.

POST/api/v1/ask

Ask a grounded question

Retrieves evidence, generates a cited answer, verifies each citation, and returns a confidence breakdown. Declines to answer when retrieval confidence falls below `abstainThreshold`.

  • 200 Answer with citations and confidence
  • 400 No indexed documents or invalid request
  • 401 Missing or rejected API key
  • 429 Rate limited
POST/api/v1/ingest

Index a document

Accepts multipart form data with a `file` field, or JSON with `filename` and `content` for text formats. Near-duplicate chunks are skipped unless `dedupe` is false.

  • 201 Indexed
  • 400 Unsupported file type or malformed body
  • 413 File too large
GET/api/v1/documents

List indexed documents

  • 200 Documents in this workspace
POST/api/documents/{id}/reindex

Re-chunk a document with another strategy

  • 200 Re-indexed
  • 404 Document not found
  • 409 No stored text or file to re-index
POST/api/retrieval/compare

Compare hybrid, dense, and sparse retrieval

Runs one question through each retrieval mode and reports ranked passages, per-mode stats, and pairwise overlap. No generation.

  • 200 Per-mode retrieval results
GET/api/health

Database and vector store health

  • 200 Component status
POST/api/chat

Streaming chat (newline-delimited JSON)

Same pipeline as /api/v1/ask, streamed as NDJSON. Event types arrive in order: meta (chat id, sources, retrieval stats), repeated delta (answer text), verification (per-claim verdicts), confidence (composite score), then done. Errors arrive as error.