mcpField
P
pinecone

pinecone

github.com/kalarislabsその他7343 回インストール4 日前に更新
リポジトリ

pinecone について

Pinecone は、本番向け RAG や AI アプリを構築する開発者向けのマネージドベクトルデータベースのスキルです。インデックスやベクトルの操作、メタデータフィルター、名前空間、ハイブリッド検索を扱います。

主な機能

  1. 01インデックスの作成と管理
  2. 02ベクトルの登録・検索・削除
  3. 03メタデータと名前空間による絞り込み
  4. 04密ベクトルと疎ベクトルの検索
  5. 05LangChain と LlamaIndex との連携

活用シーン

  1. 01RAG 用ベクトルの保存と検索
  2. 02ユーザーやテナントごとのデータ分離
  3. 03ベクトルとメタデータを使った検索
  4. 04Pinecone と LangChain または LlamaIndex の接続

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/kalarislabs/research-agent-skills --skill pinecone

インストール後、Claude Code で/pineconeを入力して読み込まれたか確認します。

同梱ファイルreferences/deployment.md

詳細

Pinecone - マネージドベクトルデータベース

本番環境の AI アプリケーション向けベクトルデータベースです。

Pinecone を使用する場合

次の場合に使用します:

  • マネージドのサーバーレスベクトルデータベースが必要
  • 本番環境の RAG アプリケーション
  • 自動スケーリングが必要
  • 低レイテンシが重要(<100ms)
  • インフラストラクチャを管理したくない
  • ハイブリッド検索(密ベクトル+疎ベクトル)が必要

指標:

  • フルマネージド SaaS
  • 数十億個のベクトルまで自動スケーリング
  • p95 レイテンシ <100ms
  • 稼働率 99.9% の SLA

代わりに以下を使用します:

  • Chroma:セルフホスト可能なオープンソース
  • FAISS:オフラインでの純粋な類似性検索
  • Weaviate:より多機能なセルフホスト型

クイックスタート

インストール
pip install pinecone-client
基本的な使い方
from pinecone import Pinecone, ServerlessSpec

# Initialize
pc = Pinecone(api_key="your-api-key")

# Create index
pc.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 index
index = pc.Index("my-index")

# Upsert vectors
index.upsert(vectors=[
    {"id": "vec1", "values": [0.1, 0.2, ...], "metadata": {"category": "A"}},
    {"id": "vec2", "values": [0.3, 0.4, ...], "metadata": {"category": "B"}}
])

# Query
results = index.query(
    vector=[0.1, 0.2, ...],
    top_k=5,
    include_metadata=True
)

print(results["matches"])

主な操作

インデックスを作成する
# 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"
    )
)
ベクトルをアップサートする
# Single upsert
index.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)
ベクトルをクエリする
# Basic query
results = index.query(
    vector=[0.1, 0.2, ...],
    top_k=10,
    include_metadata=True,
    include_values=False
)

# With metadata filtering
results = index.query(
    vector=[0.1, 0.2, ...],
    top_k=5,
    filter={"category": {"$eq": "tutorial"}}
)

# Namespace query
results = index.query(
    vector=[0.1, 0.2, ...],
    top_k=5,
    namespace="production"
)

# Access results
for match in results["matches"]:
    print(f"ID: {match['id']}")
    print(f"Score: {match['score']}")
    print(f"Metadata: {match['metadata']}")
メタデータのフィルタリング
# Exact match
filter = {"category": "tutorial"}

# Comparison
filter = {"price": {"$gte": 100}}  # $gt, $gte, $lt, $lte, $ne

# Logical operators
filter = {
    "$and": [
        {"category": "tutorial"},
        {"difficulty": {"$lte": 3}}
    ]
}  # Also: $or

# In operator
filter = {"tags": {"$in": ["python", "ml"]}}

名前空間

# Partition data by namespace
index.upsert(
    vectors=[{"id": "vec1", "values": [...]}],
    namespace="user-123"
)

# Query specific namespace
results = index.query(
    vector=[...],
    namespace="user-123",
    top_k=5
)

# List namespaces
stats = index.describe_index_stats()
print(stats['namespaces'])

ハイブリッド検索(密ベクトル+疎ベクトル)

# Upsert with sparse vectors
index.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 query
results = 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 との統合

from langchain_pinecone import PineconeVectorStore
from langchain_openai import OpenAIEmbeddings

# Create vector store
vectorstore = PineconeVectorStore.from_documents(
    documents=docs,
    embedding=OpenAIEmbeddings(),
    index_name="my-index"
)

# Query
results = vectorstore.similarity_search("query", k=5)

# With metadata filter
results = vectorstore.similarity_search(
    "query",
    k=5,
    filter={"category": "tutorial"}
)

# As retriever
retriever = vectorstore.as_retriever(search_kwargs={"k": 10})

LlamaIndex との統合

from llama_index.vector_stores.pinecone import PineconeVectorStore

# Connect to Pinecone
pc = Pinecone(api_key="your-key")
pinecone_index = pc.Index("my-index")

# Create vector store
vector_store = PineconeVectorStore(pinecone_index=pinecone_index)

# Use in LlamaIndex
from llama_index.core import StorageContext, VectorStoreIndex

storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)

インデックス管理

# List indices
indexes = pc.list_indexes()

# Describe index
index_info = pc.describe_index("my-index")
print(index_info)

# Get index stats
stats = index.describe_index_stats()
print(f"Total vectors: {stats['total_vector_count']}")
print(f"Namespaces: {stats['namespaces']}")

# Delete index
pc.delete_index("my-index")

ベクトルを削除する

# Delete by ID
index.delete(ids=["vec1", "vec2"])

# Delete by filter
index.delete(filter={"category": "old"})

# Delete all in namespace
index.delete(delete_all=True, namespace="test")

# Delete entire index
index.delete(delete_all=True)

ベストプラクティス

  1. サーバーレスを使用する - 自動スケーリングでコスト効率に優れています
  2. アップサートをバッチ処理する - より効率的です(1 バッチあたり 100~200 件)
  3. メタデータを追加する - フィルタリングを有効にします
  4. 名前空間を使用する - ユーザー/テナントごとにデータを分離します
  5. 使用状況を監視する - Pinecone ダッシュボードを確認します
  6. フィルターを最適化する - 頻繁にフィルタリングするフィールドにインデックスを作成します
  7. 無料枠でテストする - インデックス 1 個、ベクトル 100K 個が無料です
  8. ハイブリッド検索を使用する - より高品質な結果を得られます
  9. 適切な次元数を設定する - 埋め込みモデルに合わせます
  10. 定期的にバックアップする - 重要なデータをエクスポートします

パフォーマンス

操作レイテンシ備考
アップサート~50-100msバッチあたり
クエリ(p50)~50msインデックスのサイズによって異なります
クエリ(p95)~100msSLA の目標値
メタデータフィルター~+10-20ms追加のオーバーヘッド

料金(2025 年時点)

サーバーレス:

  • 100 万読み取り単位あたり $0.096
  • 100 万書き込み単位あたり $0.06
  • ストレージ 1 GB あたり月額 $0.06

無料枠:

  • サーバーレスインデックス 1 個
  • ベクトル 100K 個(1536 次元)
  • プロトタイピングに最適です

リソース

エージェントの作業手順

  1. 環境を確認します。 コーパス、埋め込みモデルとベクトルストアのバージョン、インデックスの保存先を確認します。
  2. 入力を明確にします。 データまたはユーザーから、形式、識別子、パラメーターを確認します。結果に影響する値は推測せず、質問してください。
  3. まず小規模に実行します。 小さなサブセットにインデックスを作成し、既知の質問と文章の組み合わせで検索をテストします。
  4. 上記の指示と参考情報を使用して、タスク全体を実行します。
  5. 結果を検証します。 ラベル付きデータセットで recall@k を測定します。回答では取得した文章のみを引用します。
  6. 報告します。 実行した内容(バージョン、コマンド、パラメーター)、確認した内容、未確定の点を記載します。
発生した場合対応
検索結果に無関係なチャンクが含まれるチャンク分割を見直し、BM25/ハイブリッド検索を追加するか、生成モデルを変更する前に再ランク付けします。
これらの指示に記載された関数、フラグ、エンドポイントがインストール済みバージョンに存在しないインストール済みバージョンのドキュメント(help()、--help、公式ドキュメント)を確認して適応し、ユーザーに伝えます。API を捏造してはいけません。
必須の入力、識別子、パラメーターが曖昧ユーザーに質問するか、実行前に前提を明示します。

整合性に関するルール

  • 結果、パラメーター、識別子、引用、統計情報を決して捏造しないでください。実行または検証できない場合は、その旨を明確に伝えてください。
  • 回答は取得したテキストに基づく必要があります。コーパスに回答が含まれていない場合は、その旨を伝えてください。
  • ここに記載されているバージョン固有の詳細は古くなっている可能性があります。インストール済みバージョンの公式ドキュメントで確認してください。
  • 費用が発生する操作、共有 GPU やクラウドのクォータを消費する操作、個人データや患者データを扱う操作、または取り消せない操作を行う前に、ユーザーに確認してください。

関連スキル

  • faiss:高密度ベクトルの効率的な類似検索とクラスタリングを実現する、Facebook のライブラリです。
  • qdrant-vector-search:RAG とセマンティック検索向けの、高性能なベクトル類似検索エンジンです。
  • chroma:AI アプリケーション向けのオープンソースの埋め込みデータベースです。

コメント