Weaviate 中的多租户
学习如何在单个 Weaviate 集合中按租户隔离数据,从而构建可扩展且安全的多客户应用。
Weaviate 中的多租户 是 CoddyKit 上的免费 Vector Databases: Pinecone, Weaviate & pgvector 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Vector Databases: Pinecone, Weaviate & pgvector 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Vector Databases: Pinecone, Weaviate & pgvector 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Why Multi-Tenancy?
Multi-tenancy lets one Weaviate collection serve many isolated customers (tenants) while keeping their data physically and logically separated.
- One schema, many tenants
- Strong data isolation
- Efficient resource use vs. one collection per customer
Enabling Multi-Tenancy
You enable multi-tenancy at collection creation time by setting multiTenancyConfig.enabled = true. Once enabled, every object must belong to a tenant.
{
"class": "Article",
"multiTenancyConfig": { "enabled": true }
}Creating Tenants
Tenants are added to a collection explicitly. Each tenant has a unique name and an activity status.
- HOT: active, queryable
- COLD: offloaded, must be activated first
POST /v1/schema/Article/tenants
[
{ "name": "customer-a" },
{ "name": "customer-b" }
]Inserting Tenant Data
When inserting objects you must specify which tenant owns the object. Data for one tenant is never visible to another.
{
"class": "Article",
"tenant": "customer-a",
"properties": { "title": "Hello" }
}Querying Per Tenant
Every query must include the tenant parameter. Weaviate scopes the search to that tenant's shard only, improving both isolation and performance.
{
Get {
Article (tenant: "customer-a", limit: 5) {
title
}
}
}Tenant Isolation Guarantees
Each tenant gets its own shard. This means:
- No cross-tenant data leakage
- Independent indexing per tenant
- Per-tenant lifecycle management
Activity Status & Offloading
Inactive tenants can be set to COLD to free memory, or offloaded to cloud storage. Reactivate them on demand to query again.
PUT /v1/schema/Article/tenants
[
{ "name": "customer-b", "activityStatus": "COLD" }
]Listing & Deleting Tenants
You can list all tenants of a collection or delete a tenant entirely. Deleting a tenant removes all its data permanently.
GET /v1/schema/Article/tenants
DELETE /v1/schema/Article/tenants
["customer-b"]Scaling with Many Tenants
Weaviate supports thousands of tenants efficiently because inactive shards consume minimal resources. Use COLD status aggressively for rarely-used tenants.
Python Client Example
The Python client makes tenant operations explicit via a tenant-scoped handle.
import weaviate
client = weaviate.connect_to_local()
articles = client.collections.get('Article')
tenant_a = articles.with_tenant('customer-a')
tenant_a.data.insert({'title': 'Edge case'})
client.close()Best Practices
Guidelines for multi-tenant Weaviate:
- Use one tenant per customer, not per request
- Set unused tenants to COLD
- Always validate the tenant param server-side to prevent enumeration
Quick Check
Test your understanding of multi-tenancy.
Recap
You learned to enable multi-tenancy, create and manage tenants, insert and query tenant-scoped data, and use COLD status for scaling. Multi-tenancy is the key to building secure, multi-customer apps on a single Weaviate collection.
常见问题解答
「Weaviate 中的多租户」课时是免费的吗?
是的 — 「Weaviate 中的多租户」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Vector Databases: Pinecone, Weaviate & pgvector 课程的其余内容,请升级到 CoddyKit PRO。 Vector Databases: Pinecone, Weaviate & pgvector 课程共包含 4 节课。
「Weaviate 中的多租户」这节课中我会学到什么?
学习如何在单个 Weaviate 集合中按租户隔离数据,从而构建可扩展且安全的多客户应用。 你通过在浏览器中直接运行的动手代码来练习 Vector Databases: Pinecone, Weaviate & pgvector,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Vector Databases: Pinecone, Weaviate & pgvector 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Vector Databases: Pinecone, Weaviate & pgvector 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「Weaviate 中的多租户」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Vector Databases: Pinecone, Weaviate & pgvector 课中编写并运行代码吗?
能。每节 Vector Databases: Pinecone, Weaviate & pgvector 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 语义搜索与混合搜索
- 使用 Weaviate 模块
- 备份与恢复策略
- Weaviate 中的多租户