Pinecone

orchestra-research/ai-research-skills/15-rag/pinecone

作者 orchestra-research773a52944ba4MIT13K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库3个月前更新

Managed vector database for production AI applications. Fully managed, auto-scaling, with hybrid search (dense + sparse), metadata filtering, and namespaces. Low latency (<100ms p95). Use for production RAG, recommendation systems, or semantic search at scale. Best for serverless, managed infrastructure.

仅含说明AI & Agents
AI 生成的概览

指导使用托管向量数据库 Pinecone,用于生产级 RAG、语义搜索和推荐系统。

功能
该技能提供使用 Pinecone 这一托管无服务器向量数据库的参考说明。内容涵盖安装 pinecone-client 包、创建无服务器或基于 Pod 的索引、写入与查询向量、元数据过滤、命名空间、稠密与稀疏混合搜索,以及删除索引和向量。它还记录了 LangChain 与 LlamaIndex 集成、性能指标、定价和最佳实践。
适用场景
适用于构建生产级检索增强生成、语义搜索或推荐系统,且需要托管、自动扩缩容、低延迟向量存储的场景。适合倾向于无服务器基础设施而非 Chroma、FAISS 或 Weaviate 等自托管方案的团队。
运行要求
需要 pinecone-client Python 包和 Pinecone API 密钥;索引与查询操作需要访问 Pinecone 服务的网络连接。可选集成使用 LangChain、LlamaIndex 和 OpenAI 嵌入。该技能仅提供说明文档,附带一份部署参考文档,不含脚本。

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

bash
pip install pinecone-client

Basic usage

python
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

python
# 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 PodSpec
pc.create_index(    name="my-index",    dimension=1536,    metric="cosine",    spec=PodSpec(        environment="us-east1-gcp",        pod_type="p1.x1"    ))

Upsert vectors

python
# 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

python
# 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

python
# 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

python
# 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)

python
# 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

python
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

python
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, VectorStoreIndex
storage_context = StorageContext.from_defaults(vector_store=vector_store)index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)

Index management

python
# 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

python
# 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

  1. Use serverless - Auto-scaling, cost-effective
  2. Batch upserts - More efficient (100-200 per batch)
  3. Add metadata - Enable filtering
  4. Use namespaces - Isolate data by user/tenant
  5. Monitor usage - Check Pinecone dashboard
  6. Optimize filters - Index frequently filtered fields
  7. Test with free tier - 1 index, 100K vectors free
  8. Use hybrid search - Better quality
  9. Set appropriate dimensions - Match embedding model
  10. Regular backups - Export important data

Performance

OperationLatencyNotes
Upsert~50-100msPer batch
Query (p50)~50msDepends on index size
Query (p95)~100msSLA target
Metadata filter~+10-20msAdditional 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

来源与署名

来源:orchestra-research/ai-research-skills位于15-rag/pinecone提交773a529

许可证: MIT

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架