Skip to content
Ali Hassan, home

Blog6 min read

Multi-tenant RAG in production: building Evoriqa

Multi-tenant RAG in production: how Evoriqa keeps each business's knowledge separate, runs in shadow mode first and meters use. Read the build story.

By Ali Hassan, Senior engineer for SaaS and AI products

Multi-tenant RAG means one retrieval system serving many customers at once, with each customer's knowledge walled off from the rest. I build and run exactly this in Evoriqa, my own support product, where I also pay the model bill. Here is the build story: how retrieval stays per tenant, why the agent drafts in shadow mode first, how use is metered, and which channels one agent answers on.

What is multi-tenant RAG?

Multi-tenant RAG is retrieval-augmented generation where one system holds the knowledge of many separate tenants and answers each one only from its own content. Plain RAG, described in the 2020 retrieval-augmented generation paper, fetches matching text and drops it into the prompt. The multi-tenant version adds a hard rule on top: every search is scoped to the tenant who asked, so no reply can ever draw on another tenant's data.

The idea is old; the discipline is what SaaS adds. One fixed lookup is fine for a single knowledge base. Serving many tenants from the same store is where the care goes, because a mistake means one customer seeing another's content, which ends trust in a support product. That single risk is why a multi-tenant build spends most of its effort on scoping and isolation, long before anyone tunes the ranking.

What makes multi-tenant RAG hard in a SaaS?

Three forces pull against each other. Every tenant's data has to stay isolated, so a retrieval slip can never put one business's content into another's reply. Every answer has a real model cost the platform pays, so use has to be metered. And each messaging channel brings its own webhooks and limits. RAG for SaaS is mostly the work of holding all three at once, not the retrieval itself.

The isolation problem shapes the storage choice first. pgvector's docs note that strong tenant isolation can use list partitioning or separate tables, which shows how much isolation drives a multi-tenant design. As of 30 November 2026, I run all three forces together in production, and the hard part is never the clever retrieval trick; it is the plumbing that keeps tenants, cost and channels in line.

How does Evoriqa keep retrieval separate per tenant?

Every search is scoped to one workspace and one agent before it runs, so a tenant only ever retrieves its own chunks. Tenants, billing and vectors all live in one PostgreSQL database with pgvector, which puts a tenant's documents and their embeddings under the same isolation. Each question runs semantic and keyword search together, ranked as one result, so exact product names are found as well as paraphrases. A multi-tenant RAG architecture lives or dies on that scoping.

pgvector stores embeddings as ordinary Postgres columns, so a search can filter by workspace in the same query that ranks by vector distance. The keyword half leans on Postgres full-text search, with its tsvector and ranking, which catches exact terms a pure vector search can miss, including questions in Arabic or Chinese. I weigh pgvector against a dedicated store in pgvector vs Pinecone, and the plain single-tenant shape is the one in RAG architecture. You can see the product on the Evoriqa case study.

Why run the agent in shadow mode before autonomy?

Because an agent answering wrongly on a live channel harms the business's own customer relationships, autonomy has to be earned, not assumed. Evoriqa has three modes: human-only, shadow, and automatic. In shadow mode the agent drafts every reply into the team inbox, and nothing reaches the customer until a person sends it. Per-channel numbers, drafts, approvals and how much people edit, show when a channel is ready to run on its own.

This follows the advice in Anthropic's notes on building agents: start with the simplest thing that works and add autonomy only once it earns its place. OpenAI's agents guide likewise builds human approval into the loop. A teammate can also claim any live conversation and reply in real time, so a tricky question never waits on the machine. Shadow mode is the bridge between a draft nobody trusts yet and a channel that runs on its own. The gate is the point: a channel moves to automatic only when its own numbers say people have stopped correcting it.

How is model use metered without surprise bills?

Every AI action, chat, voice, actions and knowledge ingestion, draws from a single credit balance, so a workspace sees exactly what its AI use costs. Workspaces set a monthly spend cap, and owners are emailed as usage crosses thresholds. When credits run out, customer messages still reach a person instead of being lost. The cost behind all this is real: as of 30 November 2026, Claude Sonnet 5.5 lists at $2 per million input tokens and $10 per million output.

Those rates come from Anthropic's pricing page, and a busy tenant can run through a lot of them. Metering turns that into a number a workspace can see and cap, rather than a bill that lands at the end of the month. I cover tracking spend per request in LLM observability, because you cannot cap what you do not measure.

Which channels does one agent answer on?

One agent, connected once, answers on web chat, WhatsApp, Instagram, Messenger, Slack, SMS, email and a phone line, with business hours and human handoff set per agent. Each channel has its own webhooks: WhatsApp, for example, delivers incoming messages and delivery status through Meta's Cloud API. Agencies resell the same platform under their own brand, hand a pooled credit balance to client workspaces, and bill those clients through their own Stripe account.

WhatsApp's Cloud API reports message delivery through webhook callbacks, and every one of the 8 channels has limits of its own, which is why channel plumbing, not retrieval, is where much of the work goes. A visitor can even paste a website address and get a live, shareable agent built from that site, with no sign-up, then claim it into a real workspace with its knowledge intact. Each connection is set up once, after which the same grounded answers flow out wherever the customer happens to write.

What would I keep, and where does outside help fit?

I would keep one PostgreSQL database for tenants, billing and vectors. The trade-off is a single database to scale instead of a dedicated vector store. As of 30 November 2026, Evoriqa runs this way in production, with vectors as ordinary columns through pgvector, so a tenant's embeddings fall under the same isolation as the rest of its data.

If you are adding multi-tenant RAG to a SaaS, or you have retrieval that leaks across tenants or a model bill you cannot explain, that is the work I take on. I build retrieval that stays per tenant, prove isolation holds, and meter cost so it does not surprise you. You can see the shape of it on AI product build. If a simpler setup is all you need, I will say so.

From the work

  • AI reply grounded in cited help-centre content, shadow-mode draft metrics per channel, and metered AI credits in billing.

    Evoriqa

    My own SaaS: a multi-tenant AI customer-support platform, live in production, built by the person who also pays its inference bill.

    Live in production

    • Next.js
    • TypeScript
    • PostgreSQL
  • PDF chat with document scope selector, landing page and upload queue of a RAG assistant that cites its pages.

    AI PDF Chat

    Upload several PDFs and ask questions across all of them or one; every answer cites the PDF and page, and the citation opens the passage highlighted.

    • Next.js
    • Express
    • LangChain

The offer this article leads to: AI product build, typically $15k-$40k.

Tell me what you’re building and where it’s stuck.

I’ll tell you the cleanest path forward, including if it’s “don’t build that.”

Email only, on purpose: it reaches me, not a sales team.

Or write tocontact@alihassan.dev

Ali Hassan in a dark winter jacket, looking off to one side, standing in a stone courtyard with a minaret and cloudy sky behind him.