Skip to main content
Pawan Niroula
RAG & LLMs9 min read

Designing Private RAG Systems Where Confidentiality Is Non-Negotiable

Architectural decisions for retrieval-augmented generation inside regulated environments: document boundaries, hybrid indexing, local inference, and verifiable citations.

On this page (6)

Why generic RAG demos fail in real organizations

Most tutorials treat retrieval-augmented generation as a three-step script: split a folder of PDFs, embed them with a hosted API, and stuff the top five chunks into a prompt. That works well enough for public documentation. Inside a regulated organization—such as banking or financial operations—that naive pipeline breaks down on day one.

The friction is rarely the language model alone. It comes from four operational realities:

  1. Data residency and privacy boundaries. Internal policies, circulars, and operational manuals cannot be forwarded casually to external cloud endpoints.
  2. Document structure loss. Naive fixed-character splitting tears apart numbered policy clauses, eligibility tables, and footnotes, leaving the retriever with partial rules that contradict each other.
  3. Version drift. When a revised circular supersedes an older instruction, semantic similarity alone will happily retrieve the outdated paragraph because it uses the exact same phrasing.
  4. Trust and auditability. Staff will not rely on an answer unless they can inspect the exact source title, section, and page number in seconds.

Treating retrieval as a systems problem

A dependable internal knowledge assistant looks far more like a disciplined search and information-governance system than a chatbot wrapper.

1. Structure-aware ingestion

Before computing a single embedding, documents should be normalized with metadata preserved: document identifier, effective date, department scope, approval status, and page boundaries. Tables should be converted into structured markdown or row-level summaries so numerical thresholds stay attached to their column headers.

python
from dataclasses import dataclass
@dataclass
class PolicyChunk:
doc_id: str
title: str
page_number: int
section_heading: str
effective_date: str
access_scope: str
text: str

When every chunk carries explicit metadata, retrieval can enforce pre-filters—excluding superseded documents and enforcing department permissions before vector scoring happens.

Dense embeddings excel at conceptual paraphrase, yet they frequently miss exact reference codes, form numbers, and regulatory clause IDs. Pairing dense vector search in Qdrant with lexical keyword matching (BM25 or sparse vectors) consistently outperforms either method alone on operational queries.

python
def fuse_rankings(dense_hits: list[str], lexical_hits: list[str], k: int = 60) -> list[tuple[str, float]]:
"""Reciprocal Rank Fusion (RRF) combining semantic and lexical candidates."""
scores: dict[str, float] = {}
for rank, doc_id in enumerate(dense_hits, start=1):
scores[doc_id] = scores.get(doc_id, 0.0) + 1.0 / (k + rank)
for rank, doc_id in enumerate(lexical_hits, start=1):
scores[doc_id] = scores.get(doc_id, 0.0) + 1.0 / (k + rank)
return sorted(scores.items(), key=lambda item: item[1], reverse=True)

3. Local inference and strict grounding

Running open-weight models locally through Ollama or vLLM keeps inference inside the network perimeter. Smaller 7B–14B instruction-tuned models perform remarkably well on grounded QA when you stop asking them to memorize facts and instead constrain them to synthesize only from retrieved evidence.

A useful internal assistant should refuse confidently when the retrieved excerpts do not contain the answer. A polite "not found in the indexed documents" builds more long-term trust than a plausible-sounding guess.

Evaluating before shipping

Rather than judging quality by a handful of impressive prompts, assemble a small, realistic evaluation set of everyday staff questions—including tricky edge cases, deprecated policies, and unanswerable questions. Measure three things separately:

  • Retrieval recall: Did the right page and clause make it into the top chunks?
  • Groundedness: Is every factual claim in the response directly supported by those chunks?
  • Citation accuracy: Do the page references point to the exact supporting text?

When you separate retrieval quality from generation quality, debugging becomes systematic instead of guesswork.

Written by

Have a thought on this piece? Send a note