Skip to content

Upload & ingestion

Uploading is asynchronous. The Control Plane stores the raw file and creates a document row with status: "pending"; the KB Uploader worker claims it, extracts the text, chunks it, embeds it through the Core Proxy and writes the vectors to Qdrant. A 201 from the upload means queued, not searchable.

Method Path (base http://localhost:5050/v1/admin/knowledge-base) Purpose
POST /collections/{collection_id}/documents Upload one file (multipart/form-data, 201)
GET /collections/{collection_id}/documents List the collection’s documents
GET /documents/{document_id} Get one document (poll this)
PATCH /documents/{document_id} Update name, version, author
POST /documents/{document_id}/reembed Drop the document’s chunks and vectors and queue it again
DELETE /documents/{document_id} Delete the document, its chunks and its vectors (204)

Form fields: file (required), and optional name (display name, defaults to the filename), version and author.

Terminal window
curl -s -X POST \
http://localhost:5050/v1/admin/knowledge-base/collections/01K8ZQ3V7M2T4N6P8R0S2U4W6Y/documents \
-H "Authorization: Bearer $ADMIN_JWT" \
-F "file=@q3-playbook.pdf" \
-F "name=Q3 Playbook" \
-F "version=2026.3" \
-F "author=Sales Enablement"

Response 201:

{
"id": "01K8ZR1B9D3F5H7K9M1P3R5T7V",
"collection_id": "01K8ZQ3V7M2T4N6P8R0S2U4W6Y",
"tenant_id": "default",
"name": "Q3 Playbook",
"filename": "q3-playbook.pdf",
"version": "2026.3",
"author": "Sales Enablement",
"content_type": "application/pdf",
"file_size_bytes": 482113,
"status": "pending",
"error_message": null,
"chunk_count": 0,
"embedding_model": null,
"created_at": "2026-10-28T09:20:41.902114+00:00",
"updated_at": "2026-10-28T09:20:41.902114+00:00",
"created_by": "admin",
"updated_by": null
}

Errors: 404 {"detail": "Collection not found"}; 400 for an unsupported type (Unsupported content type: application/zip. Supported: …).

The upload is accepted by MIME type. When the client sends application/octet-stream (browsers often do for .md, .txt, .docx), the Control Plane falls back to the file extension.

Format Extensions MIME type Extracted with
PDF .pdf application/pdf pdftotext (poppler); author from pdfinfo
Word .docx application/vnd.openxmlformats-officedocument.wordprocessingml.document ZIP + XML parse; author from docProps/core.xml
Excel .xlsx, .xls …spreadsheetml.sheet, application/vnd.ms-excel calamine
PowerPoint .pptx …presentationml.presentation ZIP + XML parse
Legacy Word / PowerPoint .doc, .ppt application/msword, application/vnd.ms-powerpoint LibreOffice headless
HTML .html, .htm text/html scraper
CSV .csv text/csv delimiter auto-detected (, ; tab), rendered as header: value per row
Plain text, Markdown .txt, .md, .markdown text/plain, text/markdown passthrough
  1. Poll GET /documents/{document_id} every few seconds:

    Terminal window
    curl -s http://localhost:5050/v1/admin/knowledge-base/documents/01K8ZR1B9D3F5H7K9M1P3R5T7V \
    -H "Authorization: Bearer $ADMIN_JWT"
  2. Stop when status is ready or error:

    {
    "id": "01K8ZR1B9D3F5H7K9M1P3R5T7V",
    "name": "Q3 Playbook",
    "status": "ready",
    "chunk_count": 42,
    "embedding_model": "text-embedding-3-small",
    "error_message": null
    }
  3. On error, read error_message (for example text extraction failed: pdftotext timed out after 60s and was killed …), fix the cause and call POST /documents/{document_id}/reembed to queue it again.

Lifecycle: pending → processing → ready | error. The uploader polls every 5 seconds by default, so a small file is usually ready within seconds once the embedding provider answers.

import time, requests
def wait_ready(doc_id, timeout=300):
deadline = time.time() + timeout
while time.time() < deadline:
d = requests.get(f"{BASE}/v1/admin/knowledge-base/documents/{doc_id}",
headers={"Authorization": f"Bearer {ADMIN_JWT}"}).json()
if d["status"] in ("ready", "error"):
return d
time.sleep(3)
raise TimeoutError(doc_id)

For each claimed document the uploader:

  1. Resolves the embedding model: the tenant’s default_embedding_model_id, falling back to its own EMBEDDING_MODEL name when the tenant has none set.
  2. Extracts text with the extractor for the content type, under hard deadlines and output caps. Any timeout, cap or killed converter fails the document closed; nothing partial is indexed.
  3. Chunks the text: split on blank lines, then on sentence boundaries for long paragraphs, accumulating sentences to about 500 tokens (4 characters per token) with about 50 tokens of overlap.
  4. Builds BM25 sparse tokens for each chunk, for keyword matching.
  5. Embeds the chunks in batches of 50 through POST /v1/proxy/llm/embeddings on the Core Proxy, so the traffic is logged and metered.
  6. Writes one Qdrant point per chunk into brutor_kb_{tenant_id} with a dense and a sparse vector and the payload tenant_id, collection_id, document_id, chunk_index, content, source, acl, metadata. The Qdrant collection is created on first write with the model’s dimension.
  7. Stores the chunk rows, sets status: "ready", chunk_count and embedding_model, and publishes a knowledge_base invalidation on Redis so the Core Proxy clears the tenant’s response cache and reloads group configuration.
  • Metadata only: PATCH /documents/{document_id} with any of name (1–512), version (≤50), author (≤255). Content is untouched.
  • Re-process the same content (after an extraction fix or a model switch for one document): POST /documents/{document_id}/reembed. Response is the document with status: "pending" and chunk_count: 0.
  • New content: delete the document and upload the new file. There is no in-place content replace or version history on a document. The Admin UI’s Upload new version action does exactly this: it deletes the old document and uploads the new file under the same name with the version you enter.

DELETE /documents/{document_id} returns 204 and removes the vectors from Qdrant.

AI Estate → Resources → Knowledge Base → Collections → View Documents on a collection shows the documents table (Filename, Version, Author, Status, Chunks, Size, Created, Modified, Actions) with Upload Documents (multi-file; the picker accepts .pdf,.txt,.md,.html,.csv,.docx,.xlsx,.pptx,.doc,.xls,.ppt). Uploads made in the console are labelled version 1.0. The page polls statuses while documents are pending and shows Ready / Processing / Pending / Error badges. Row actions are Upload new version, Re-embed and Delete; a header action deletes all documents in the collection. The same page has Test RAG Search (see the preview).

Collections → View Documents on borealis-credit-policy: four Markdown documents (evaluation report, risk management file, affordability policy, instructions for use), each version 2026.10 by Borealis Credit Risk, Ready, with 2 to 4 chunks, and the Test RAG Search box below.

Set on the kb-uploader service. Values shown are the defaults unless marked.

Variable Default Example Purpose
DATABASE_URL required postgresql://brutor:…@postgres:5432/ai_gateway Shared database
QDRANT_URL http://qdrant:6334 http://qdrant:6334 Qdrant gRPC endpoint
QDRANT_JWT_SIGNING_SECRET required 32+ random chars Mints the per-tenant Qdrant JWTs; must match Qdrant’s API key
PROXY_INTERNAL_URL required http://gateway-core:8100 Core Proxy base URL; all embedding traffic goes through it
PROXY_SERVICE_API_KEY required the PROXY_HEALTH_CHECK_API_KEY value Service key for the proxy; also guards /api/v1/jobs
EMBEDDING_MODEL nomic-embed-text text-embedding-3-small Model name used only when the tenant has no default model
POLL_INTERVAL_SECS 5 2 Seconds between polls for pending documents
MAX_CONCURRENT_JOBS 4 8 Documents processed in parallel
CLAIM_BATCH_SIZE 8 16 Documents claimed per poll
STALE_PROCESSING_SECS 1800 3600 Re-claim a document stuck in processing
MAX_DOCUMENT_BYTES 52428800 (50 MiB) 104857600 Largest document read; larger fails with a message
CHUNK_SIZE_TOKENS 500 800 Target chunk size
CHUNK_OVERLAP_TOKENS 50 100 Overlap between consecutive chunks
EMBEDDING_BATCH_SIZE 50 100 Chunks per embedding call
EMBEDDING_CONCURRENCY 4 2 Parallel embedding calls
EXTRACT_PDF_TIMEOUT_SECS 60 120 Deadline per pdftotext / pdfinfo run (1–3600)
EXTRACT_OFFICE_TIMEOUT_SECS 120 300 Deadline per LibreOffice conversion (1–3600)
EXTRACT_PARSE_TIMEOUT_SECS 120 60 Deadline per in-process parse (1–3600)
EXTRACT_MAX_OUTPUT_BYTES 67108864 134217728 Cap on converter output (1–1073741824)
REDIS_URL unset redis://redis:6379 Cache-invalidation publish (best effort)
LISTEN_ADDR 0.0.0.0:8200 0.0.0.0:8200 Health and jobs API

Every EXTRACT_*_TIMEOUT_SECS must be shorter than STALE_PROCESSING_SECS, or the service refuses to start. Changing the chunk size affects new and re-embedded documents only.

The jobs API (GET /api/v1/jobs?tenant_id=default, GET /api/v1/jobs/{document_id}?tenant_id=default, with X-API-Key: $PROXY_SERVICE_API_KEY) returns the latest 50 documents for a tenant:

{
"jobs": [
{
"id": "01K8ZR1B9D3F5H7K9M1P3R5T7V",
"name": "Q3 Playbook",
"filename": "q3-playbook.pdf",
"status": "ready",
"error_message": null,
"chunk_count": 42,
"created_at": "2026-10-28T09:20:41.902114",
"updated_at": "2026-10-28T09:20:49.113870"
}
]
}