Namespaces
Multi-tenant / multi-collection isolation on a single index.
A namespace gives each tenant an isolated view of the same dynavec index. Every vector is tagged with its namespace, and searches are automatically scoped to that namespace. This lets multiple customers share the same infrastructure while keeping their retrieval results separated.
Namespace-per-tenant
Use db.namespace("tenant-id") to create a lightweight handle bound to one tenant. The same
document ID can exist in multiple namespaces because the namespace is part of the storage key.
acme = db.namespace("acme")
globex = db.namespace("globex")
acme.upsert([Document(id="refund-policy", text="Acme refunds are available within 30 days.")])
globex.upsert([Document(id="refund-policy", text="Globex refunds are available within 14 days.")])
acme.search("What is the refund period?", top_k=2)
globex.search("What is the refund period?", top_k=2)
End-to-end multi-tenant RAG
A typical RAG application maps the authenticated tenant to a namespace, retrieves context from that namespace, and passes only that context to the LLM.
tenant = db.namespace(tenant_id)
hits = tenant.search(user_query, top_k=5)
context = "\n\n".join(hit.text for hit in hits)
answer = llm.generate(
f"Answer using only the following context:\n{context}\n\nQuestion: {user_query}"
)
The complete runnable recipe is available in
examples/multi_tenant_rag.py. It demonstrates two tenants using the same index, including identical
document IDs with tenant-specific content.
Runnable example
pip install "dynavec[sentence-transformers]"
python examples/multi_tenant_rag.py