Thanks to visit codestin.com
Credit goes to docs.futureagi.com

Codestin Search App

Pinecone Java Integration with Future AGI for Vector Tracing

Trace Pinecone vector operations in Java with TracedPineconeIndex. Query, upsert, delete, and fetch with full span instrumentation.

📝
TL;DR
  • TracedPineconeIndex wraps io.pinecone.clients.Index
  • Constructor takes indexName as a required parameter (used in span attributes)
  • Query uses RETRIEVER span kind, write operations use VECTOR_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)

AttributeExample
db.systempinecone
db.vector.index_namemy-index
retriever.top_k10
embedding.dimensions1536
db.vector.results.count10
pinecone.top_score0.95
pinecone.filter{"category": "science"}
db.vector.namespacemy-namespace

Write spans (VECTOR_DB)

AttributeExample
db.systempinecone
db.vector.index_namemy-index
db.vector.namespacemy-namespace
db.vector.count1 (upsert)

Accessing the original index

Index original = traced.unwrap();
Was this page helpful?

Questions & Discussion