RAG Query API Server

OpenAPI 3.1 · Base: https://militarymanuals.ai

Endpoints

GET/api/admin/document/{doc_id}

Admin Get Document

Return full document detail: all chunks + per-page image list. Searches all known collections in parallel for all chunks belonging to doc_id. Requires X-Admin-Key header.

doc_id (path) string required
x-admin-key (header) string
Responses
200 Successful Response
422 Validation Error
DELETE/api/admin/document/{doc_id}

Admin Delete Document

Delete a document from Qdrant, registry.json, and image files. Requires X-Admin-Key header.

doc_id (path) string required
x-admin-key (header) string
Responses
200 Successful Response
422 Validation Error
GET/api/admin/documents

Admin List Documents

Return all documents from registry with chunk counts from Qdrant. Requires X-Admin-Key header.

x-admin-key (header) string
Responses
200 Successful Response
422 Validation Error
DELETE/api/cache/collections

Invalidate Collections Cache

Invalidate the collections metadata cache. Call after updating collection data.

collection (query) string
Optional: invalidate only this collection
Responses
200 Successful Response
422 Validation Error
DELETE/api/cache/images

Invalidate Image Cache

Invalidate the image listing cache. Call after image ingestion.

Responses
200 Successful Response
DELETE/api/cache/query

Invalidate Query Cache

Invalidate the content-addressed query result cache. Call after pipelines F or G upsert data.

collection (query) string
Optional: invalidate only this collection's query cache
Responses
200 Successful Response
422 Validation Error
GET/api/catalog

Get Catalog

Return documents grouped by branch/collection, filtered to only those indexed in Qdrant. Titles, pub_year, category, page_count, and ia_identifier are sourced directly from Qdrant payloads — the same data stored at ingest time from the registry. This ensures the catalog always reflects the authoritative Qdrant state.

Responses
200 Successful Response
GET/api/collection/search

Search Collection

Semantic search within a specific collection. Returns matching chunks from all documents in the collection, ranked by vector similarity.

collection (query) string required
Collection name
q (query) string required
Search query
top_k (query) integer
Max results to return
Responses
200 Successful Response
422 Validation Error
GET/api/collections

List Collections

List all collections with their metadata (parallel fetch, Ruff-style).

Responses
200 Successful Response
GET/api/collections/{collection}

Get Collection

Get info for a single collection.

collection (path) string required
Responses
200 Successful Response
422 Validation Error
GET/api/context

Get Context

Get chunks from a document. Two modes: - No query param + limit=0: returns sequential chunks centered around chunk_index (window-based). - No query param + limit>0: returns up to `limit` consecutive chunks starting at chunk_index. - With query param: returns semantically ranked chunks matching the query, filtered to this document only (top_k = window param). Args: doc_id: The document ID chunk_index: The center chunk index for sequential mode (0-based) collection: The collection name window: For sequential mode, window size (2*window+1 chunks returned). For semantic mode, top_k limit. query: If provided, triggers semantic search within this document

doc_id (query) string required
Document ID
chunk_index (query) integer
Chunk index (0-based)
collection (query) string required
Collection name
window (query) integer
Window size (returns 2*window+1 chunks, used when limit is not set)
query (query) string
Optional: semantic search query within this document
limit (query) integer
If > 0, return up to this many consecutive chunks starting at chunk_index (ignores window)
Responses
200 Successful Response
422 Validation Error
GET/api/doc/{doc_id}

Get Document

Get document metadata from Qdrant payload. Returns document metadata from the first matching point found. Searches across all known collections using Qdrant filters for efficiency. Args: doc_id: The document ID to retrieve metadata for Returns: Dictionary with document metadata fields (title, branch, category, etc.)

doc_id (path) string required
Responses
200 Successful Response
422 Validation Error
GET/api/images/{doc_id}/{page_num}

List Images For Page

List images for a specific page of a document. Args: doc_id: The document ID page_num: The page number to list images for Returns: Dictionary with 'images' list containing image filenames for that page

doc_id (path) string required
page_num (path) integer required
Responses
200 Successful Response
422 Validation Error
GET/api/manifest

Api Manifest

Return machine-readable API manifest auto-generated from FastAPI routes. No manual maintenance — every route registered with the app appears here.

Responses
200 Successful Response
GET/api/openapi.json

Get Openapi Json

Return OpenAPI 3.1 specification auto-generated from FastAPI routes. This is a proxy to FastAPI's built-in openapi schema — no manual maintenance required. Every route registered with the app automatically appears here.

Responses
200 Successful Response
GET/api/provenance/poll/{job_id}

Poll Kurier Status

Poll Kurier job status — no auth required. This is a thin proxy to poll_zkverify_job that bypasses nginx's auth layer so browsers can poll without an API key.

job_id (path) string required
Responses
200 Successful Response
422 Validation Error
POST/api/provenance/prove

Prove Chunk

Generate a ZK proof for a specific chunk identified by doc_id and chunk_id. Takes a doc_id + chunk_id + collection, fetches the chunk from Qdrant, generates a ZK proof for it, and returns the chunk payload plus proof fields. Used by the website's next/previous chunk navigation with provenance.

Request body · application/json
$ref ProvenanceProveRequest
Responses
200 Successful Response
422 Validation Error
GET/api/provenance/status/{job_id}

Get Proof Status

Poll Kurier job status for a proof verification job. Returns current status and, if complete, the verification result.

job_id (path) string required
Responses
200 Successful Response
422 Validation Error
POST/api/provenance/submit

Submit Proof

Submit a ZK proof to Kurier/zkVerify for on-chain verification. Accepts proof data directly (no server-side cache required). Returns job_id immediately for polling.

Request body · application/json
$ref ProveSubmitRequest
Responses
200 Successful Response
422 Validation Error
POST/api/query

Query

Vector search endpoint using Qdrant similarity search. Accepts a natural language query and returns relevant document chunks from Qdrant using vector similarity search. Supports single collection search or cross-collection search with collection='*'. Args: request: QueryRequest with query text, top_k, and collection Returns: QueryResponse with matching chunks, query, collection, and total count

Request body · application/json
$ref QueryRequest
Responses
200 Successful Response
422 Validation Error
POST/api/query-provable

Query Provable

Vector search with ZK proofs attached to every result chunk. Flow: 1. Query Qdrant (vector similarity) 2. Generate ZK proofs in parallel for all result chunks 3. Return only chunks that have successfully generated proofs No chunk text is returned for a chunk unless its ZK proof exists. Proof generation runs in parallel, capped by ZK_PROOF_PARALLELISM env var (default 2, set to 4 on the R730, 2 on the VPS). Args: request: QueryProvanableRequest with query text, top_k, and collection Returns: QueryProvanableResponse with chunks (each with zk_proof attached), plus a proofs dict keyed by chunk_id.

Request body · application/json
$ref QueryProvanableRequest
Responses
200 Successful Response
422 Validation Error
GET/api/source/{doc_id}

Get Source Pdf

Stream the source PDF for a document, requiring X402 payment proof. Without a Payment-Signature header: returns 402 with PAYMENT-REQUIRED. With a valid EIP-3009 PaymentPayload: streams the PDF file.

doc_id (path) string required
Responses
200 Successful Response
422 Validation Error
GET/api/source/{doc_id}/info

Get Source Info

Return document metadata and price for paid PDF download.

doc_id (path) string required
Responses
200 Successful Response
422 Validation Error
GET/health

Health

Health check endpoint — verifies Qdrant and embedding service.

Responses
200 Successful Response