pinecone
zechenzhangAGI/AI-research-SKILLs
專為生產環境人工智慧應用設計的託管向量資料庫。具備完全託管、自動擴展、混合搜尋(密集 + 稀疏)、元資料篩選及命名空間等功能。低延遲(p95 小於 100 毫秒)。適用於生產環境中的 RAG、推薦系統或大規模語義搜尋。 最適合用於無伺服器、託管式基礎架構。
...展開全部關於 pinecone
Pinecone 是一款專為生產環境中的 AI 應用程式設計、完全託管的無伺服器向量資料庫。它不僅能解決向量資料庫的擴展問題,同時也能處理基礎架構管理的複雜性。Pinecone 提供了一個平台,讓開發人員能夠專注於建構 AI 應用程式,無需擔心底層資料庫架構的相關事宜,例如資源配置、擴展或維護。 其低延遲(p95 小於 100 毫秒)的特性,使其非常適合用於推薦系統、語義搜尋以及檢索增強生成(RAG)應用程式等生產環境。
Pinecone 的關鍵功能包括結合密集向量與稀疏向量的混合搜尋、元資料過濾,以及對命名空間的支持。該平台專為高可用性與可靠性而建,提供 99.9% 正常運作時間的服務水準協議 (SLA)。Pinecone 可自動擴展至數十億個向量,且不會造成效能下降,因此非常適合用於大型生產系統。 它與 AWS、GCP 和 Azure 等雲端服務供應商的整合,提供了靈活的部署選項,並能無縫運作於無伺服器或基於 Pod 的環境中,以滿足不同的效能需求。
Pinecone 本平台專為開發人工智慧驅動應用程式,且需要高效且可擴展向量搜尋功能的組織與開發者而設計。 理想的應用場景包括 RAG 系統、推薦引擎以及大規模語義搜尋,特別是在延遲與基礎架構管理至關重要的情況下。憑藉其簡易的整合性與託管服務模式,Pinecone 對於需要可靠且維護成本低的向量資料庫解決方案來處理 AI 工作負載的開發者而言,是絕佳的選擇。
常見問題
如何開始使用 Pinecone?
要開始使用 Pinecone,您可以透過 `pip install pinecone -client` 安裝 `pinecone -client` Python 套件。接著,初始化 Pinecone 客戶端、建立索引、對向量執行 upsert 操作,並執行查詢。文件中針對上述每個步驟皆提供範例程式碼。
Pinecone 的延遲是多少?
Pinecone 具備低延遲特性,其 p95 延遲低於 100 毫秒,因此非常適合需要快速響應時間的生產環境應用程式。
Pinecone 是否支援混合搜尋?
是的,Pinecone 支援混合搜尋,允許在查詢中同時使用密集向量與稀疏向量,以提供更靈活且高效的搜尋能力。
我可以根據元資料篩選結果嗎?
是的,Pinecone 提供元資料篩選功能,讓您能依據各種條件(例如完全匹配、比較、邏輯運算子,或用於清單的「in」運算子)來篩選查詢結果。
Pinecone 是無伺服器架構嗎?
是的,Pinecone 預設為無伺服器架構,但亦支援基於 Pod 的部署,以滿足需要在特定環境中獲得更穩定效能的使用者需求。
Pinecone - Managed Vector Database
The vector database for production AI applications.
When to use Pinecone
Use when:
- Need managed, serverless vector database
- Production RAG applications
- Auto-scaling required
- Low latency critical (<100ms)
- Don't want to manage infrastructure
- Need hybrid search (dense + sparse vectors)
Metrics:
- Fully managed SaaS
- Auto-scales to billions of vectors
- p95 latency <100ms
- 99.9% uptime SLA
Use alternatives instead:
- Chroma: Self-hosted, open-source
- FAISS: Offline, pure similarity search
- Weaviate: Self-hosted with more features
Quick start
Installation
pip install pinecone-client
Basic usage
from pinecone import Pinecone, ServerlessSpec# Initializepc = Pinecone(api_key="your-api-key")# Create indexpc.create_index( name="my-index", dimension=1536, # Must match embedding dimension metric="cosine", # or "euclidean", "dotproduct" spec=ServerlessSpec(cloud="aws", region="us-east-1"))# Connect to indexindex = pc.Index("my-index")# Upsert vectorsindex.upsert(vectors=[ {"id": "vec1", "values": [0.1, 0.2, ...], "metadata": {"category": "A"}}, {"id": "vec2", "values": [0.3, 0.4, ...], "metadata": {"category": "B"}}])# Queryresults = index.query( vector=[0.1, 0.2, ...], top_k=5, include_metadata=True)print(results["matches"])
Core operations
Create index
# Serverless (recommended)pc.create_index( name="my-index", dimension=1536, metric="cosine", spec=ServerlessSpec( cloud="aws", # or "gcp", "azure" region="us-east-1" ))# Pod-based (for consistent performance)from pinecone import PodSpecpc.create_index( name="my-index", dimension=1536, metric="cosine", spec=PodSpec( environment="us-east1-gcp", pod_type="p1.x1" ))
Upsert vectors
# Single upsertindex.upsert(vectors=[ { "id": "doc1", "values": [0.1, 0.2, ...], # 1536 dimensions "metadata": { "text": "Document content", "category": "tutorial", "timestamp": "2025-01-01" } }])# Batch upsert (recommended)vectors = [ {"id": f"vec{i}", "values": embedding, "metadata": metadata} for i, (embedding, metadata) in enumerate(zip(embeddings, metadatas))]index.upsert(vectors=vectors, batch_size=100)
Query vectors
# Basic queryresults = index.query( vector=[0.1, 0.2, ...], top_k=10, include_metadata=True, include_values=False)# With metadata filteringresults = index.query( vector=[0.1, 0.2, ...], top_k=5, filter={"category": {"$eq": "tutorial"}})# Namespace queryresults = index.query( vector=[0.1, 0.2, ...], top_k=5, namespace="production")# Access resultsfor match in results["matches"]: print(f"ID: {match['id']}") print(f"Score: {match['score']}") print(f"Metadata: {match['metadata']}")
Metadata filtering
# Exact matchfilter = {"category": "tutorial"}# Comparisonfilter = {"price": {"$gte": 100}} # $gt, $gte, $lt, $lte, $ne# Logical operatorsfilter = { "$and": [ {"category": "tutorial"}, {"difficulty": {"$lte": 3}} ]} # Also: $or# In operatorfilter = {"tags": {"$in": ["python", "ml"]}}
Namespaces
# Partition data by namespaceindex.upsert( vectors=[{"id": "vec1", "values": [...]}], namespace="user-123")# Query specific namespaceresults = index.query( vector=[...], namespace="user-123", top_k=5)# List namespacesstats = index.describe_index_stats()print(stats['namespaces'])
Hybrid search (dense + sparse)
# Upsert with sparse vectorsindex.upsert(vectors=[ { "id": "doc1", "values": [0.1, 0.2, ...], # Dense vector "sparse_values": { "indices": [10, 45, 123], # Token IDs "values": [0.5, 0.3, 0.8] # TF-IDF scores }, "metadata": {"text": "..."} }])# Hybrid queryresults = index.query( vector=[0.1, 0.2, ...], sparse_vector={ "indices": [10, 45], "values": [0.5, 0.3] }, top_k=5, alpha=0.5 # 0=sparse, 1=dense, 0.5=hybrid)
LangChain integration
from langchain_pinecone import PineconeVectorStorefrom langchain_openai import OpenAIEmbeddings# Create vector storevectorstore = PineconeVectorStore.from_documents( documents=docs, embedding=OpenAIEmbeddings(), index_name="my-index")# Queryresults = vectorstore.similarity_search("query", k=5)# With metadata filterresults = vectorstore.similarity_search( "query", k=5, filter={"category": "tutorial"})# As retrieverretriever = vectorstore.as_retriever(search_kwargs={"k": 10})
LlamaIndex integration
from llama_index.vector_stores.pinecone import PineconeVectorStore# Connect to Pineconepc = Pinecone(api_key="your-key")pinecone_index = pc.Index("my-index")# Create vector storevector_store = PineconeVectorStore(pinecone_index=pinecone_index)# Use in LlamaIndexfrom llama_index.core import StorageContext, VectorStoreIndexstorage_context = StorageContext.from_defaults(vector_store=vector_store)index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
Index management
# List indicesindexes = pc.list_indexes()# Describe indexindex_info = pc.describe_index("my-index")print(index_info)# Get index statsstats = index.describe_index_stats()print(f"Total vectors: {stats['total_vector_count']}")print(f"Namespaces: {stats['namespaces']}")# Delete indexpc.delete_index("my-index")
Delete vectors
# Delete by IDindex.delete(ids=["vec1", "vec2"])# Delete by filterindex.delete(filter={"category": "old"})# Delete all in namespaceindex.delete(delete_all=True, namespace="test")# Delete entire indexindex.delete(delete_all=True)
Best practices
- Use serverless - Auto-scaling, cost-effective
- Batch upserts - More efficient (100-200 per batch)
- Add metadata - Enable filtering
- Use namespaces - Isolate data by user/tenant
- Monitor usage - Check Pinecone dashboard
- Optimize filters - Index frequently filtered fields
- Test with free tier - 1 index, 100K vectors free
- Use hybrid search - Better quality
- Set appropriate dimensions - Match embedding model
- Regular backups - Export important data
Performance
| Operation | Latency | Notes |
|---|---|---|
| Upsert | ~50-100ms | Per batch |
| Query (p50) | ~50ms | Depends on index size |
| Query (p95) | ~100ms | SLA target |
| Metadata filter | ~+10-20ms | Additional overhead |
Pricing (as of 2025)
Serverless:
- $0.096 per million read units
- $0.06 per million write units
- $0.06 per GB storage/month
Free tier:
- 1 serverless index
- 100K vectors (1536 dimensions)
- Great for prototyping
Resources
- Website: https://www.pinecone.io
- Docs: https://docs.pinecone.io
- Console: https://app.pinecone.io
- Pricing: https://www.pinecone.io/pricing





首頁
