v0.8.0 Release
Added: Control plane operations for serverless indexes
Java SDK now supports control plane operations for serverless indexes. Users can now create, list, describe, and delete serverless indexes. Note that the PineconeIndexOperationClient has been renamed to PineconeControlPlaneClient.
Example
The following example shows how to use the create, list, describe, and delete serverless indexes.
import io.pinecone.PineconeControlPlaneClient;
import io.pinecone.helpers.RandomStringBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.*;
import java.util.Objects;
import static io.pinecone.helpers.IndexManager.isIndexReady;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class ServerlessIndexOperations {
public void createAndDelete() throws InterruptedException {
String indexName = RandomStringBuilder.build("index-name", 8);
PineconeControlPlaneClient controlPlaneClient = new PineconeControlPlaneClient("PINECONE_API_KEY");
ServerlessSpec serverlessSpec = new ServerlessSpec().cloud(ServerlessSpec.CloudEnum.AWS).region("us-west-2");
CreateIndexRequestSpec createIndexRequestSpec = new CreateIndexRequestSpec().serverless(serverlessSpec);
// Create the index
CreateIndexRequest createIndexRequest = new CreateIndexRequest()
.name(indexName)
.metric(IndexMetric.COSINE)
.dimension(10)
.spec(createIndexRequestSpec);
controlPlaneClient.createIndex(createIndexRequest);
// Wait until index is ready
Thread.sleep(3500);
// Describe the index
IndexModel indexModel = controlPlaneClient.describeIndex(indexName);
assertNotNull(indexModel);
assertEquals(10, indexModel.getDimension());
assertEquals(indexName, indexModel.getName());
assertEquals(IndexMetric.COSINE, indexModel.getMetric());
// List the index
IndexList indexList = controlPlaneClient.listIndexes();
assert !Objects.requireNonNull(indexList.getIndexes()).isEmpty();
// Delete the index
controlPlaneClient.deleteIndex(indexName);
}
}Updated: Control plane operations for pod indexes
We have updated the api's for create, configure, list, describe, and delete operations for pod indexes.
Example
The following example how to create, list, describe, and delete pod indexes.
import io.pinecone.PineconeControlPlaneClient;
import io.pinecone.helpers.RandomStringBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.*;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class PodIndexOperations {
public void createAndDelete() throws InterruptedException {
String apiKey = System.getenv("PINECONE_API_KEY");
String environment = System.getenv("PINECONE_ENVIRONMENT");
String indexName = RandomStringBuilder.build("index-name", 8);
PineconeControlPlaneClient controlPlaneClient = new PineconeControlPlaneClient(apiKey);
CreateIndexRequestSpecPod podSpec = new CreateIndexRequestSpecPod().environment(environment).podType("p1.x1");
CreateIndexRequestSpec createIndexRequestSpec = new CreateIndexRequestSpec().pod(podSpec);
// Create the index
CreateIndexRequest createIndexRequest = new CreateIndexRequest()
.name(indexName)
.metric(IndexMetric.COSINE)
.dimension(10)
.spec(createIndexRequestSpec);
controlPlaneClient.createIndex(createIndexRequest);
// Wait until index is ready
Thread.sleep(3500);
// Describe the index
IndexModel indexModel = controlPlaneClient.describeIndex(indexName);
assertNotNull(indexModel);
assertEquals(10, indexModel.getDimension());
assertEquals(indexName, indexModel.getName());
assertEquals(IndexMetric.COSINE, indexModel.getMetric());
// List the index
IndexList indexList = controlPlaneClient.listIndexes();
assert !Objects.requireNonNull(indexList.getIndexes()).isEmpty();
// Delete the index
controlPlaneClient.deleteIndex(indexName);
}
}The following example shows how to scale up and down a pod index using configure index operation.
public class PodIndexOperations {
public void scaleUpAndDownPodIndex() {
try {
String apiKey = System.getenv("PINECONE_API_KEY");
String environment = System.getenv("PINECONE_ENVIRONMENT");
String indexName = RandomStringBuilder.build("index-name", 8);
PineconeControlPlaneClient controlPlaneClient = new PineconeControlPlaneClient(apiKey);
// Scale up for the test
ConfigureIndexRequestSpecPod pod = new ConfigureIndexRequestSpecPod().replicas(3);
ConfigureIndexRequestSpec spec = new ConfigureIndexRequestSpec().pod(pod);
ConfigureIndexRequest configureIndexRequest = new ConfigureIndexRequest().spec(spec);
controlPlaneClient.configureIndex(indexName, configureIndexRequest);
// Verify the scaled up replicas
PodSpec podSpec = controlPlaneClient.describeIndex(indexName).getSpec().getPod();
assert (podSpec != null);
assertEquals(podSpec.getReplicas(), 3);
// Scaling down
pod = new ConfigureIndexRequestSpecPod().replicas(1);
spec = new ConfigureIndexRequestSpec().pod(pod);
configureIndexRequest = new ConfigureIndexRequest().spec(spec);
controlPlaneClient.configureIndex(indexName, configureIndexRequest);
// Verify replicas were scaled down
podSpec = controlPlaneClient.describeIndex(indexName).getSpec().getPod();
assert (podSpec != null);
assertEquals(podSpec.getReplicas(), 1);
} catch (Exception exception) {
throw new PineconeException("Test failed: " + exception.getLocalizedMessage());
}
}
}Added: Support for collections in Java SDK
We have added the support to create, list, describe, and delete the collections in java sdk.
Example
The following example shows how to create, list, describe, and delete collections:
public class Collections {
public void testIndexToCollectionHappyPath() throws InterruptedException {
String apiKey = System.getenv("PINECONE_API_KEY");
String environment = System.getenv("PINECONE_ENVIRONMENT");
PineconeControlPlaneClient controlPlaneClient = new PineconeControlPlaneClient(apiKey);
String indexName = RandomStringBuilder.build("collection-test", 8);
ArrayList<String> indexes = new ArrayList<>();
ArrayList<String> collections = new ArrayList<>();
IndexMetric indexMetric = IndexMetric.COSINE;
List<String> upsertIds = Arrays.asList("v1", "v2", "v3");
String namespace = RandomStringBuilder.build("ns", 8);
int dimension = 4;
String collectionName = RandomStringBuilder.build("collection-test", 8);
// Create collection from index
CreateCollectionRequest createCollectionRequest = new CreateCollectionRequest().name(collectionName).source(indexName);
CollectionModel collection = controlPlaneClient.createCollection(createCollectionRequest);
assertEquals(collection.getStatus(), CollectionModel.StatusEnum.INITIALIZING);
// Wait until collection is ready
Thread.sleep(120000);
// List collections
List<CollectionModel> collectionList = controlPlaneClient.listCollections().getCollections();
// Verify collections is listed
boolean collectionFound = false;
if (collectionList != null && !collectionList.isEmpty()) {
for (CollectionModel col : collectionList) {
if (col.getName().equals(collectionName)) {
collectionFound = true;
break;
}
}
}
if (!collectionFound) {
fail("Collection " + collectionName + " was not found when listing collections");
}
// Describe collections
collection = controlPlaneClient.describeCollection(collectionName);
assertEquals(collection.getStatus(), CollectionModel.StatusEnum.READY);
assertEquals(collection.getDimension(), dimension);
assertEquals(collection.getVectorCount(), 3);
assertNotEquals(collection.getVectorCount(), null);
assertTrue(collection.getSize() > 0);
// Delete collections
controlPlaneClient.deleteCollection(collectionName);
collections.remove(collectionName);
Thread.sleep(2500);
}
}What's Changed
- Add global control plane code by @rohanshah18 in #59
- Update index operations by @rohanshah18 in #62
- Update configure index test and clean up control plane client by @rohanshah18 in #63
- Add collections operations to
PineconeControlPlaneClientwith integration tests by @austin-denoble in #65 - Refactor dataplane by @rohanshah18 in #66
- Revert "Refactor dataplane " by @rohanshah18 in #67
- Update changelogs, sdk version, and user-agent for v0.8.0 release by @rohanshah18 in #68
New Contributors
- @austin-denoble made their first contribution in #65
Full Changelog: v0.7.4...v0.8.0