Self-Hosted Multi-Tenant RAG Application
Build a production multi-tenant RAG app with tenant-scoped TypeGraph clients, document ingest, events, and search.
1
Cache Clients by Tenant
Create one TypeGraph client per customer tenant. Each client shares your Postgres and model configuration while tenantId selects an isolated customer graph.
typegraph-factory.ts
2
Require X-Tenant-Id
API routes should require X-Tenant-Id. Do not expose tenant choice as organization ID or as a top-level body field. If internal SDK payloads carry identity.tenantId, validate that it matches the header.
tenant-header.ts
3
Ingest Documents
Document ingest should call typegraph.document.ingest() and pass all per-call identity and write access under context.
documents-route.ts
4
Search Tenant Data
Search always runs inside the tenant-bound client. context narrows readable records; resources and weights control retrieval and scoring.
search.ts