Skip to content

Architecture pattern

Retrieval-augmented generation with governed retrieval

Ground model answers in your own documents without leaking them, by enforcing each user's permissions at retrieval time and sending prompts through a governed AI gateway.

Retrieval-augmented generation with governed retrieval. Architecture diagram, with the numbered flow listed below it.
Retrieval-augmented generation with governed retrievalA user asks a question in a RAG application. Retrieval goes through an API that only returns documents the user is allowed to see, and the prompt goes to the model through an AI gateway that applies guardrails and logging. Documents are indexed with their permissions attached.UsersApplicationGoverned accessData and modelsUserSigned in, with rolesRAG applicationOrchestrates the stepsRetrieval APIEnforces document accessAI gatewayGuardrails, redaction, logsVector indexChunks plus access labelsIngestion pipelineClassify, chunk, embedLanguage modelHosted or self-hosted123456
  • Caller
  • Gateway
  • Component you run
  • Outside your boundary
  • Request
  • Event or background

How it flows

  1. User to RAG applicationAsks a question. The application keeps the user’s identity with the request.
  2. RAG application to Retrieval APIRetrieves context on behalf of that user, not with a shared superuser account.
  3. Retrieval API to Vector indexSearches only chunks the user is allowed to read, filtered at query time.
  4. Ingestion pipeline to Vector index (asynchronous)Indexes documents with their source permissions and sensitivity labels.
  5. RAG application to AI gatewaySends the prompt and retrieved context through the AI gateway.
  6. AI gateway to Language modelApplies prompt checks and redaction, then calls the model and logs the exchange.

The problem

Retrieval-augmented generation (RAG) gives a model relevant passages from your own documents before it answers. Early prototypes often index everything with one service account and search it on behalf of anyone. The model then happily summarises a board paper, a salary file or another customer's contract for a user who should never have seen it.

Retrieved text is also untrusted input. A document can contain instructions that try to steer the model, which is a form of indirect prompt injection.

When to use it

  • Assistants that answer from internal knowledge: policies, product documentation, support history, contracts.
  • Document access varies by role, team, region or customer.
  • You need to show where an answer came from and prove who saw what.
  • Prompts and retrieved content may contain personal or confidential data.

When not to

  • Public, uniformly accessible content. Plain RAG without per-user filtering is fine, though the gateway controls still help.
  • Questions that need precise, current figures from a system of record. Call the system's API as a tool instead of searching stale document chunks.
  • When the source permissions themselves are unreliable. Fix access control at the source first; RAG inherits its mistakes.

Key components

  • Ingestion pipeline. Classifies, chunks and embeds documents, carrying source permissions and sensitivity labels onto every chunk.
  • Vector index. Stores embeddings with those labels as filterable metadata.
  • Retrieval API. The only way to query the index. It receives the user's identity and applies permission filters at query time.
  • AI gateway. Applies prompt checks, redaction and logging, and routes to an approved model.
  • Citations and audit. Answers reference their source documents, and each retrieval is logged against the user.

Trade-offs

  • Permission sync. Access changes at the source must reach the index quickly, or revoked users keep seeing content. Plan for re-indexing and deletion.
  • Recall versus safety. Strict filtering can hide useful context. That is usually the right failure, but users will notice.
  • Latency and cost. Retrieval, guardrails and larger prompts all add time and tokens. Caching helps, but only when cache entries are scoped per permission set.
  • Injection is reduced, not removed. Filtering and guardrails lower the risk from malicious documents; tools and actions triggered by the model still need their own limits.

Explore further

Weighing this up for your platform?