Skip to main content

OpenTelemetry instrumentation for Pinecone vector database

Project description

traceAI-pinecone

OpenTelemetry instrumentation for Pinecone vector database.

Installation

pip install traceAI-pinecone

Quick Start

import os
from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
from traceai_pinecone import PineconeInstrumentor
import pinecone

# Set up environment
os.environ["FI_API_KEY"] = "<your-api-key>"
os.environ["FI_SECRET_KEY"] = "<your-secret-key>"

# Register tracer
trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="my-rag-app"
)

# Instrument Pinecone
PineconeInstrumentor().instrument(tracer_provider=trace_provider)

# Use Pinecone as normal - all operations are traced!
pc = pinecone.Pinecone(api_key="your-pinecone-api-key")
index = pc.Index("my-index")

# Query vectors
results = index.query(
    vector=[0.1] * 1536,
    top_k=10,
    include_metadata=True
)

# Upsert vectors
index.upsert(
    vectors=[
        {"id": "vec1", "values": [0.1] * 1536, "metadata": {"title": "Doc 1"}},
        {"id": "vec2", "values": [0.2] * 1536, "metadata": {"title": "Doc 2"}},
    ]
)

Instrumented Operations

Operation Span Name Description
query pinecone query Vector similarity search
upsert pinecone upsert Insert or update vectors
delete pinecone delete Delete vectors by ID or filter
fetch pinecone fetch Retrieve vectors by ID
update pinecone update Update vector metadata
describe_index_stats pinecone describe_index_stats Get index statistics

Span Attributes

Common Attributes

Attribute Type Description
db.system string Always "pinecone"
db.operation.name string Operation name (query, upsert, etc.)
db.namespace string Index name
db.vector.namespace string Pinecone namespace
db.vector.index.name string Index name
db.vector.index.host string Pinecone host URL

Query Attributes

Attribute Type Description
db.vector.query.top_k int Number of results requested
db.vector.query.filter string JSON filter expression
db.vector.query.include_metadata bool Whether metadata is included
db.vector.query.include_vectors bool Whether vectors are included
db.vector.results.count int Number of results returned
db.vector.results.scores string JSON array of top scores
db.vector.results.ids string JSON array of result IDs

Upsert Attributes

Attribute Type Description
db.vector.upsert.count int Number of vectors upserted
db.vector.upsert.dimensions int Vector dimensions

Delete Attributes

Attribute Type Description
db.vector.delete.count int Number of vectors deleted
db.vector.delete.all bool Whether all vectors deleted

RAG Pipeline Example

from fi_instrumentation import register
from traceai_pinecone import PineconeInstrumentor
from traceai_openai import OpenAIInstrumentor
import pinecone
import openai

# Register tracer
trace_provider = register(project_name="rag-pipeline")

# Instrument both Pinecone and OpenAI
PineconeInstrumentor().instrument(tracer_provider=trace_provider)
OpenAIInstrumentor().instrument(tracer_provider=trace_provider)

# Initialize clients
pc = pinecone.Pinecone()
index = pc.Index("documents")
client = openai.OpenAI()

def rag_query(question: str) -> str:
    # 1. Generate embedding for question
    embedding_response = client.embeddings.create(
        model="text-embedding-3-small",
        input=question
    )
    query_embedding = embedding_response.data[0].embedding

    # 2. Search Pinecone for relevant documents
    results = index.query(
        vector=query_embedding,
        top_k=5,
        include_metadata=True
    )

    # 3. Build context from results
    context = "\n".join([
        match.metadata.get("text", "")
        for match in results.matches
    ])

    # 4. Generate answer with context
    response = client.chat.completions.create(
        model="gpt-4",
        messages=[
            {"role": "system", "content": f"Context:\n{context}"},
            {"role": "user", "content": question}
        ]
    )

    return response.choices[0].message.content

# All steps are traced with correlated spans!
answer = rag_query("What is retrieval augmented generation?")

Testing

Unit Tests

cd python/frameworks/pinecone
pip install pytest
pytest tests/ -v

Integration Tests

Requires a Pinecone account and API key:

export PINECONE_API_KEY=your-api-key
pytest tests/ -v -m integration

Example

Run the example RAG pipeline:

cd examples
python basic_rag.py

Resources

License

Apache License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

traceai_pinecone-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

traceai_pinecone-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file traceai_pinecone-0.1.0.tar.gz.

File metadata

  • Download URL: traceai_pinecone-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for traceai_pinecone-0.1.0.tar.gz
Algorithm Hash digest
SHA256 be5a7e0672529bc9594065c283226430eb8e9292631716078b7639636339a62a
MD5 e6f5ce03c3059a52574643774179bae8
BLAKE2b-256 2c1ee9b59fe504bb3d41082efc62597a88f4d53d96d3cdeb39493231a33875f7

See more details on using hashes here.

File details

Details for the file traceai_pinecone-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: traceai_pinecone-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for traceai_pinecone-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ba0b4a2bf543bc2a854d9fad77cc4ece07ab9070cd99c3840af4d4ceb8c0692
MD5 52e415e4e7d8b2e56e3a617416de2ca1
BLAKE2b-256 cee2d763fe96c14eee0dfc1fc09827b1625769f493344c21b56d8c87b6cd3df6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page