Most RAG tutorials stop once the model gives a good answer. This series starts there and asks a harder question: does every answer respect who is asking?
You build a support-assistant API for a multi-tenant SaaS product. Two synthetic customers, Acme and Globex, upload their own runbooks and help articles. Their staff ask questions and get answers with citations. The catch is that both tenants' documents live in the same PostgreSQL table, so one wrong query can hand Acme's runbook to a Globex user.
What you build, lesson by lesson
- Foundations. Map the ingest, retrieve and generate path, and name where it leaks. Store chunks and embeddings in PostgreSQL 17 with pgvector and an HNSW index. Then add a
/answerendpoint that refuses below a similarity threshold and checks every citation. At the end of this module the API works, and it deliberately leaks across tenants. - Security. Close the leak. A verified JWT becomes the caller's tenant and roles. Transaction-local settings carry them into PostgreSQL, where row-level security and document ACLs filter the vector query itself, not the results afterwards. Retrieved text is escaped and treated as untrusted data.
- Quality. Turn the rules into a build gate: a versioned golden dataset, recall@k and groundedness scores, hard cross-tenant probes and a CI workflow that fails when a change leaks data or lowers quality.
How it works in practice
Every lesson has a runnable folder in the companion repo, with tests you run against a throwaway PostgreSQL container. A deterministic fake embedder and a fake LLM stand in for paid APIs, so the whole series runs offline at no cost, and the provider interfaces show where a real model plugs in. Every command and output in the lessons comes from that code.
Who it is for
Backend engineers who know Node.js and REST, and who need to put retrieval in front of data that belongs to different customers. You don't need any RAG or vector database background.




