# Multitenancy on namespaces
## The pattern
One index serves all tenants; each tenant's vectors live in its namespace. Every data-plane call carries the tenant's namespace. Deletes are per-tenant (`delete_all` in the namespace). Stats break down per namespace for per-tenant observability.
## Steps
1. **Create one index** with the shared embedding dimension and metric. All tenants must use the same embedding model.
2. **Derive the namespace server-side** from the authenticated tenant id. Never accept a namespace from client input; that is a cross-tenant read vulnerability.
3. **Write a data-access wrapper** that takes `tenant_id`, maps it to a namespace string, and passes it to every upsert, query, fetch, delete, and stats call. No raw index calls outside the wrapper.
4. **Onboard tenants** by upserting into their namespace; namespaces auto-create.
5. **Offboard tenants** with `delete(delete_all=True, namespace=...)`. Verify the namespace count hits zero in stats.
6. **Monitor per namespace** with `describe_index_stats` filtering, and alert on per-tenant growth anomalies.
## Traps
1. Forgetting the namespace on one call site: that site reads or writes the default namespace, leaking data across tenants or losing writes.
2. Tenant ids with dots, uppercase, or spaces as namespace strings: sanitize to the same charset rules as index names.
3. Tenants needing different dimensions or models: namespaces share the index config, so this needs separate indexes per cohort, not per tenant.