L1Desk — AI L1-Support RAG
Goal
A production multi-tenant RAG app that answers customers' technical (L1) support questions strictly from tenant-uploaded documentation, with source citations and human handoff when confidence is low — so companies can offload routine support while enforcing the product policy that no answer is preferable to a wrong one.
The Problem
L1 technical support automatically provides answers to repetitive, documentation-driven queries, which is exactly what makes it a good fit for an LLM agent — and exactly what makes a naive implementation dangerous. The core difficulties:
- Confident wrongness. A support customer will act on an answer. A hallucinated, confident answer is worse than no answer at all, so abstention must be a first-class, machine-checkable behavior rather than a prompt tone.
- Exact tokens dominate. Support queries are full of error codes, product names, version strings, and function names — tokens where dense vector search is weak and keyword search is strong.
- Strict multi-tenant isolation. Every retrieval, citation, and deletion must be scoped per tenant; one tenant's data must never leak into another tenant's answers.
Methodology
L1Desk is an npm-workspaces monorepo of four decoupled services, deployed across two sites over a private Tailscale network. The interesting decisions are mostly at the seams.
1. Architecture and Deployment
- Four services:
- Next.js 15 web tier (business site, tenant dashboards, embeddable widget)
- FastAPI mail service (the only mail sender, behind a provider facade over four vendors)
- FastAPI RAG engine (query-time retrieval, escalation gates, generation)
- Celery ingestion worker (parsing, chunking, embedding)
- Two types of servers: a CPU-light server optimized for transactions, and CPU-heavy servers optimized for heavy data ingestion, embeddings, cosine similarity computations.
- The RAG line (on CPU-heavy servers) keeps its own vector database (pgvector chunks plus conversation state), separate from the app database.
- Ingestion reads by key, not bytes: the web tier stores uploaded bytes in the object store and dispatches a key; the worker parses, classifies against a content-addressed document registry (hash of the normalized parsed text), chunks, embeds, and writes in one transaction — identical content under two names collides instead of double-indexing, and modified documents are replaced atomically with no mixed old-and-new chunks.
2. Hybrid Retrieval in a Single Query
- Documents are parsed into structure-aware chunks — one chunk per section, with the document title and section heading carried on every chunk so both the embedder and the full-text index get context.
- Query-time retrieval runs dense HNSW nearest-neighbor top-20 plus Postgres full-text search top-20, RRF-fused in a single SQL query — no Elasticsearch, no separate vector database; the lexical leg and the vector column live in the same table.
- Before answering, the 20 candidates go through a second pass: a small cross-encoder reranker model re-orders them by true relevance to the question and only the five best go on to the answer.
- Every retrieval query carries the tenant id throughout — the dense leg, the lexical leg, and the rerank — so isolation is a property of the query shape, not a convention.
3. Escalation Gates — Avoid Hallucinations in Low-Confidence Answers
- Gate 0 (pre-retrieval): handles simple greetings and non-technical questions.
- Gate 1 (pre-LLM): when retrieval has low confidence, escalate, avoiding hallucinating answers.
- Gate 2 (post-LLM): catches "confidently wrong" answers produced by the LLM.
- When any gate fires, the question is escalated for human intervention. The app handles most regular technical queries; it does not hallucinate and does not intend to replace humans for handling special cases.
4. Evaluation as the Arbiter
- A golden set uses the MRR and Recall-at-K metrics. It provides no answer for queries returning low-confidence results, i.e., answers not supported by documents.
- The golden set is used to evaluate every retrieval and model change before release. This includes the embedding model (nomic-embed-text-v1.5, 768-dim), the RRF fusion depth and weights, the reranker, and the gate thresholds.
5. Customer-Facing Layer
- The app provides a lightweight widget (<15 KB) for tenants to embed in their company's website. From there, technical queries from the tenant's customers are answered by the RAG app based on the tenant's documents.
- Every customer query is audit-logged and visible in the tenant dashboard.
- The tenant dashboard also has Stripe billing, which I implemented using Stripe webhooks.
Results
Latency
The fused hybrid retrieval query runs in tens of milliseconds, and the retrieval-plus-rerank stage runs in a few hundred milliseconds at the median — roughly 10x faster than the initial prototype, which refit a TF-IDF vectorizer over the whole tenant corpus on every query (about 3 s per query on a large tenant). Total answer latency is dominated by LLM decode, which is why answers are enforced to be terse and streamed to the user.
Reliability
Abstention is measured, not assumed: no-answer probes are scored as a first-class metric, and their top-k scores are the calibration anchors for the pre-LLM gate. The gates together enforce the product contract — a question either gets a cited answer grounded in the tenant's own docs, or it gets a human.
Production Operations
L1Desk runs in production across web and ML server tiers over a private network, behind Cloudflare. CI runs unit and end-to-end browser tests on every push, and the two-site deployment means the lab never exposes a public inbound port.
Lessons
- Vectors are derived data — chunk text in Postgres is the source of truth and the worst case is a re-embed. That is why a managed vector database was never stood up.
- If you can't name the code path that writes a table, the table shouldn't exist. The app-database conversation models were deleted because no writer ever existed — the tables sat silently empty, a second source of truth that was always stale.