Supported formats
text/plain, text/markdown and application/pdf. PDFs are extracted in read-only mode with Apache PDFBox. Adding a format means implementing a TextExtractor adapter and enum value.
How an uploaded document becomes useful context in a conversation. A deliberately narrow input scope, an asynchronous state machine, a four-stage ingestion pipeline and fail-open retrieval that keeps chat available if search fails.
The uploader accepts a fixed set of formats, enforces hard per-agent quotas and rejects duplicates. RAG is per agent: each agent has a private corpus, with no shared documents or vectors.
text/plain, text/markdown and application/pdf. PDFs are extracted in read-only mode with Apache PDFBox. Adding a format means implementing a TextExtractor adapter and enum value.
5 MiB per file, 16 documents per agent and 25 MiB total. Known bounds mean predictable embedding costs, fast vector search and a clear disk ceiling for operators.
The (agentId, sha256) key prevents duplicates. Uploading the same file returns the existing ID, with details in the error response so the UI can navigate to it.
A universal extractor would create a disproportionate attack surface: malicious Office documents, SVG with embedded JavaScript or HTML with remote CSS. The selected formats have narrowly scoped extractors — an intentional trade-off between coverage and security.
Ingestion is asynchronous. A document moves through PENDING → INDEXING → READY, or reaches FAILED after a hard failure. A periodic scheduler claims documents, manages retries and recovers interrupted work.
INDEXING stage is where processing can temporarily fail.A document stuck in INDEXING with an expired claimed_at value is claimed again on the next scheduler tick. The pipeline is idempotent: each run removes the document's vectors before reinserting them. A node failure between stages cannot corrupt the corpus.
A 429 or 5xx from the embedding provider returns the document to PENDING for a later retry. Parsing errors, out-of-memory conditions and invalid content move to FAILED with a sanitised error message exposed through the API.
Each document follows a linear chain with no conditional branches. Every stage is a port that can be replaced independently.
A TextExtractorRouter dispatches by MIME type: UTF-8 for text and Markdown, PDFBox for PDFs. Output: a string.
Recursive chunker, targeting about 1,000 characters with 200 characters of overlap. It prefers paragraph, sentence and then space boundaries, avoiding cuts in the middle of a word.
Requests are sent to the provider in batches. One request for 50 chunks costs about five times less than 50 individual requests. Transient errors return the document to PENDING.
Vectors and metadata (documentId, index and preview) are inserted into the vector store. An abstraction port allows switching to PGVector or Pinecone without rewriting ingestion.
The vector store is not persisted separately. On startup, a bootstrap process iterates over all READY documents and rebuilds the store from their database chunks. There is one source of truth and no consistency problem between systems to synchronise.
Each conversation turn follows a short cycle: embed the query, find the agent's top-k chunks, assemble a size-bounded context block and prepend it to the LLM request. Deletion returns quickly through the API; disk cleanup is handled by a scheduler.
If embedding fails or the vector store does not respond, the chat turn continues without context. The LLM still replies, without grounding. Fail-closed would let a temporary embedding-provider issue bring down all chat — worse than a less-supported answer.
The DELETE call returns 204 within milliseconds: the database row and chunks are removed, vectors are evicted and an event is emitted. A separate scheduler consumes the event and deletes the file. Temporary I/O issues are not exposed to the user.
Retrieved chunks are added to the start of the user request rather than exposed as structured citations. Explicit citations could be added later without changing the retrieval mechanism; the prompt already contains the source data.