Enterprise AI Context
An assistant that answers questions about a company's email, documents and business data, cites where every fact comes from, and says so when it can't find the answer.
- CSR Online
- Designed, built and run by Adrián Vázquez, on his own
In production · development paused
Since March 2026
~5,560 tests
- 43% → 86% emails with their source in the context
- 21% → 76% documents with their source in the top ten
- 0.63 → 0.71 MRR, with no re-embedding
- ~23× faster OCR per page
Measured on one installation's corpus; the figures compare before and after each fix.
- Python
- FastAPI
- Qdrant
- PostgreSQL
- bge-m3 + BM25
- Docling
- Tesseract
- spaCy
- sqlglot
- Claude (API)
- Docker
The situation
A company's knowledge lives in three places that don't talk to each other. Email, including years of archived mailboxes in PST files, buries agreements, complaints and commitments in thousands of threads. Shared folders have no search that understands a question. And business data sits in the ERP or in master spreadsheets that nobody cross-checks against the emails.
A typical question from management crosses all three (“what did we agree with supplier X on delivery terms, how much have we bought from them this year, and have they complained lately?”), and answering it meant opening three tools and asking whoever remembered. When that person leaves, the knowledge leaves with them.
The task
An assistant that searches the company's knowledge and writes the answer only from what it found, citing every source, in Spanish, Catalan or English. Five rules weren't negotiable: read-only on every source; an answer without a source isn't an answer; fail open on auxiliary steps but closed on security; quality measured, not assumed; and fixes that work for any company, never tailored to one.
Ingestion couldn't take the chat down, had to resume where it stopped, and could never duplicate or silently lose anything, with mailboxes tens of gigabytes in size.
How it works
Ingestion
Sources, read-only: mailboxes (PST archives, read with libpff in a separate process, so a message that crashes the library can't take down the worker) and shared folders.
Change detection: size and date first, SHA-256 only if they changed; re-importing a PST duplicates nothing.
Extractor cascade (Docling, PyMuPDF, pdfplumber, pypdf and OCR with Tesseract), with Docling in a process that can be killed.
Cleaning, threads rebuilt from the headers and near-duplicates found with MinHash; parent-child chunks with a deterministic context prefix.
Dense (bge-m3) and sparse (BM25 with IDF) vectors → Qdrant, with deterministic ids and per-file checkpoints in PostgreSQL.
Query
- Claude (API)
Guardrail: rules first, then a light classifier; an out-of-scope question never reaches the model.
- Claude (API)
Understanding the question: follow-ups are rewritten as standalone questions, and date and sender filters come from rules, not from a model.
- Qdrant
Hybrid search, fused with RRF inside Qdrant.
- Claude (API)
LLM reranking and CRAG.
- PostgreSQL
Context composition: exact counts from PostgreSQL and business tables first, then the passages.
- FastAPI
Streamed answer from the model chosen in the chat.
- Python
Citations assigned by code, not by the model.
Two services from one image, the chat and the ingestion worker, kept apart so a huge import can't take the chat down: only the worker mounts the sources, read-only, and the exposed container sees neither the file system nor the mail.
Counts and totals never come from passages: email counts are fixed, parameterised SQL in PostgreSQL, and business tables (spreadsheets loaded nightly into PostgreSQL) are queried with a single SELECT checked by sqlglot, under a read-only role, in a read-only transaction.
How and why
D1 Deterministic ingestion, no LLM.
Ingestion depends on no model: an extractor cascade, threads rebuilt from the headers, MinHash deduplication and an idempotent registry in PostgreSQL. The same input always produces the same index, re-importing never duplicates anything, and an interrupted import resumes where it stopped.
Rejected: an LLM in ingestion: it tied ingestion to an external service's availability, wasn't reproducible, and scored a lower hit@10 than the deterministic context.
D2 Hybrid search with RRF.
Dense vectors understand synonyms and languages; sparse ones get codes, figures and uncommon names right. The two lists are fused with RRF, because a cosine of 0.8 and a BM25 score of 14.3 aren't comparable. fastembed computes both dense and sparse vectors inside the app, since Ollama doesn't produce sparse ones.
Rejected: HyDE: on 298 questions from one company it lost 7 to 10 points in the top ten and added a median 4.0 s per question.
D3 LLM reranking.
After search, the auxiliary model reorders the candidates before the cut that reaches the model writing the answer.
Rejected: a local ONNX reranker, which ranked worse in a live evaluation.
The cost: one more call to the auxiliary model per question (sometimes two), and its latency.
D4 The prompt asks, the code checks.
Citation numbers are placed by deterministic code that matches subject, file, sender and date to each sentence. The sources shown come from the same cut the model receives, so every citation points to something the model actually had in front of it.
Rejected: an LLM faithfulness critic on every answer: it delays the answer and breaks streaming.
The cost: a module of about 1,400 lines of fine-grained rules.
D5 Internal models on Claude.
The internal steps (rewriting the question, reranking, deciding what to search) run on Claude, and their behaviour is measured with it: it's more predictable with structured output (lists, labels, JSON) and keeps its reasoning out of the answer. The model that writes the answer is chosen by each person in the chat, from those the installation offers.
Still to do: letting the service run entirely on local AI models, with no Claude.
D6 A home-grown orchestrator, no framework.
A turn is a chain of 19 phases over an explicit state, each emitting events streamed over SSE. A test that reads every import stops new crossings between the code's layers.
Rejected: LangGraph and CrewAI, which added heavy dependencies and took away control in an on-premise deployment.
The cost: the orchestrator is my code, and maintaining it is on me.
D7 One installation per client.
One client's data never shares a database with another client's. And indexed data is never changed in place: a snapshot first; then the new version in a separate collection, validated on a sample, and the old one deleted only at the end.