← All news and guides
Private AI

Permission-Aware RAG: Enforcing Who Can See What in a Company Knowledge Assistant

How to build a company knowledge assistant that respects permissions: ACL metadata, filtering in pgvector, Qdrant and Azure AI Search, revocation and tests.

Mono Team ·

A long office corridor of identical doors with frosted glass panels, one door slightly ajar, soft daylight at the far end.

Short answer: enforce permissions at retrieval, before any text reaches the model. Store the access rule on every chunk when you index it. At query time, take the user's identity from their signed-in session, never from the prompt, and filter the search with it. For sensitive sources, re-check the top results against the source system before you build the prompt. Do not rely on a system prompt that says "don't reveal confidential files". The model cannot hide what it has been given. Synced permissions also lag, so a person whose access was removed this morning can still match chunks indexed last night unless you check live.

This guide is for engineering leads building an internal knowledge assistant over files, wikis, tickets and chat. It covers the architecture, the filter, vector database choices, revoked access, guardrails, logging and testing. It is engineering guidance, not legal advice. For private AI on your own servers or cloud, see our Own Your AI service.

Why do company knowledge assistants leak data?

A row of tall grey filing cabinets in a quiet office, most drawers shut and one pulled halfway open, soft overhead light, nothing legible, the far end out of focus.

Most leaks come from one shortcut. A connector signs in to SharePoint, Google Drive, Confluence or a ticket system with one service account that can read everything, and copies it all into one index. The assistant searches that index for every user. The source systems had careful permissions. The index has none.

The OWASP Top 10 for LLM Applications (2025) lists this as LLM08, Vector and Embedding Weaknesses. It names unauthorised access and data leakage when access controls on embeddings are inadequate or misaligned, and cross-context leaks between groups of users. Its mitigation is permission-aware vector and embedding stores with strict logical and access partitioning.

Three causes dominate:

  • A flat index. Everyone's question searches everyone's documents, so an intern can retrieve the salary review.
  • Stale permissions. Access was removed at the source, but the index still carries the old rule.
  • Filtering after generation. The model sees restricted text and a later step scrubs the answer. Paraphrases slip through.

What does a permission-aware RAG architecture look like?

Identity must travel with every step. The table shows what a plain RAG demo leaves out.

ComponentJobPermission-aware requirement
ConnectorJob: Reads documents from a source systemPermission-aware requirement: Reads the source's permissions with each document, not just the content
IngestionJob: Splits documents into chunks, embeds them, writes them to the indexPermission-aware requirement: Copies the access rule onto every chunk and the source document ID and version
IndexJob: Stores vectors, text and metadataPermission-aware requirement: Holds an access field that can be filtered, with an index on it
Identity layerJob: Says who is askingPermission-aware requirement: Takes the user and group list from the signed-in session or directory
RetrieverJob: Finds the best chunksPermission-aware requirement: Applies the user's identity as a filter inside the search, not afterwards in application code
Live checkJob: Confirms access at the sourcePermission-aware requirement: Re-checks the top results for sensitive sources before the prompt is built
Generator and guardrailsJob: The LLM, plus filters on inputs, outputs and tool callsPermission-aware requirement: The LLM only receives chunks the user may read. Guardrails are a second layer
Audit logJob: Records what happenedPermission-aware requirement: Stores who asked, which chunks came back and which rule applied

Decide who may see what before the generator runs. You can then test the control by checking chunk IDs, without reading a single answer.

How do you carry permissions from source to chunk?

Decide the access model once and write it into every chunk's metadata. A workable minimum is below.

FieldWhat it holdsNotes
tenant_idWhat it holds: The customer or business unit the chunk belongs toNotes: A hard partition. Never mixed in one query
source_id and source_versionWhat it holds: The document it came from and the version indexedNotes: Lets you delete or refresh every chunk of a document
allowed_principalsWhat it holds: User IDs and group IDs allowed to read itNotes: Store the group ID, not the expanded member list, so group changes take effect without re-indexing
classificationWhat it holds: A label such as public, internal or restrictedNotes: Lets you force a live check for restricted material
acl_synced_atWhat it holds: When the permission was last read from the sourceNotes: Lets you find chunks whose rule is old

Four rules save pain later:

  • Resolve deny rules at ingestion. Source systems combine allow and deny entries. Compute the final allow-list when you index, so the query only asks "is any of my principals in this list?"
  • Store group IDs and expand them at query time. At query time, get the user's groups from the identity provider or directory, and cache the result for a short time. Token group claims can be incomplete for users in many groups, so check your identity provider's documentation before trusting them alone.
  • Fail closed. A chunk with no access rule must be invisible, not public.
  • Treat permission changes as events. A share, unshare, move or delete at the source should update the chunks without waiting for a full crawl.

Where should you apply the permission filter?

There are three places to enforce it. Use the first, and add the third for sensitive material.

ApproachHow it worksProblem
Pre-filter inside the searchHow it works: The vector query carries the filter, so only permitted chunks are candidatesProblem: The right default. Behaviour depends on the engine, as the next sections show
Post-filter in application codeHow it works: Fetch the top K chunks, then drop the ones the user cannot readProblem: Can return too few or zero results, and one coding mistake leaks data
Live check at the sourceHow it works: Ask the source system whether this user can open this document, for the top resultsProblem: Adds latency and load, but handles revocation instantly

Avoid post-filtering. If the top 10 chunks are all restricted and you drop them, the user gets nothing even though permitted answers sit at rank 11. It also rests the safety of the system on one line of application code.

How do you filter by permission in Postgres with pgvector?

Postgres gives you two tools: a normal filter in the query, and row-level security (RLS). RLS is a good fit because the database enforces it even if application code forgets the filter.

  • Turn it on and force it. Run `ALTER TABLE chunks ENABLE ROW LEVEL SECURITY` and `ALTER TABLE chunks FORCE ROW LEVEL SECURITY`. Table owners normally bypass RLS unless you force it. Superusers and roles with `BYPASSRLS` always bypass it, so the application must connect as a role that has neither.
  • Know the default. With RLS enabled and no policy, PostgreSQL applies default-deny: no rows are visible.
  • Write the policy on an array column. Store `allowed_principals` as `text[]`. A policy such as `USING (allowed_principals && string_to_array(current_setting('app.principals', true), ','))` lets a row through only when the user's principals overlap with the row's. If the setting is missing it returns no rows.
  • Set the identity per transaction. Call `set_config('app.principals', $1, true)` at the start of each transaction, with the user's ID and group IDs. Setting it per transaction matters with a connection pool, where one connection serves many users.

Now the vector part. The pgvector README (version 0.8.7) is clear that with approximate indexes, filtering is applied after the index is scanned. If a condition matches 10% of rows, with HNSW and the default `hnsw.ef_search` of 40, only about 4 rows will match on average. A user who can see only a small slice of the corpus can therefore get far fewer results than expected, or none. The README gives three remedies:

  • Iterative index scans (from version 0.8.0), enabled with `SET hnsw.iterative_scan = strict_order` or `relaxed_order`. The index keeps scanning until it finds enough results or reaches a limit.
  • Partial indexes when you filter on only a few distinct values.
  • Partitioning when you filter on many values. For tenant isolation the README recommends list partitioning or separate tables.

Test recall with the policy on and your real permission mix. A secure system that returns empty answers will get switched off.

Which vector database suits a private knowledge assistant?

You may not need a separate vector database at the start. If you already run Postgres, pgvector keeps the index, the access rules and RLS in one place. A dedicated engine is worth a look when you outgrow it. The table summarises what each vendor's documentation says about permissions.

OptionHow it handles permissionsNotes
Postgres with pgvectorHow it handles permissions: Row-level security plus a metadata filter. Enforced by the databaseNotes: Post-index filtering needs iterative scans, partial indexes or partitioning. Self-hostable
QdrantHow it handles permissions: Payload filters on a field in one shared collection. Mark the tenant field with `is_tenant`Notes: Its guide says a separate collection per tenant is "rarely the most efficient approach". Use separate collections only for a limited number of tenants needing strict isolation. Self-hostable
Azure AI Search with Foundry IQHow it handles permissions: Security string filters, ACL and RBAC scopes, SharePoint ACLs, Purview labels and OneLakeNotes: Microsoft-hosted, so check the region and your data residency needs. Sources vary between generally available and preview, as described below

If you sell a SaaS product and enterprise customers want their AI kept apart from other tenants, our private AI for SaaS page covers the isolation levels and hosting choices. Inside one tenant, the filters in this guide still apply.

Qdrant's multi-tenancy guide describes three patterns: payload filtering for many small tenants, user-defined sharding for fewer large ones, and tiered multitenancy that combines both. The tenant flag on a keyword index needs version 1.11.0 or later.

For Azure AI Search, Microsoft's document-level access overview (dated 9 November 2026) says the user's token goes in the `x-ms-query-source-authorization` header, and that ACLs must be projected onto every indexed chunk. SharePoint ACLs, ADLS Gen2 ACL and RBAC, Blob RBAC and push ACL are generally available in REST version 2026-10-01. Purview labels and OneLake are in preview.

Which embedding model should you run privately?

A wall-mounted wooden board with rows of brass keys hanging from hooks, warm side light, shallow depth of field, no tags or numbers legible.

Embeddings are made from your documents, so treat them as the same class of data as the source, with the same access rule, retention and erasure path. Our DPDP compliant AI architecture guide covers deleting a person from indexes and caches.

When you choose a model, check four things:

  • Licence. Read the licence on each model card. BGE-M3 from BAAI, for example, shows an MIT licence on its model card. Do not assume the same of every embedding model.
  • Languages. Test on your staff's languages. BGE-M3's model card describes more than 100 working languages and inputs up to 8,192 tokens.
  • Where it runs. Run it on your own servers or India-hosted cloud, not through a third-party embedding API.
  • Version control. Changing the model means re-embedding the whole index, so record the model name and version on every chunk.

How do you handle revoked access and stale permissions?

Synced permissions always lag. Azure's own documentation says its permission refresh does not provide immediate revocation, and that ADLS ACLs refresh about daily. Every index that copies ACLs has this gap. What matters is how big the gap is and whether you can close it for the documents that count.

TechniqueWhat it fixesCost
Event-driven ACL updatesWhat it fixes: Shrinks the gap to minutes where the source sends change eventsCost: Needs webhooks or change feeds per source
Short cache on group membershipWhat it fixes: A removed member loses access quicklyCost: More directory calls
Live check on the top resultsWhat it fixes: Closes the gap fully for the documents it coversCost: Latency and API load on the source system
Delete on source delete, plus a reconciliation crawlWhat it fixes: Removed documents stop appearing, and missed events are caughtCost: Needs delete events, compute and API quota

A sensible rule: always live-check restricted material, such as HR, legal, board and customer-contract folders, and accept the sync lag for general wikis. Send the user's identity and each candidate document ID to the source system, drop anything it refuses, and do this before the prompt is built. If the source is down, fail closed.

What can guardrails add, and what can they not do?

Guardrails are filters on inputs, outputs and tool calls. They are useful, and the tools below can run on your own infrastructure. They are a second layer, not an access control.

ToolWhat it isLicence
NVIDIA NeMo GuardrailsWhat it is: A library for programmable controls on LLM and agent apps. Its README describes input and output checks, and for RAG, detecting or masking sensitive data in retrieved content and checking that answers are grounded in evidenceLicence: Apache 2.0
Microsoft PresidioWhat it is: Detects and anonymises personal data in textLicence: MIT

Useful jobs for guardrails in a knowledge assistant:

  • Mask personal data in outputs for roles that should not see it. See PII redaction for LLMs.
  • Treat retrieved text as untrusted. A document can contain instructions aimed at the model. Never let retrieved text decide which tools run or whose permissions apply.
  • Check tool calls. If the assistant can send e-mail or write to systems, apply the user's permissions to the action too.
  • Block obvious jailbreak patterns. This reduces noise but will not stop a determined user.

The test: with every guardrail off, could a user still retrieve a chunk they should not? If yes, the access control is missing. Fix that first.

What should you log in a permission-aware assistant?

Logs let you answer "who saw this document, and why?" after an incident. Record for each query:

  • the user ID and the group list used, with the time
  • the source document IDs and versions of every chunk retrieved, and any dropped by the live check
  • the access rule that allowed each chunk, such as the principal that matched
  • the model name and version, the prompt template version and any guardrail result

Be careful with full prompts and answers, which can hold the personal data you are protecting. Store them only if needed, restrict access and set a retention period. From 13 May 2027 the DPDP Rules require processing logs to be kept for at least one year (Rules 6(1)(e) and 8(3)), so decide what is kept and who sees it. Our guide to DPDP one-year log retention shows how to do that without hoarding prompts, and LLM observability setup covers the tooling.

How do you test that permissions actually hold?

Test permissions like any security control, on every change to connectors, index schema or retrieval code.

TestHowPass condition
Canary documentHow: Index a document with a unique phrase that only one test user may readPass condition: Other test users never see the phrase in answers or citations
Two-user and cross-tenant testHow: Ask the same question as users with different rights and in different tenantsPass condition: Each gets only chunks from their own allowed set
Group removalHow: Remove a test user from a group at the sourcePass condition: Access ends within your stated lag, and immediately for live-checked sources
Prompt attackHow: Ask the assistant to ignore its rules and list restricted filesPass condition: Nothing restricted appears, since it was never retrieved

Keep canary documents in place and run the checks on a schedule, since a pass now does not cover a connector change later.

What should you do first?

List the sources and who may read each one now. Choose the chunk metadata and a default of no access. Make the connectors read permissions along with content. Filter inside the search and test recall for narrow-access users. Add live checks for restricted sources, turn on audit logs and automate the tests above. If you want a private assistant on your own servers or India-hosted cloud with permissions built in, that is part of our Own Your AI work. Legal questions on staff data, customer data and DPDP go to your counsel.

Sources: PostgreSQL documentation, Row Security Policies (postgresql.org/docs/current/ddl-rowsecurity.html). pgvector README, version 0.8.7 (github.com/pgvector/pgvector), Filtering and Iterative Index Scans. Qdrant documentation, Multitenancy guide (qdrant.tech/documentation/guides/multiple-partitions/). Microsoft Learn, Document-level access control in Azure AI Search, dated 9 November 2026. OWASP Top 10 for LLM Applications 2025, LLM08 Vector and Embedding Weaknesses (genai.owasp.org). NVIDIA NeMo Guardrails README (github.com/NVIDIA-NeMo/Guardrails). Microsoft Presidio repository licence (github.com/microsoft/presidio). BAAI BGE-M3 model card (huggingface.co/BAAI/bge-m3). Digital Personal Data Protection Rules, 2025, Rules 6(1)(e) and 8(3). Last reviewed 20 November 2026.

FAQ

What is permission-aware RAG?

It is retrieval-augmented generation that applies each user's access rights when it searches. Every indexed chunk carries the access rule of its source document, and the search is filtered by the signed-in user's identity and groups. The model only receives chunks that user may read, so it cannot reveal anything restricted.

Can I stop a chatbot revealing confidential files with a system prompt?

No. If a restricted chunk is placed in the prompt, the model can quote, summarise or paraphrase it, and prompt tricks can pull it out. The reliable method is to keep restricted chunks out of the prompt by filtering during retrieval. Use prompts and guardrails as extra layers, not as the access control.

Should I filter results before or after the vector search?

Filter inside the vector search wherever the engine allows it. Filtering afterwards can return too few results or none, and it puts security in application code. With pgvector, approximate indexes apply filters after the scan, so enable iterative scans, use partial indexes or partition the table, and test recall for users with narrow access.

How quickly does access removal take effect in a RAG index?

It depends on how you sync permissions. Microsoft's Azure AI Search documentation says its permission refresh does not give immediate revocation, and that ADLS ACLs refresh about daily. For instant revocation, re-check the top results against the source system at query time, at least for restricted folders. Use change events and short caches for the rest.

Does a private knowledge assistant need a separate vector database?

Not necessarily. Postgres with pgvector can hold the vectors, the text and the access rules, and row-level security enforces them in the database. Consider a dedicated engine such as Qdrant if you outgrow Postgres. Whichever you pick, use one permission-filtered index with a tenant field rather than a collection per user.

Build a private assistant that respects who can see what.