AI products

How to add RAG to an existing SaaS product

Where retrieval sits in a stack you already run, why tenant isolation decides the design, and what it costs in seconds and cents — measured, not estimated.

Short answer. As a service beside your API, not inside it: ingestion and reindexing on a schedule, retrieval that filters by tenant and permission before it ranks anything, one interface to the model, and an evaluation set before launch. Budget $15,000–$30,000 over 2–4 weeks for the first feature. On a system we measured, an answer costs about $0.011 and takes 1.9 seconds to the last token — about 0.3 s of retrieval and 1.5 s of generation.

Where RAG sits in a SaaS you already run

Six parts, and only one of them is the model:

  1. Connectors and ingestion. Pull documents from wherever they live in your product and outside it, normalise them, split them into passages.
  2. An index that keeps up. The reindex interval matters more than the corpus size. The system measured below indexes roughly 2,500 documents and reindexes them daily, because the data changes daily.
  3. A retrieval service that filters by tenant and permission first, then ranks. This is the part that decides the design, and the next section is about it.
  4. One interface to the model, so the provider can change without touching the product: streaming, fallback, token budgets.
  5. An answer surface in your product, with the sources shown, so a user can check what the answer rests on.
  6. An evaluation set and monitoring, so a quality drop is a failed check rather than a support ticket.

For the index, if you already run PostgreSQL, keeping vectors in it with pgvector puts them next to the data and the tenant model you already enforce. A dedicated vector store — Pinecone, Weaviate, Qdrant — earns its place when the corpus or the query load outgrows the database you have, not before.

Tenant isolation is the requirement that decides the design

In a multi-tenant SaaS, the one failure you cannot have is an answer built from another customer’s documents. The prompt is not a security boundary: telling a model to ignore passages it has been given is not the same as not giving them. So the filter goes into the retrieval query itself, by tenant and by permission, before ranking — the same way tenancy is enforced in the schema rather than in middleware, which is decision one of building a multi-tenant SaaS.

It is also why retrieval rather than fine-tuning: anything trained into a model is available to every tenant who reaches it. The longer version of that argument.

The latency budget, measured

StageTime, average
Retrievalabout 0.3 s
Generation, to the last tokenabout 1.5 s
Everything else in the pipelineabout 0.1 s
Total, averageabout 1.9 s
Total, p95about 4.2 s

Measured to the last token, not the first. That is the harder number to publish and the one a user actually waits for. Streaming the answer lets the first words appear well before it; it does not change when the answer is complete.

The cost per answer, measured

About $0.011 per answer: roughly $0.002 of retrieval and $0.009 of generation, across about 40,000 queries a month — which is about $440 a month, as arithmetic. The split is the transferable part. Retrieval infrastructure is the cheap fifth; what retrieval really costs arrives in the generation line, as the extra input tokens every retrieved passage adds to every prompt. Context length is the cost lever, not the vector database. To see what that lever is worth at your own prices and volume, the AI token cost calculator prices the retrieved context as its own line.

Rolling it out without risking the product

What it costs to build

An LLM feature added to a product that already exists — document Q&A is the classic case — is our $15,000–$30,000, 2–4 week band, at a fixed price agreed after a discovery call. The variable is not the model; it is how much of your existing codebase has to be touched to reach the data. How we build it is on the AI integration page; if you would rather build it inside your own team, our AI engineers join your board from $4,000 a month.

Common questions

Three that come up once retrieval meets a real product.

Two to four weeks for the first feature, in our published band. What stretches it is not the model but how much of the existing codebase has to be touched to reach the data, and how many systems the documents come from.
Usually not at first. If you already run PostgreSQL, pgvector keeps the index next to your data and the tenant model you already enforce. A dedicated vector store earns its place when the corpus or the query load outgrows the database you have.
Filter by tenant and permission inside the retrieval query, before ranking, so another tenant’s passages never reach the model at all. The prompt is not a security boundary, and anything fine-tuned into a model is available to every tenant who reaches it.

Adding RAG to a product you run?

Tell us where the documents live and who may see which. We come back with how we would build it and what it costs, in writing.

Message received

We’ll review your enquiry and respond within one business day.

Related reading