This version of the Pinecone Java SDK introduces Sparse Indexes. It also supports version 2025-01 of the Pinecone API. You can read more about versioning here.
Features
Sparse Index
Following is an example that shows how to create sparse index, upsert and query data into the index, and finally deleting the index.
import io.pinecone.proto.UpsertResponse;
import io.pinecone.unsigned_indices_model.QueryResponseWithUnsignedIndices;
import org.openapitools.db_control.client.model.DeletionProtection;
import org.openapitools.db_control.client.model.IndexModel;
import java.util.*;
public class SparseIndexExample {
public static void main(String[] args) {
// Instantiate Pinecone class
Pinecone pinecone = new Pinecone
.Builder(System.getenv("PINECONE_API_KEY"))
.withSourceTag("pinecone_test")
.build();
// Create sparse Index
String indexName = "example-index";
String cloud = "aws";
String region = "us-east-1";
String vectorType = "sparse";
Map<String, String> tags = new HashMap<>();
tags.put("env", "test");
pinecone.createSparseServelessIndex(indexName,
cloud,
region,
DeletionProtection.ENABLED,
tags,
vectorType);
// Wait for index to be ready
Thread.sleep(10000);
IndexModel indexModel = pinecone.describeIndex(indexName);
System.out.println(indexModel.getStatus());
// Upsert vectors
Index index = pinecone.getIndexConnection(indexName);
String id = "v1";
ArrayList<Long> indices = new ArrayList<>();
indices.add(1L);
indices.add(2L);
ArrayList<Float> values = new ArrayList<>();
values.add(1f);
values.add(2f);
UpsertResponse upsertResponse = index.upsert("v1", Collections.emptyList(), indices, values, null, "");
System.out.println(upsertResponse);
// Note: It can take up to 1 minute before upserted records are available to query.
// https://docs.pinecone.io/guides/indexes/sparse-indexes#upsert-sparse-vectors
// Query by vector id
QueryResponseWithUnsignedIndices queryResponse = index.queryByVectorId(1, id, true, false);
System.out.println(queryResponse);
// Delete sparse index
pinecone.deleteIndex(indexName);
}
}
Breaking Changes
Embed endpoint
parameters
now acceptsMap<String, Object>
instead ofEmbedRequestParameters
.- The response class
Embeddings
hasdense
andsparse
i.e. users will now have to usegetDenseEmbedding()
orgetSparseEmbedding()
.
For example:embeddings.getData().get(0).getValues() -> embeddings.getData().get(0).getDenseEmbedding().getValues()
.
Rerank endpoint
documents
now acceptsList<Map<String, Object>>
instead ofList<Map<String, String>>
parameters
now acceptsMap<String, Object>
instead ofMap<String, String>
What's Changed
- Add index tags by @rohanshah18 in #169
- Generate code based on 2025-01 api spec by @rohanshah18 in #171
- Update rerank example in the README after breaking changes by @rohanshah18 in #177
Full Changelog: v3.1.0...v4.0.0