Skip to content

Commit

Permalink
Merge branch 'main' into async-stub
Browse files Browse the repository at this point in the history
Merge integration test fixes into async-stub branch
  • Loading branch information
rohanshah18 committed Oct 6, 2023
2 parents 287ad6c + be78899 commit 73c3739
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
51 changes: 33 additions & 18 deletions src/integration/java/io/pinecone/PineconeClientLiveIntegTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PineconeClientLiveIntegTest {
private PineconeIndexOperationClient controlPlaneClient;

@BeforeEach
public void setUp() throws Exception {
public void setUp() {
PineconeClientConfig config = new PineconeClientConfig()
.withApiKey(System.getenv("PINECONE_API_KEY"))
.withEnvironment(System.getenv("PINECONE_ENVIRONMENT"))
Expand All @@ -54,7 +54,7 @@ public void sanity() throws Exception {
new PineconeConnectionConfig()
.withConnectionUrl("https://" + host));

String ns = RandomStringBuilder.build("ns", 8);
String namespace = RandomStringBuilder.build("ns", 8);

// upsert
float[][] upsertData = {{1.0F, 2.0F, 3.0F}, {4.0F, 5.0F, 6.0F}, {7.0F, 8.0F, 9.0F}};
Expand All @@ -73,20 +73,19 @@ public void sanity() throws Exception {

UpsertRequest request = UpsertRequest.newBuilder()
.addAllVectors(upsertVectors)
.setNamespace(ns)
.setNamespace(namespace)
.build();

UpsertResponse upsertResponse = conn.getBlockingStub().upsert(request);
logger.info("Put " + upsertResponse.getUpsertedCount() + " vectors into the index");
assert (upsertResponse.getUpsertedCount() == 3);

// hybrid upsert

List<String> hybridsIds = Arrays.asList("v4","v5","v6");
List<String> hybridsIds = Arrays.asList("v4", "v5", "v6");
List<Vector> hybridVectors = new ArrayList<>();
List<Integer> sparseIndices = Arrays.asList(0,1,2);
List<Float> sparseValues = Arrays.asList(0.11f,0.22f,0.33f);
for (int i=0; i< hybridsIds.size(); i++) {
List<Integer> sparseIndices = Arrays.asList(0, 1, 2);
List<Float> sparseValues = Arrays.asList(0.11f, 0.22f, 0.33f);
for (int i = 0; i < hybridsIds.size(); i++) {
hybridVectors.add(
Vector.newBuilder()
.addAllValues(Floats.asList(upsertData[i]))
Expand All @@ -99,17 +98,27 @@ public void sanity() throws Exception {

UpsertRequest hybridRequest = UpsertRequest.newBuilder()
.addAllVectors(hybridVectors)
.setNamespace(ns)
.setNamespace(namespace)
.build();
UpsertResponse hybridResponse = conn.getBlockingStub().upsert(hybridRequest);
logger.info("Put " + hybridResponse.getUpsertedCount() + " vectors into the index");
assert (hybridResponse.getUpsertedCount() == 3);

// fetch
List<String> ids = Arrays.asList("v1","v2");
FetchRequest fetchRequest = FetchRequest.newBuilder().addAllIds(ids).setNamespace(ns).build();
List<String> ids = Arrays.asList("v1", "v2");
FetchRequest fetchRequest = FetchRequest.newBuilder().addAllIds(ids).setNamespace(namespace).build();
FetchResponse fetchResponse = conn.getBlockingStub().fetch(fetchRequest);
assert(fetchResponse.containsVectors("v1"));
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
UpdateRequest updateRequest = UpdateRequest.newBuilder()
.setId("v1")
.setNamespace(namespace)
.addAllValues(Floats.asList(10F, 11F, 12F))
.build();
conn.getBlockingStub().update(updateRequest);
fetchRequest = FetchRequest.newBuilder().addIds("v1").setNamespace(namespace).build();
conn.getBlockingStub().fetch(fetchRequest);

// DEPRECATED: batch queries
float[] rawVector = {1.0F, 2.0F, 3.0F};
Expand All @@ -123,12 +132,12 @@ public void sanity() throws Exception {
.build()))
.build())
.build())
.setNamespace(ns)
.setNamespace(namespace)
.build();

QueryRequest batchQueryRequest = QueryRequest.newBuilder()
.addQueries(queryVector)
.setNamespace(ns)
.setNamespace(namespace)
.setTopK(2)
.setIncludeMetadata(true)
.build();
Expand All @@ -141,7 +150,7 @@ public void sanity() throws Exception {
Iterable<Float> iterable = Arrays.asList(1.0F, 2.0F, 3.0F);
QueryRequest queryRequest = QueryRequest.newBuilder()
.addAllVector(iterable)
.setNamespace(ns)
.setNamespace(namespace)
.setTopK(2)
.setIncludeMetadata(true)
.build();
Expand All @@ -155,7 +164,7 @@ public void sanity() throws Exception {
// Query by id example
QueryRequest queryByIdRequest = QueryRequest.newBuilder()
.setId("v2")
.setNamespace(ns)
.setNamespace(namespace)
.setTopK(2)
.setIncludeMetadata(true)
.build();
Expand All @@ -168,19 +177,25 @@ public void sanity() throws Exception {
// Delete
String[] idsToDelete = {"v2"};
DeleteRequest deleteRequest = DeleteRequest.newBuilder()
.setNamespace(ns)
.setNamespace(namespace)
.addAllIds(Arrays.asList(idsToDelete))
.setDeleteAll(false)
.build();

conn.getBlockingStub().delete(deleteRequest);
fetchRequest = FetchRequest.newBuilder().addAllIds(ids).setNamespace(namespace).build();
fetchResponse = conn.getBlockingStub().fetch(fetchRequest);
assert (fetchResponse.getVectorsCount() == ids.size() - 1);

// Clear out the test
DeleteRequest deleteAllRequest = DeleteRequest.newBuilder()
.setNamespace(ns)
.setNamespace(namespace)
.setDeleteAll(true)
.build();

conn.getBlockingStub().delete(deleteAllRequest);
fetchRequest = FetchRequest.newBuilder().addAllIds(ids).setNamespace(namespace).build();
fetchResponse = conn.getBlockingStub().fetch(fetchRequest);
assert (fetchResponse.getVectorsCount() == 0);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package io.pinecone.integration;
package io.pinecone;

import io.pinecone.PineconeClientConfig;
import io.pinecone.PineconeIndexOperationClient;
import io.pinecone.helpers.RandomStringBuilder;
import io.pinecone.model.CreateIndexRequest;
import io.pinecone.model.IndexMeta;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Random;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -18,7 +15,7 @@ public class PineconeIndexOperationsClientIntegrationTest {
private PineconeIndexOperationClient pinecone;

@BeforeEach
public void setUp() throws Exception {
public void setUp() {
PineconeClientConfig config = new PineconeClientConfig()
.withApiKey(System.getenv("PINECONE_API_KEY"))
.withEnvironment(System.getenv("PINECONE_ENVIRONMENT"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public static String build(String prefix, int len) {
int index = (int) (rnd.nextFloat() * alphabet.length());
name.append(alphabet.charAt(index));
}
return prefix + "-" + name.toString();
return prefix + "-" + name;
}
}

0 comments on commit 73c3739

Please sign in to comment.