Skip to content

v4.0.0 Release

Latest
Compare
Choose a tag to compare
@rohanshah18 rohanshah18 released this 03 Feb 19:47
6ed8d46

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 accepts Map<String, Object> instead of EmbedRequestParameters.
  • The response class Embeddings has dense and sparse i.e. users will now have to use getDenseEmbedding() or getSparseEmbedding().
    For example: embeddings.getData().get(0).getValues() -> embeddings.getData().get(0).getDenseEmbedding().getValues().

Rerank endpoint

  • documents now accepts List<Map<String, Object>> instead of List<Map<String, String>>
  • parameters now accepts Map<String, Object> instead of Map<String, String>

What's Changed

Full Changelog: v3.1.0...v4.0.0