Pinecone

Pinecone is a managed vector database designed for machine learning applications. It provides low-latency vector search at scale with features like namespaces, metadata filtering, and serverless deployment. Respan gives you full observability over every index operation, upsert, and query.

Create an account at platform.respan.ai and grab an API key.

Run npx @respan/cli setup to set up with your coding agent.

Setup

1

Install packages

$pip install respan-ai opentelemetry-instrumentation-pinecone pinecone
2

Set environment variables

$export PINECONE_API_KEY="YOUR_PINECONE_API_KEY"
$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

PINECONE_API_KEY is used for Pinecone requests. RESPAN_API_KEY is used to export traces to Respan.

3

Initialize and run

1from pinecone import Pinecone, ServerlessSpec
2from respan import Respan
3from opentelemetry.instrumentation.pinecone import PineconeInstrumentor
4
5respan = Respan(instrumentations=[PineconeInstrumentor()])
6
7pc = Pinecone()
8
9pc.create_index(
10 name="documents",
11 dimension=4,
12 metric="cosine",
13 spec=ServerlessSpec(cloud="aws", region="us-east-1"),
14)
15index = pc.Index("documents")
16
17index.upsert(
18 vectors=[
19 {"id": "doc1", "values": [0.1, 0.2, 0.3, 0.4], "metadata": {"topic": "observability"}},
20 {"id": "doc2", "values": [0.5, 0.6, 0.7, 0.8], "metadata": {"topic": "search"}},
21 {"id": "doc3", "values": [0.2, 0.3, 0.4, 0.5], "metadata": {"topic": "embeddings"}},
22 ],
23 namespace="articles",
24)
25
26results = index.query(
27 vector=[0.1, 0.2, 0.3, 0.4],
28 top_k=2,
29 namespace="articles",
30 include_metadata=True,
31)
32for match in results["matches"]:
33 print(f"{match['id']} (score: {match['score']:.4f}) — {match['metadata']['topic']}")
34
35respan.flush()
4

View your trace

Open the Traces page to see your Pinecone operation spans.

Configuration

ParameterTypeDefaultDescription
api_keystr | NoneNoneFalls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneFalls back to RESPAN_BASE_URL env var.
instrumentationslist[]Plugin instrumentations to activate (e.g. PineconeInstrumentor()).
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment tag (e.g. "production").

Attributes

In Respan()

1from respan import Respan
2from opentelemetry.instrumentation.pinecone import PineconeInstrumentor
3
4respan = Respan(
5 instrumentations=[PineconeInstrumentor()],
6 customer_identifier="user_123",
7 metadata={"service": "rag-api", "version": "1.0.0"},
8)

With propagate_attributes

1from respan import Respan, propagate_attributes
2from opentelemetry.instrumentation.pinecone import PineconeInstrumentor
3
4respan = Respan(instrumentations=[PineconeInstrumentor()])
5
6def search(user_id: str, query_vector):
7 with propagate_attributes(
8 customer_identifier=user_id,
9 thread_identifier="conv_abc_123",
10 metadata={"plan": "pro"},
11 ):
12 return index.query(vector=query_vector, top_k=2, namespace="articles")
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.