多租戶與命名空間

使用 Pinecone 構建 AI 應用

James Chapman

Curriculum Manager, DataCamp

多租戶(Multitenancy)

 

  • 在_隔離_中服務多個 tenant
  • 分離不同客戶的資料
    • 安全隱私
  • 降低查詢延遲

多租戶架構示意

使用 Pinecone 構建 AI 應用

多租戶策略

 

  1. 命名空間(Namespaces)
    • 優點:可減少額外索引需求
    • 缺點:tenant 共享資源,資料較複雜
  2. 中介資料過濾(Metadata Filtering)
    • 優點:可跨多個 tenant 查詢
    • 缺點:資源共享,成本追蹤困難
  3. 獨立索引(Separate Indexes)
    • 優點:實體區隔 tenant,能分配獨立資源
    • 缺點:需要更多人力與成本
使用 Pinecone 構建 AI 應用

命名空間(Namespaces)

  • 若不存在,會在 upsert 時_隱式_建立
index.upsert(
  vectors=vector_set1, namespace="namespace1"
)
index.upsert(
  vectors=vector_set2, namespace="namespace2"
)
使用 Pinecone 構建 AI 應用

檢視命名空間

index.describe_index_stats()
{'dimension': 1536,
 'index_fullness': 0.0,
 'namespaces': {'namespace1': {'vector_count': 5},
                'namespace2': {'vector_count': 5}},
 'total_vector_count': 10}
使用 Pinecone 構建 AI 應用

從命名空間查詢向量

query_result = index.query(
    vector=vector,

namespace='namespace1',
top_k=3 )
使用 Pinecone 構建 AI 應用

自命名空間刪除向量

index.delete(
    ids=["1", "2"],
    namespace='namespace1'
)
使用 Pinecone 構建 AI 應用

一起來練習吧!

使用 Pinecone 構建 AI 應用

Preparing Video For Download...