Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path for gcp-starter env, add assert with retry mechanism, and add deprecation warning in vector_service.proto #57

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

[comment]: <> (When bumping [pc:VERSION_LATEST_RELEASE] create a new entry below)
### Unreleased version
### v0.7.3
- Add assert with retry mechanism
- Add deprecation warning for queries parameter
- Fix path for create and list indexes calls for gcp-stater

### v0.7.2
- Fix extraction of SDK version

Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ Maven:
<dependency>
<groupId>io.pinecone</groupId>
<artifactId>pinecone-client</artifactId>
<version>0.7.2</version>
<version>0.7.3</version>
</dependency>
```

[comment]: <> (^ [pc:VERSION_LATEST_RELEASE])

Gradle:
```
implementation "io.pinecone:pinecone-client:0.7.2"
implementation "io.pinecone:pinecone-client:0.7.3"
```

[comment]: <> (^ [pc:VERSION_LATEST_RELEASE])

Alternatively, you can use our standalone uberjar [pinecone-client-0.7.2-all.jar](https://repo1.maven.org/maven2/io/pinecone/pinecone-client/0.7.2/pinecone-client-0.7.2-all.jar), which bundles the pinecone client and all dependencies together inside a single jar. You can include this on your classpath like any 3rd party JAR without having to obtain the *pinecone-client* dependencies separately.
Alternatively, you can use our standalone uberjar [pinecone-client-0.7.3-all.jar](https://repo1.maven.org/maven2/io/pinecone/pinecone-client/0.7.3/pinecone-client-0.7.3-all.jar), which bundles the pinecone client and all dependencies together inside a single jar. You can include this on your classpath like any 3rd party JAR without having to obtain the *pinecone-client* dependencies separately.

[comment]: <> (^ [pc:VERSION_LATEST_RELEASE])


## Examples

- The data and control plane operation examples can be found in `io/pinecone/integration` folder.
- The data and control plane operation examples can be found in `io/pinecone/integration` folder.

## Deprecation Warning
`queries` parameter of `VectorRequest` has been deprecated. Please use `vector` parameter of `VectorRequest` and the associated methods.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static void main(String[] cliArgs) {

PineconeClient pineconeClient = new PineconeClient(configuration);


PineconeConnectionConfig connectionConfig = new PineconeConnectionConfig()
.withIndexName(args.indexName);

Expand All @@ -53,7 +52,6 @@ public static void main(String[] cliArgs) {
.addAllValues(Floats.asList(5F, 3F, 1F))
.build();

// Deprecated: use addValue() or addAllValues() instead of addVector() and addAllVectors() respectively
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
UpsertRequest upsertRequest = UpsertRequest.newBuilder()
.addVectors(v1)
.addVectors(v2)
Expand All @@ -68,17 +66,17 @@ public static void main(String[] cliArgs) {
System.out.println("Got upsert response:");
System.out.println(upsertResponse);


QueryVector queryVector = QueryVector
.newBuilder()
.addAllValues(Floats.asList(1F, 2F, 2F))
.setTopK(args.topK)
.setNamespace(args.namespace)
.build();

// Deprecated: queries param on QueryRequest is deprecated, use vector parameter and the associated methods
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
QueryRequest queryRequest = QueryRequest
.newBuilder()
.addQueries(queryVector)
.addQueries(queryVector) // use addVector() or addAllVector() as shown in PineconeLiveIntegrationTest.java
.setTopK(args.topK)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ public static void main(String[] cliArgs) throws InterruptedException {
}

try {
// Deprecated: use addValue() or addAllValues() instead of addVector()
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
// and addAllVectors() respectively
UpsertRequest upsertRequest = UpsertRequest.newBuilder()
.addAllVectors(vectors)
.build();
Expand Down Expand Up @@ -197,7 +195,11 @@ public static void main(String[] cliArgs) throws InterruptedException {
.setTopK(args.topK)
.build());
}
QueryRequest queryRequest = QueryRequest.newBuilder().addAllQueries(queryVectors)

// Deprecated: queries param on QueryRequest is deprecated, use vector parameter and the associated methods
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
QueryRequest queryRequest = QueryRequest
.newBuilder()
.addAllQueries(queryVectors) // use addVector() or addAllVector() as shown in PineconeLiveIntegrationTest.java
.setTopK(args.topK)
.build();
QueryResponse response = conn.getBlockingStub().query(queryRequest);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pineconeClientVersion = 0.7.2
pineconeClientVersion = 0.7.3
8 changes: 6 additions & 2 deletions src/integration/java/io/pinecone/helpers/IndexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import java.util.List;

public class IndexManager {
private static PineconeClientConfig config;
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved

public static PineconeConnection createIndexIfNotExistsDataPlane(int dimension) throws IOException, InterruptedException {
PineconeClientConfig config = new PineconeClientConfig()
config = new PineconeClientConfig()
.withApiKey(System.getenv("PINECONE_API_KEY"))
.withEnvironment(System.getenv("PINECONE_ENVIRONMENT"));
PineconeIndexOperationClient controlPlaneClient = new PineconeIndexOperationClient(config);
Expand All @@ -18,6 +20,8 @@ public static PineconeConnection createIndexIfNotExistsDataPlane(int dimension)
String indexName = findIndexWithDimensionAndPodType(indexList, dimension, controlPlaneClient);
if(indexName.isEmpty()) indexName = createNewIndex(dimension, controlPlaneClient);

// Do not proceed until the newly created index is ready
isIndexReady(indexName, controlPlaneClient);
PineconeClient dataPlaneClient = new PineconeClient(config);
IndexMeta indexMeta = controlPlaneClient.describeIndex(indexName);
String host = indexMeta.getStatus().getHost();
Expand All @@ -41,7 +45,7 @@ private static String findIndexWithDimensionAndPodType(List<String> indexList, i
while (i < indexList.size()) {
IndexMeta indexMeta = isIndexReady(indexList.get(i), controlPlaneClient);
if (indexMeta.getDatabase().getDimension() == dimension
&& indexMeta.getDatabase().getPodType().equals("p1.x1")) {
&& (indexMeta.getDatabase().getPodType().equals("p1.x1") || config.getEnvironment().equals("gcp-starter"))) {
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
return indexList.get(i);
}
i++;
Expand Down
29 changes: 29 additions & 0 deletions src/integration/java/io/pinecone/helpers/RetryAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.pinecone.helpers;

import java.util.concurrent.ExecutionException;

public class RetryAssert {
private static final int maxRetry = 4;
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
private static int delay = 1500;

public static void assertWithRetry(AssertionRunnable assertionRunnable) throws InterruptedException {
int retryCount = 0;
boolean success = false;

while (retryCount < maxRetry && !success) {
try {
assertionRunnable.run();
success = true;
} catch (AssertionError | ExecutionException e) {
retryCount++;
delay*=2;
Thread.sleep(delay);
}
}
}

@FunctionalInterface
public interface AssertionRunnable {
void run() throws AssertionError, ExecutionException, InterruptedException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.util.List;

import static io.pinecone.helpers.IndexManager.isIndexReady;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

Expand All @@ -37,6 +38,8 @@ public void createAndDelete() throws IOException, InterruptedException {
.withMetric("euclidean");
pinecone.createIndex(request);

isIndexReady(indexName, pinecone);
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved

// Get the index description
IndexMeta indexMeta = pinecone.describeIndex(indexName);
assertNotNull(indexMeta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.pinecone.PineconeConnection;
import io.pinecone.helpers.RandomStringBuilder;
import io.pinecone.proto.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand All @@ -17,6 +18,7 @@
import java.util.List;

import static io.pinecone.helpers.IndexManager.createIndexIfNotExistsDataPlane;
import static io.pinecone.helpers.RetryAssert.assertWithRetry;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
Expand All @@ -33,7 +35,7 @@ public static void defineConfig() throws IOException, InterruptedException {
}

@Test
public void sanity() {
public void sanity() throws InterruptedException {
String namespace = RandomStringBuilder.build("ns", 8);

// upsert
Expand Down Expand Up @@ -86,22 +88,25 @@ public void sanity() {

// fetch
List<String> ids = Arrays.asList("v1", "v2");
FetchRequest fetchRequest = FetchRequest.newBuilder().addAllIds(ids).setNamespace(namespace).build();
FetchResponse fetchResponse = blockingStub.fetch(fetchRequest);
assert (fetchResponse.containsVectors("v1"));
FetchRequest fetchRequest1 = FetchRequest.newBuilder().addAllIds(ids).setNamespace(namespace).build();
assertWithRetry(() -> {
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
FetchResponse fetchResponse = blockingStub.fetch(fetchRequest1);
assert (fetchResponse.containsVectors("v1"));
});

// Updates vector v1's values to 10.0, 11.0, and 12.0 from 1.0, 2.0, and 3.0
List<Float> updateValueList = Floats.asList(10F, 11F, 12F);
UpdateRequest updateRequest = UpdateRequest.newBuilder()
.setId("v1")
.setNamespace(namespace)
.addAllValues(Floats.asList(10F, 11F, 12F))
.addAllValues(updateValueList)
.build();
blockingStub.update(updateRequest);
fetchRequest = FetchRequest.newBuilder().addIds("v1").setNamespace(namespace).build();
blockingStub.fetch(fetchRequest);

// DEPRECATED: all methods related to queries in QueryVector
// Use methods related to Vector. Example: addVector, addAllVector, etc.
// DEPRECATED: queries parameter of QueryRequest has been deprecated
// Use vector parameter and the associated methods.
// Below commented example shows addQueries() which is deprecated
/*
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
float[] rawVector = {1.0F, 2.0F, 3.0F};
QueryVector queryVector = QueryVector.newBuilder()
.addAllValues(Floats.asList(rawVector))
Expand All @@ -117,45 +122,43 @@ public void sanity() {
.build();

QueryRequest batchQueryRequest = QueryRequest.newBuilder()
// DEPRECATED: addQueries() and addAllQueries()
// Please use addVector() or addAllVector() instead
.addQueries(queryVector)
.addQueries(queryVector) // Deprecated
.setNamespace(namespace)
.setTopK(2)
.setIncludeMetadata(true)
.build();
*/

QueryResponse queryResponse = blockingStub.query(batchQueryRequest);
assertThat(queryResponse, notNullValue());
assertThat(queryResponse.getResultsList(), notNullValue());
assertThat(queryResponse.getResultsCount(), equalTo(1));

Iterable<Float> iterable = Arrays.asList(1.0F, 2.0F, 3.0F);
// Below example shows usage of addAllVector() which is associated with vector parameter of QueryRequest.
Iterable<Float> iterableVector = Arrays.asList(1.0F, 2.0F, 3.0F);
QueryRequest queryRequest = QueryRequest.newBuilder()
.addAllVector(iterable)
.addAllVector(iterableVector)
.setNamespace(namespace)
.setTopK(2)
.setIncludeMetadata(true)
.build();

// When querying using a single vector, we get matches instead of results
queryResponse = blockingStub.query(queryRequest);
assertThat(queryResponse, notNullValue());
assertThat(queryResponse.getMatchesList(), notNullValue());
assertThat(queryResponse.getMatchesCount(), equalTo(2));
assertWithRetry(() -> {
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
QueryResponse queryResponse = blockingStub.query(queryRequest);
Assertions.assertEquals(queryResponse.getMatchesCount(), 2);
});

// Query by id example
QueryRequest queryByIdRequest = QueryRequest.newBuilder()
.setId("v2")
.setId("v1")
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
.setNamespace(namespace)
.setTopK(2)
.setTopK(1)
.setIncludeMetadata(true)
.setIncludeValues(true)
.build();

queryResponse = blockingStub.query(queryByIdRequest);
assertThat(queryResponse, notNullValue());
assertThat(queryResponse.getMatchesList(), notNullValue());
assertThat(queryResponse.getMatchesCount(), equalTo(2));
assertWithRetry(() -> {
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
QueryResponse queryResponse = blockingStub.query(queryByIdRequest);
assertThat(queryResponse, notNullValue());
assertThat(queryResponse.getMatchesCount(), equalTo(1));
assert (queryResponse.getMatches(0).getValuesList().containsAll(updateValueList));
});

// Delete
String[] idsToDelete = {"v2"};
Expand All @@ -166,9 +169,11 @@ public void sanity() {
.build();

blockingStub.delete(deleteRequest);
fetchRequest = FetchRequest.newBuilder().addAllIds(ids).setNamespace(namespace).build();
fetchResponse = blockingStub.fetch(fetchRequest);
assert (fetchResponse.getVectorsCount() == ids.size() - 1);
FetchRequest fetchRequest2 = FetchRequest.newBuilder().addAllIds(ids).setNamespace(namespace).build();
assertWithRetry(() -> {
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
FetchResponse fetchResponse = blockingStub.fetch(fetchRequest2);
Assertions.assertEquals(fetchResponse.getVectorsCount(), ids.size() - 1);
});

// Clear out the test
DeleteRequest deleteAllRequest = DeleteRequest.newBuilder()
Expand All @@ -177,8 +182,10 @@ public void sanity() {
.build();

blockingStub.delete(deleteAllRequest);
fetchRequest = FetchRequest.newBuilder().addAllIds(ids).setNamespace(namespace).build();
fetchResponse = blockingStub.fetch(fetchRequest);
assert (fetchResponse.getVectorsCount() == 0);
FetchRequest fetchRequest3 = FetchRequest.newBuilder().addAllIds(ids).setNamespace(namespace).build();
assertWithRetry(() -> {
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved
FetchResponse fetchResponse = blockingStub.fetch(fetchRequest3);
Assertions.assertEquals(fetchResponse.getVectorsCount(), 0);
});
}
}
Loading