Pinecone (Java)
Trace Pinecone vector operations in Java with TracedPineconeIndex. Query, upsert, delete, and fetch with full span instrumentation.
📝
TL;DR
TracedPineconeIndexwrapsio.pinecone.clients.Index- Constructor takes
indexNameas a required parameter (used in span attributes) - Query uses
RETRIEVERspan kind, write operations useVECTOR_DB - Supports namespaces and metadata filters
Prerequisites
Complete the Java SDK setup first.
Installation
<dependency>
<groupId>com.github.future-agi.traceAI</groupId>
<artifactId>traceai-java-pinecone</artifactId>
<version>main-SNAPSHOT</version>
</dependency>implementation 'com.github.future-agi.traceAI:traceai-java-pinecone:main-SNAPSHOT' You also need the Pinecone Java SDK:
<dependency>
<groupId>io.pinecone</groupId>
<artifactId>pinecone-client</artifactId>
<version>5.0.0</version>
</dependency>implementation 'io.pinecone:pinecone-client:5.0.0' Wrap the index
Note: the constructor requires indexName as a parameter. This is different from most other wrappers - Pinecone doesn’t expose the index name from the Index object, so you need to provide it.
import ai.traceai.TraceAI;
import ai.traceai.pinecone.TracedPineconeIndex;
import io.pinecone.clients.Pinecone;
import io.pinecone.clients.Index;
TraceAI.initFromEnvironment();
Pinecone pinecone = new Pinecone.Builder(System.getenv("PINECONE_API_KEY")).build();
Index index = pinecone.getIndexConnection("my-index");
// indexName is required in the constructor
TracedPineconeIndex traced = new TracedPineconeIndex(index, "my-index");
Query
import java.util.List;
List<Float> queryVector = List.of(0.1f, 0.2f, 0.3f); // your embedding
var results = traced.query(queryVector, 10);
for (var match : results.getMatchesList()) {
System.out.println("ID: " + match.getId() + ", Score: " + match.getScore());
}
With namespace and filter:
import java.util.Map;
var results = traced.query(
queryVector,
10,
"my-namespace",
Map.of("category", "science") // metadata filter
);
Span created: “Pinecone Query” with kind RETRIEVER
Upsert
import io.pinecone.unsigned_indices_model.VectorWithUnsignedIndices;
import java.util.List;
List<VectorWithUnsignedIndices> vectors = List.of(
VectorWithUnsignedIndices.newBuilder()
.setId("vec-1")
.addAllValues(List.of(0.1f, 0.2f, 0.3f))
.build()
);
traced.upsert(vectors, "my-namespace");
Span created: “Pinecone Upsert” with kind VECTOR_DB
Delete
traced.deleteByIds(List.of("vec-1", "vec-2"), "my-namespace");
Span created: “Pinecone Delete” with kind VECTOR_DB
Fetch
var fetched = traced.fetch(List.of("vec-1"), "my-namespace");
Span created: “Pinecone Fetch” with kind VECTOR_DB
What gets captured
Query spans (RETRIEVER)
| Attribute | Example |
|---|---|
db.system | pinecone |
db.vector.index_name | my-index |
retriever.top_k | 10 |
embedding.dimensions | 1536 |
db.vector.results.count | 10 |
pinecone.top_score | 0.95 |
pinecone.filter | {"category": "science"} |
db.vector.namespace | my-namespace |
Write spans (VECTOR_DB)
| Attribute | Example |
|---|---|
db.system | pinecone |
db.vector.index_name | my-index |
db.vector.namespace | my-namespace |
db.vector.count | 1 (upsert) |
Accessing the original index
Index original = traced.unwrap(); Was this page helpful?