Grounding pipeline

How SLAtech avoids hallucination

12-stage RAG-based grounding pipeline + structured citation system. Every response is grounded in tenant content - not fine-tuned. Visitors see citation snippets per source. Confidence-scored. Audit-trail logged. Continuous eval feedback. Pairs with the architecture overview, answer-quality page and AI ethics statement.

1. Tenant content ingestion

Documents (PDF, DOCX, scraped HTML, FAQ pairs, manually-authored articles) chunked into 200-500 token segments with 50-token overlap. Each chunk gets metadata: ClientId (tenant partition), sourceUrl, chunkIndex, lastUpdated.

Technical: Chunking algorithm respects document structure (paragraph boundaries) when possible. Overlap prevents context-loss across chunk boundaries.

2. Embedding generation

Our embedding model (1536 dimensions) converts each chunk into a semantic vector. Embeddings are stored in our vector store with the chunk's metadata.

Technical: Same embedding model used for queries - ensures cosine-similarity comparisons are semantically valid.

3. Query embedding

When a visitor submits a message, the bot embeds the query using the same embedding model. Query embedding is filtered against ClientId before retrieval - cross-tenant contamination is structurally impossible.

Technical: Repository pattern enforces ClientId filter at compile time via static analyzer rule (SLATECH001).

4. Top-K retrieval

The vector store returns the top-K (default 10) chunks with highest cosine similarity to the query. Default ScoreThreshold = 0.5 filters out low-relevance chunks.

Technical: TopK clamped to [1, 20] per per-tenant configuration. Below-threshold queries route to a "no relevant content" fallback rather than hallucinating.

5. Context assembly

Retrieved chunks + system prompt + conversation history pass to the LLM. System prompt explicitly instructs the LLM: "Answer only from the provided context. If the answer is not in the context, say so."

Technical: Token budget enforced (default 4000 tokens of context); if budget exceeds, low-score chunks are dropped first.

6. LLM generation

A leading large language model (default) or a tenant-configured LLM generates the response, grounded in the retrieved context. Temperature default 0.3 for grounded customer-facing answers.

Technical: Per-tenant LLM provider abstraction allows swapping language-model providers without customer-side migration.

7. Citation extraction

The response includes a structured citation list: { sourceUrl, snippet, score } per retrieved chunk. Snippet is the actual quoted text - not just the URL.

Technical: BuildSnippet helper in QueryRequest record extracts the relevant 200-character span from the chunk.

8. SSE streaming with sources-early event

Server-Sent Events transport. First event is sources-early - emits citation metadata before LLM streaming starts. Widget renders "according to" hover-card while the answer is still streaming.

Technical: Cuts perceived latency by ~70% vs synchronous response. Enables AI scrapers to extract grounded quotes from the response.

9. LLM-as-Judge confidence scoring

Answers built on retrieved content are scored by a secondary call against three axes: factuality, hallucination and confidence. Scores surface in the admin Inbox.

Technical: Confidence score below 0.5 typically triggers a human-handoff fallback rather than a guessed answer.

10. Human-handoff fallback

When confidence is low OR query is identified as high-risk (clinical advice, legal position, regulatory question) - bot routes to a "human will follow up" pattern. The visitor receives an acknowledgement + a follow-up channel.

Technical: Per-vertical instructions tuned for each industry. Med is configured to refer diagnosis-adjacent questions to a clinician rather than answer them; Legal refers substantive legal questions to an attorney. A separate compliance check reads answers after they are sent and flags medical-advice and diagnosis claims in the admin Inbox, so the two work together: instruction first, detection behind it.

11. Per-response audit trail

Every response logged with full context: input query, retrieved chunks with scores, system prompt, LLM model used, generated response, citation snippets, confidence scores.

Technical: Audit logs retained 13 months. Per-tenant audit log exportable on Enterprise tier.

12. Continuous eval feedback

Factuality and unsupported-statement flags are recorded per answer and can be tracked over time for a site. There is no nightly benchmark run: the sealed per-vertical test set described here never existed.

Technical: How answer quality is measured, and what a publishable comparison would need, is at /en/eval/.

Verify the grounding on your own tenant

Answers built on retrieved content are scored for factuality, and the results are visible to you for your own site. There is no published benchmark yet - see /en/eval/.