Skip to main content
  1. Sign up — Create an account at platform.respan.ai
  2. Create an API key — Generate one on the API keys page
  3. Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page
Add the Docs MCP to your AI coding tool to get help building with Respan. No API key needed.
{
  "mcpServers": {
    "respan-docs": {
      "url": "https://docs.respan.ai/mcp"
    }
  }
}

What is Pinecone?

Pinecone is a managed vector database built for high-performance similarity search at scale. Respan auto-instruments Pinecone operations so every upsert, query, and delete is captured as a traced span.

Setup

1

Install packages

pip install respan-ai opentelemetry-instrumentation-pinecone pinecone python-dotenv
2

Set environment variables

export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export PINECONE_API_KEY="YOUR_PINECONE_API_KEY"
3

Initialize and run

import os
from dotenv import load_dotenv

load_dotenv()

from pinecone import Pinecone, ServerlessSpec
from respan import Respan

# Initialize Respan with auto-instrumentation
respan = Respan(is_auto_instrument=True)

# Create a Pinecone client
pc = Pinecone(api_key=os.getenv("PINECONE_API_KEY"))

# Create an index
pc.create_index(
    name="respan-demo",
    dimension=1536,
    metric="cosine",
    spec=ServerlessSpec(cloud="aws", region="us-east-1"),
)

index = pc.Index("respan-demo")

# Upsert vectors
index.upsert(
    vectors=[
        {"id": "vec_1", "values": [0.1] * 1536, "metadata": {"genre": "drama"}},
        {"id": "vec_2", "values": [0.2] * 1536, "metadata": {"genre": "comedy"}},
    ]
)

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

respan.flush()
4

View your trace

Open the Traces page to see your Pinecone spans including upsert and query operations.

Configuration

ParameterTypeDefaultDescription
api_keystr | NoneNoneFalls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneFalls back to RESPAN_BASE_URL env var.
is_auto_instrumentbool | NoneFalseAuto-discover installed instrumentors. Required for Traceloop instrumentors.
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment tag (e.g. "production").

Attributes

Attach customer identifiers, thread IDs, and metadata to spans.

In Respan()

Set defaults at initialization — these apply to all spans.
from respan import Respan

respan = Respan(
    is_auto_instrument=True,
    customer_identifier="user_123",
    metadata={"service": "search-api", "version": "1.0.0"},
)

With propagate_attributes

Override per-request using a context manager.
from respan import Respan, propagate_attributes

respan = Respan(is_auto_instrument=True)

with propagate_attributes(
    customer_identifier="user_456",
    thread_identifier="session_abc",
    metadata={"plan": "enterprise"},
):
    results = index.query(vector=[0.1] * 1536, top_k=5, include_metadata=True)
    print(results)
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.

Examples

Create index

from pinecone import Pinecone, ServerlessSpec

pc = Pinecone(api_key=os.getenv("PINECONE_API_KEY"))

pc.create_index(
    name="product-embeddings",
    dimension=1536,
    metric="cosine",
    spec=ServerlessSpec(cloud="aws", region="us-east-1"),
)

Upsert vectors

index = pc.Index("product-embeddings")

index.upsert(
    vectors=[
        {
            "id": "product_001",
            "values": [0.12, 0.34, 0.56] + [0.0] * 1533,  # 1536-dim vector
            "metadata": {"category": "electronics", "price": 299.99},
        },
        {
            "id": "product_002",
            "values": [0.78, 0.91, 0.23] + [0.0] * 1533,
            "metadata": {"category": "clothing", "price": 49.99},
        },
    ]
)

Query

results = index.query(
    vector=[0.12, 0.34, 0.56] + [0.0] * 1533,
    top_k=5,
    include_metadata=True,
    filter={"category": {"$eq": "electronics"}},
)

for match in results["matches"]:
    print(f"{match['id']}: score={match['score']:.4f}, metadata={match['metadata']}")

Delete

# Delete by IDs
index.delete(ids=["product_001", "product_002"])

# Delete by filter
index.delete(filter={"category": {"$eq": "electronics"}})