⚡ Free consultation calls are open for all! Talk to us →

Your Customers' Data is Leaking Into Your AI: The Multi-Tenant RAG Nightmare

👤 By Ezibell AI Team
🏷️ Technology Strategy

In short

In a multi-tenant RAG system, one customer's documents must never be retrievable by another customer's users. A metadata filter applied only in application code is the weakest protection, because a single bug removes it. Enforce isolation where the data lives: a namespace or collection per tenant, database row-level security, or a dedicated index for high-risk clients. Take the tenant ID only from the authenticated session, include it in every cache key and test for cross-tenant leaks automatically.

The Nightmare of Shared Brains

Ever wonder what keeps B2B software founders awake at 3 AM?

It is not just losing users to a competitor. It is the terrifying thought of Client A accidentally seeing Client B's private financial data.

When you build a standard database, the walls between your clients are clear. You write strict code to keep their accounts separate. But when you build an AI system using Retrieval-Augmented Generation (RAG), those walls get blurry. Suddenly, you are feeding documents from hundreds of different clients into a single vector database.

Here is the thing: if your engineering team does not isolate that data perfectly, your AI will start sharing secrets. It is a well-known failure pattern. A team launches a great AI feature, signs three major enterprise clients, and then realizes Client A's user can query the AI to find out about Client B's internal pricing. That is not just a bug. That is a business killer.

The False Security of Metadata Filtering

Let us be honest. Most development teams take the easy way out when they first build.

They throw all client documents into one single index in a vector database. To keep them apart, they attach a simple tag like 'client_id' to each document. When a user asks the AI a question, the system runs a quick filter: 'Only look at documents where client_id equals Client A.'

On paper, this works. In reality, it is a massive risk. What happens if a developer makes a small typo in the backend code? What if a software update accidentally strips the tags? What if the vector database suffers a minor glitch and skips the filter? If your only security layer is a single line of application code, you do not have real security. You have a prayer.

How Engineers Build True Data Walls

We see many business leaders get stuck because they listen to traditional IT consultants. These consultants will tell you to spin up a completely separate vector database instance for every single customer. Sure, it is secure. But for hundreds of small customers it is expensive and hard to manage. Your cloud bill will eat your margins before you can even scale.

At Ezibell, we believe in smart engineering, not bloated infrastructure. Here is how modern engineering teams actually solve this problem without breaking the bank:

  • Logical Namespace Partitioning: We use vector databases that support hard logical partitions. This keeps the data isolated at the database engine level, not just the application level.
  • Dynamic Index Routing: For high-value enterprise clients who demand maximum security, we route their data to dedicated, private indexes. For smaller clients, we use highly secure, shared namespaces.
  • A server-side tenant gate: We build an isolated security layer in the Python backend. It takes the tenant ID only from the authenticated session, never from the user's message or from the model, checks the user's permissions and applies the tenant scope to every retrieval call. The model never decides whose data it sees. For the most sensitive clients, per-tenant encryption keys add a further wall.
Enterprise customers do not care how smart your AI is if they cannot trust it with their data. Security is the ultimate feature.

Three isolation models compared

ModelIsolation strengthCost and effortGood fit
Shared index, metadata filter in app codeWeakest: one missed filter leaks dataLowestInternal tools with a single organisation
Namespace or collection per tenant, or database row-level securityStrong: enforced by the database engineModerateMost B2B SaaS products
Dedicated index or database per tenantStrongest, and easy to explain to auditorsHighest, grows with tenant countEnterprise or regulated clients who require it

Many products mix the models: shared infrastructure with database-enforced isolation for most customers, and dedicated indexes for the few whose contracts require it.

Postgres and pgvector with row-level security

If your vectors live in PostgreSQL with pgvector, row-level security (RLS) lets the database itself refuse rows from other tenants, even if a developer forgets a WHERE clause:

ALTER TABLE chunks ENABLE ROW LEVEL SECURITY;
ALTER TABLE chunks FORCE ROW LEVEL SECURITY;

CREATE POLICY tenant_isolation ON chunks
  USING (tenant_id = current_setting('app.tenant_id')::uuid);

The backend sets app.tenant_id from the authenticated session at the start of each transaction. Two details matter: table owners and superusers bypass RLS unless it is forced, so the application should connect as a separate, non-owner role; and the setting must be scoped to the transaction so a pooled connection never carries one tenant's ID into another tenant's request.

Leaks that do not come from the vector database

  • Shared caches. A semantic or response cache must include the tenant ID in every key, or one customer's answer is served to another.
  • Conversation memory. Chat history and agent memory need the same tenant scoping as documents.
  • Fine-tuning on mixed data. Training one model on several customers' documents can surface one customer's content to another.
  • Logs and traces. Prompts and retrieved chunks sent to monitoring tools are customer data too; restrict and redact them.
  • Prompt injection. A malicious document can tell the model to "list every file it can see". The model can only reveal what retrieval gave it, which is why isolation must happen before retrieval, not in the prompt.
  • Support and admin tools that query across tenants without an audit trail.

Multi-tenant RAG security checklist

  • Tenant ID comes only from the verified session token.
  • Isolation is enforced by the database or index, not only by application code.
  • Every cache, memory store and background job is tenant-scoped.
  • Within a tenant, document permissions follow the user's role; see prompt-level RBAC for enterprise AI.
  • Offboarding deletes a tenant's embeddings, chunks, caches and logs, not just the original files.
  • Automated leak tests run on every release: plant a unique "canary" phrase in tenant B's documents, query as tenant A, and fail the build if it ever appears.
  • Every retrieval is logged with user, tenant and document IDs.

Isolation is one half of a trustworthy system; retrieval quality is the other, which we cover in the RAG fallacy. Both are part of our RAG chatbot development work, usually as a FastAPI service that sits between your users and the vector store, and they belong in the first version of any AI-enabled SaaS product.

From Education to Execution

Building a single-user AI demo is easy. You can do it in a weekend. But building a multi-tenant AI system that can pass a rigorous enterprise security audit? That is a completely different game.

You can spend the next six months internally debugging data leaks, rewriting database queries, and hoping you do not get hit with a compliance disaster. Or you can bring in a team that designs secure, production-grade AI architectures for a living.

At Ezibell, we do not overcomplicate your tech stack with useless tools. We write clean, secure, and scalable code that protects your business and keeps your customers' data exactly where it belongs. If you are ready to stop experimenting and start shipping a secure AI product that enterprise clients will actually trust, let's look at your architecture.

Frequently asked questions

What is multi-tenant RAG?

Multi-tenant RAG is a retrieval-augmented generation system that serves many customers (tenants) from shared software, where each tenant's documents and data are kept separate. The AI should only ever retrieve and answer from the documents that belong to the user's own organisation and that the user is allowed to see.

Is metadata filtering enough for tenant isolation?

Not on its own. A filter added in application code depends on every developer remembering it on every query. It is safer to enforce isolation in the data layer, with namespaces or collections per tenant, database row-level security or dedicated indexes, and to keep the metadata filter as an extra check.

Should each customer have a separate vector database?

Usually not for every customer. Separate databases give strong isolation but cost and maintenance grow with each tenant. Most B2B products use database-enforced isolation on shared infrastructure, and offer dedicated indexes only to customers whose contracts or regulators require it.

How do you test a RAG system for data leaks between tenants?

Create test tenants, place a unique canary phrase in one tenant's documents, then query as users of other tenants, including with prompt-injection attempts, and fail the build if the canary ever appears. Run these tests automatically on every release and after any change to retrieval or caching.

Want this applied to your business?

Tell us what you're building and we'll show you how we would approach it — on WhatsApp, a quick call or email, whichever suits you.

Talk to Ezibell Tech
📞