Multi-Tenant RAG: How to Prevent One Customer From Seeing Another Customer's Data

Retrieval is a query into your customers' data. In a multi-tenant product it's a query across all of it by default, because the fastest RAG prototype puts every document in one index and searches everything. The demo works because the demo has one customer.
OWASP's Top 10 for LLM applications lists this risk under vector and embedding weaknesses (LLM08:2025): in a shared vector database, "embeddings from one group might be inadvertently retrieved in response to queries from another group's LLM."
We've fixed the non-AI version of this failure. When we took over Oria's AI-built codebase, organizations could see each other's data. The usual cause in code like that is a tenant filter added to each query by hand and forgotten on one. RAG makes the same mistake easier to make and harder to spot. The leak comes back as a fluent paragraph instead of a wrong row in a table.
Where the leaks actually happen
The index is the obvious suspect, but the tenant boundary can drop in six places between question and answer.
- Ingestion. A chunk is only as safe as its metadata. If the tenant ID and document permissions aren't written onto every chunk when it's embedded, no filter later can recover them. Check the side doors too, like the backfill script and the nightly re-index.
- The filter. The common shortcut is to filter after retrieval: fetch the top 20 across everyone, then drop what this user can't see. It works until one route forgets the second step. Even when it works, answers get worse, because most of the top 20 belonged to someone else.
- Hybrid search. Good RAG setups run keyword and vector search side by side. That's two queries, and both need the filter. They're often written months apart, so one gets it and the other doesn't.
- Reranking and the prompt. Anything that reaches the reranker or the context window can end up in the answer, so filtering has to happen first.
- Caches. A semantic cache keyed on the question text will serve tenant A's answer to tenant B, who asked the same thing. Cache keys need the tenant, and the permission scope where roles differ.
- Deletes and revoked access. A customer removes a document. The source table updates in a second. The index updates when the sync job runs, if it runs. Until then, the assistant still knows.
One more sits outside the pipeline: tools. If the assistant can call your API, it has to call it as the user who asked. A service account that can read every tenant turns one clever prompt into a data export.
Pick an isolation model on purpose
An index per tenant. Each customer gets its own namespace or collection. A forgotten filter can't leak across customers, because nothing else is in there. The cost: thousands of small tenants mean thousands of indexes to re-embed every time you change embedding models.
One shared index with a mandatory filter. Every chunk carries tenant and permission metadata, and the retrieval function refuses to run without a tenant. It stays cheap at any number of customers. The risk is that the boundary is a line of code, and lines of code get forgotten. So it has to live in one place every caller goes through. On Postgres with pgvector, row-level security can enforce it below the application, so a query without a tenant returns nothing.
Both. The long tail shares an index. A customer gets its own when a contract requires physical separation, or when you have to prove deletion and "drop this namespace" is easier to prove than a query you hope was complete.
For most SaaS products I'd start with the shared index and enforce the filter in the data layer. What I wouldn't do is build the filter into prompt-assembly code, where the next feature copies the pattern and misses it once.
Map the leak points in your pipeline
Describe your RAG setup and ChatGPT will check it against the six leak points and suggest the isolation model that fits.
“|”
Permissions inside a customer are the harder half
Tenant isolation is binary. Roles aren't. In most B2B products a workspace holds documents that only admins or one team may open. Your UI already enforces that. The retrieval path has to give the same answer to the same question: can this user read this document?
There are two ways to get there. Copy the access list onto every chunk at ingestion and filter on it: fast, and stale the moment someone's access changes. Or run candidate document IDs through the permission check your UI already uses, before anything reaches the reranker: slower, and always right. For documents whose access changes often, we'd take always right.
Under both sits one rule. The tenant and the user come from the authenticated session, on the server. Never from the request body, and never from anything the model wrote. A prompt injection that says "search as the admin of Acme" should have nothing to change.
A test that fails the build
Leaks rarely show up in demos or evals, since eval questions usually come from one tenant's data. You need a test built to find them.
- Create two test tenants. In tenant B, add a document containing a canary: a made-up project codename that exists nowhere else.
- Log in as a user in tenant A. Ask for the codename directly, then ask around it. Run the questions through every entry point that uses retrieval, including the API.
- Repeat as the lowest role inside tenant B, against a document only admins can open.
- Delete the canary document, wait for one sync cycle and ask again.
Fail the build if the codename shows up in any answer, citation, log line or trace the wrong user can see. It's an afternoon of work, and it then runs on every change, next to the 50 to 200 question eval set that checks quality.
What done looks like
A request comes in. The server resolves user, tenant and role from the session, and the retrieval function takes them as required arguments inside both searches. The reranker and the prompt only ever see permitted chunks. The cache key includes the tenant. The trace records which chunk IDs were used, so when a customer asks what the assistant saw, you can tell them.
Nothing there is exotic. It's the authorization model you already trust, applied to a read path that didn't exist last year.
Selling to customers who will ask how their data is isolated?
We map every path from user to index and back, add the leak tests to CI and fix what they find. Flat price, one senior engineer, your repo and your cloud account, usually two to five weeks. Send your email and we'll set up a 30-minute call within 24 hours.
The seven-question check
Two or more "no" or "not sure" answers mean your assistant is less isolated than the rest of your product.
- Is the tenant ID written onto every chunk at ingestion, including backfills and re-index jobs?
- Does the retrieval function refuse to run without a tenant taken from the session?
- Are the keyword and vector searches both filtered before reranking?
- Do role restrictions inside a customer apply to the assistant the same way they apply to the UI?
- Do cache keys include the tenant and the permission scope?
- Do you know how long after a delete or a revoked permission the assistant stops using that document?
- Does a cross-tenant canary test run on every build?
Related reading
- Your AI prototype works. Here is why it will fail in production: access is the first of six production gaps
- RAG done right in 2026: hybrid search, reranking, evals: the retrieval and eval setup these filters sit inside
- We inherited an AI-generated codebase. Here is what we found: the same tenant boundary, broken without any AI involved
The service: AI Product Development. Background: multi-tenant SaaS and RAG in our glossary.
Enjoyed this article? Share it with others
Related Posts

AI Will Not Replace Online Courses. It Will Replace Static Learning Paths
AI-generated lessons get the attention, but content is rarely why students quit. The bigger opening is the path: every student still gets the same next step. Where plain rules already adapt a course, where a model earns its place, and what a first version looks like.

We Replaced a Manual Workflow With an AI Agent: The Architecture
Content-idea research for Xperiencify and Coaching Genie used to be manual. Now it runs end to end. Most of what we shipped as an "AI agent" is plain code: intake, a fact sheet, rule checks, retries, a usage log. The model does the reading and writing. Here's the architecture.

How Much Will Your AI Feature Cost at 1,000 Active Users?
Your AI prototype costs a few dollars a week, so the feature looks cheap. At 1,000 active users, context growth, tool steps, retries, background jobs and evals multiply that. Here is the illustrative math, line by line, and the five levers that bring it down.