RAG API Documentation

April 27, 2026 ยท View on GitHub

This is the concise endpoint reference for the active unified RAG API. For implementation internals and contributor guidance, see RAG-Developer-Guide.md.

Base URL

/api/v1/rag

The unified router is implemented in tldw_Server_API/app/api/v1/endpoints/rag_unified.py. Health and operations routes are implemented in tldw_Server_API/app/api/v1/endpoints/rag_health.py.

Authentication

  • Single-user mode: X-API-KEY: <key>
  • Multi-user mode: Authorization: Bearer <JWT>

Deployments may also enforce RBAC scopes and rate limits.

Unified Routes

MethodRoutePurpose
POST/ablateCompare configured retrieval/generation variants for one query.
GET/capabilitiesReturn runtime-supported RAG capabilities, defaults, limits, and quick-start payloads.
GET/vlm/backendsList available VLM/table-processing backends.
POST/searchRun the primary unified RAG search pipeline.
POST/feedback/implicitRecord implicit interaction events such as clicks, expansions, copies, dwell time, and citation use.
POST/batchRun multiple RAG queries concurrently.
GET/simpleConvenience search endpoint using query parameters.
POST/batch/resume/{checkpoint_id}Resume a checkpointed batch run.
POST/search/streamStream generated answer events as NDJSON.
GET/advancedConvenience endpoint enabling common advanced options.
GET/featuresReturn feature groups and request parameter names.
GET/health/simpleLightweight unified-pipeline health check.

Health And Operations Routes

MethodRoutePurpose
GET/healthComprehensive RAG health report.
GET/health/liveLiveness probe.
GET/health/readyReadiness probe.
GET/cache/statsCache statistics and recommendations.
POST/cache/clearClear RAG caches.
GET/cache/warmCache warmer status.
GET/metrics/summaryRecent RAG metrics summary.
GET/costs/summaryCost tracking summary, when configured.
GET/batch/jobsBatch job state summary.
POST/quality-gateRun a quality-gate check.
POST/baseline/saveSave a RAG regression baseline.
GET/regression/checkLoad a stored regression baseline by baseline_id.
POST/regression/checkCompare current metrics against a stored regression baseline.

Primary Request And Response Models

  • UnifiedRAGRequest
  • UnifiedRAGResponse
  • UnifiedBatchRequest
  • UnifiedBatchResponse

Public request sources are:

  • media_db
  • notes
  • characters
  • chats
  • kanban
  • sql

characters and chats are separate public source values, but they currently share the character/chat retrieval backend.

Public request search_mode values are:

  • fts
  • vector
  • hybrid

search_mode is accepted for all searches, but vector behavior depends on the selected sources and configured vector adapters. Sources without vector indexing use their source-specific retrieval path.

Examples

curl -X POST http://localhost:8000/api/v1/rag/search \
  -H "X-API-KEY: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "machine learning applications",
    "sources": ["media_db", "notes"],
    "search_mode": "hybrid",
    "top_k": 10,
    "enable_reranking": true,
    "enable_generation": false
  }'

Generated Answer

curl -X POST http://localhost:8000/api/v1/rag/search \
  -H "X-API-KEY: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Summarize the strongest evidence for this topic",
    "sources": ["media_db"],
    "search_mode": "hybrid",
    "enable_generation": true,
    "enable_citations": true
  }'
curl -X POST http://localhost:8000/api/v1/rag/search \
  -H "X-API-KEY: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Compare the main arguments across my notes",
    "sources": ["notes"],
    "strategy": "agentic",
    "enable_generation": true
  }'

POST /search/stream returns NDJSON. Streaming requires enable_generation: true.

curl -N -X POST http://localhost:8000/api/v1/rag/search/stream \
  -H "X-API-KEY: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Explain transformer attention",
    "search_mode": "hybrid",
    "enable_generation": true
  }'

Common event types include delta, claims_overlay, and final_claims.

curl -X POST http://localhost:8000/api/v1/rag/batch \
  -H "X-API-KEY: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "queries": ["What is RAG?", "Explain vector search"],
    "sources": ["media_db"],
    "search_mode": "hybrid",
    "max_concurrent": 5,
    "enable_checkpoint": true
  }'

Resume A Batch

curl -X POST http://localhost:8000/api/v1/rag/batch/resume/checkpoint-id \
  -H "X-API-KEY: your-api-key"

Capabilities And Health

curl http://localhost:8000/api/v1/rag/capabilities \
  -H "X-API-KEY: your-api-key"

curl http://localhost:8000/api/v1/rag/health \
  -H "X-API-KEY: your-api-key"

Error Handling

Typical responses:

  • 400 for invalid request fields or unsupported combinations.
  • 401 or 403 for missing credentials, invalid credentials, or missing permissions.
  • 429 for rate-limit failures.
  • 500 for unexpected service errors.