Private RAG for Enterprises: Architecture and Data-Leakage Controls
Retrieval-Augmented Generation (RAG) has matured from experimental prototypes into the standard architecture for enterprise knowledge retrieval. However, deploying RAG on sensitive business corpora introduces critical security risks: unauthorized lateral data access, prompt injection through untrusted documents, and model training leakage. Here is how AEITCH architects deterministic, zero-leakage enterprise RAG systems.
1. The Multi-Tenant Security Boundary Problem in Naive RAG
In standard tutorials, documents are parsed, chunked, embedded via an external API, and loaded into an open vector store. When an employee asks a question, the vector store fetches the nearest cosine-distance chunks and injects them into the LLM context prompt.
In an enterprise setting, this pattern creates catastrophic data leakage. An engineer asking about corporate infrastructure might inadvertently receive chunks from unreleased financial disclosures or confidential HR investigations if the retrieval layer does not evaluate user permissions before computing vector similarity.
True enterprise RAG must decouple retrieval indexing from query-time permission authorization. Security tokens must be validated at the database query boundary before any chunk reaches the language model prompt buffer.
2. Deterministic ACL Projection with PostgreSQL and pgvector
Rather than maintaining separate vector databases that duplicate your relational security hierarchy, modern enterprise architectures benefit from co-locating embeddings directly inside PostgreSQL using the pgvector extension. This allows single-query, atomic joins between vector similarity searches and row-level security (RLS) policies.
Below is a production SQL schema implementing hybrid vector retrieval with strict role-based document access controls:
-- Enable vector extension
CREATE EXTENSION IF NOT EXISTS vector;
-- Document chunks table with enterprise tenancy and access roles
CREATE TABLE enterprise_chunks (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
document_id UUID NOT NULL,
organization_id UUID NOT NULL,
authorized_roles TEXT[] NOT NULL,
content TEXT NOT NULL,
dense_embedding vector(1536), -- e.g. text-embedding-3-large
tsv_content tsvector GENERATED ALWAYS AS (to_tsvector('english', content)) STORED,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Hybrid query: dense vector + sparse keyword search filtered by user role
CREATE OR REPLACE FUNCTION match_enterprise_chunks (
query_embedding vector(1536),
query_text TEXT,
org_id UUID,
user_roles TEXT[],
match_threshold FLOAT,
match_count INT
)
RETURNS TABLE (
id UUID,
content TEXT,
similarity FLOAT
)
LANGUAGE plpgsql STABLE AS $
BEGIN
RETURN QUERY
SELECT
c.id,
c.content,
(1 - (c.dense_embedding <=> query_embedding)) AS similarity
FROM enterprise_chunks c
WHERE c.organization_id = org_id
AND c.authorized_roles && user_roles
AND (1 - (c.dense_embedding <=> query_embedding)) > match_threshold
ORDER BY c.dense_embedding <=> query_embedding
LIMIT match_count;
END;
$;3. Hybrid Dense-Sparse Retrieval and Reciprocal Rank Fusion (RRF)
Dense vector embeddings excel at capturing conceptual meaning but routinely fail on exact alphanumerics: product model numbers, customer IDs, acronyms, and error codes. Sparse search (BM25) excels at exact string matches but struggles with synonymy.
AEITCH production pipelines employ Reciprocal Rank Fusion (RRF), running dense and sparse queries in parallel and merging their rankings using formula RRF_Score = sum(1 / (k + rank)). This guarantees that exact keyword references and semantic intent both surface reliably in the top 5 chunks.
4. Defense-in-Depth Pipeline Architecture
To achieve comprehensive zero-leakage compliance, the RAG orchestration pipeline must follow four distinct quarantine stages:
1. Ingestion Quarantine: Files undergo malware inspection, PII redaction (via Microsoft Presidio or custom regex tokenizers), and deterministic chunk splitting before vectorization.
2. VPC Tenancy: Embeddings are generated using private VPC endpoints (e.g. AWS PrivateLink or Azure Private Link), ensuring zero document content traverses the public internet.
3. Output Guardrails: Model outputs pass through a deterministic post-processing layer that scans for hallucinated credentials, prompt-leaked instructions, or PII before presentation to the end user.
Technical References & Industry Standards
- PostgreSQL pgvector Documentation — Official documentation for open-source vector similarity search for Postgres.
- NIST Artificial Intelligence Risk Management Framework (AI RMF 1.0) — Federal guidelines on governance, mapping, and measuring AI security and privacy risks.
AI Automation & Agents
Explore how AEITCH engineers implement production architectures for enterprise clients.