Skip to content
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
63 changes: 33 additions & 30 deletions src/integration/java/io/pinecone/helpers/IndexManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.pinecone.helpers;

import io.pinecone.clients.PineconeControlPlaneClient;
import io.pinecone.clients.Index;
import io.pinecone.clients.Pinecone;
import io.pinecone.configs.PineconeConfig;
import io.pinecone.configs.PineconeConnection;
import io.pinecone.exceptions.PineconeException;
Expand All @@ -20,35 +21,37 @@ public class IndexManager {

public static PineconeConnection createIndexIfNotExistsDataPlane(int dimension, String indexType) throws IOException, InterruptedException {
String apiKey = System.getenv("PINECONE_API_KEY");
PineconeControlPlaneClient controlPlaneClient = new PineconeControlPlaneClient(apiKey);
IndexList indexList = controlPlaneClient.listIndexes();
Pinecone pinecone = new Pinecone(apiKey);

String indexName = findIndexWithDimensionAndType(indexList, dimension, controlPlaneClient, indexType);
if (indexName.isEmpty()) indexName = createNewIndex(controlPlaneClient, indexType, dimension);
String indexName = findIndexWithDimensionAndType(pinecone, dimension, indexType);
if (indexName.isEmpty()) indexName = createNewIndex(pinecone, dimension, indexType);

// Do not proceed until the newly created index is ready
isIndexReady(indexName, controlPlaneClient);
isIndexReady(indexName, pinecone);

// Adding to test PineconeConnection(pineconeConfig, host) constructor
String host = controlPlaneClient.describeIndex(indexName).getHost();
String host = pinecone.describeIndex(indexName).getHost();
PineconeConfig config = new PineconeConfig(apiKey);
config.setHost(host);
return new PineconeConnection(config);
}

public static String createIndexIfNotExistsControlPlane(PineconeControlPlaneClient controlPlaneClient, int dimension, String indexType) throws IOException, InterruptedException {
IndexList indexList = controlPlaneClient.listIndexes();
String indexName = findIndexWithDimensionAndType(indexList, dimension, controlPlaneClient, indexType);
public static String createIndexIfNotExistsControlPlane(Pinecone pinecone, int dimension, String indexType) throws IOException, InterruptedException {
String indexName = findIndexWithDimensionAndType(pinecone, dimension, indexType);

return (indexName.isEmpty()) ? createNewIndex(controlPlaneClient, indexType, dimension) : indexName;
return (indexName.isEmpty()) ? createNewIndex(pinecone, dimension, indexType) : indexName;
}

private static String findIndexWithDimensionAndType(IndexList indexList, int dimension, PineconeControlPlaneClient controlPlaneClient, String indexType)
public static String findIndexWithDimensionAndType(Pinecone pinecone, int dimension, String indexType)
throws InterruptedException {
String indexName = "";
int i = 0;
List<IndexModel> indexModels = indexList.getIndexes();
List<IndexModel> indexModels = pinecone.listIndexes().getIndexes();
if(indexModels == null) {
return indexName;
}
while (i < indexModels.size()) {
IndexModel indexModel = isIndexReady(indexModels.get(i).getName(), controlPlaneClient);
IndexModel indexModel = isIndexReady(indexModels.get(i).getName(), pinecone);
if (indexModel.getDimension() == dimension
&& ((indexType.equalsIgnoreCase(IndexModelSpec.SERIALIZED_NAME_POD)
&& indexModel.getSpec().getPod() != null
Expand All @@ -59,10 +62,10 @@ private static String findIndexWithDimensionAndType(IndexList indexList, int dim
}
i++;
}
return "";
return indexName;
}

private static String createNewIndex(PineconeControlPlaneClient controlPlaneClient, String indexType, int dimension) throws IOException {
public static String createNewIndex(Pinecone pinecone, int dimension, String indexType) {
String indexName = RandomStringBuilder.build("index-name", 8);
String environment = System.getenv("PINECONE_ENVIRONMENT");
CreateIndexRequestSpec createIndexRequestSpec;
Expand All @@ -80,18 +83,18 @@ private static String createNewIndex(PineconeControlPlaneClient controlPlaneClie
.dimension(dimension)
.metric(IndexMetric.DOTPRODUCT)
.spec(createIndexRequestSpec);
controlPlaneClient.createIndex(createIndexRequest);
pinecone.createIndex(createIndexRequest);

return indexName;
}

public static IndexModel waitUntilIndexIsReady(PineconeControlPlaneClient controlPlaneClient, String indexName, Integer totalMsToWait) throws InterruptedException {
IndexModel index = controlPlaneClient.describeIndex(indexName);
public static IndexModel waitUntilIndexIsReady(Pinecone pinecone, String indexName, Integer totalMsToWait) throws InterruptedException {
IndexModel index = pinecone.describeIndex(indexName);
int waitedTimeMs = 0;
int intervalMs = 1500;

while (!index.getStatus().getReady()) {
index = controlPlaneClient.describeIndex(indexName);
index = pinecone.describeIndex(indexName);
if (waitedTimeMs >= totalMsToWait) {
logger.info("Index " + indexName + " not ready after " + waitedTimeMs + "ms");
break;
Expand All @@ -106,27 +109,27 @@ public static IndexModel waitUntilIndexIsReady(PineconeControlPlaneClient contro
return index;
}

public static IndexModel waitUntilIndexIsReady(PineconeControlPlaneClient controlPlaneClient, String indexName) throws InterruptedException {
return waitUntilIndexIsReady(controlPlaneClient, indexName, 120000);
public static IndexModel waitUntilIndexIsReady(Pinecone pinecone, String indexName) throws InterruptedException {
return waitUntilIndexIsReady(pinecone, indexName, 120000);
}

public static PineconeConnection createNewIndexAndConnect(PineconeControlPlaneClient controlPlaneClient, String indexName, int dimension, IndexMetric metric, CreateIndexRequestSpec spec) throws InterruptedException, PineconeException {
public static PineconeConnection createNewIndexAndConnect(Pinecone pinecone, String indexName, int dimension, IndexMetric metric, CreateIndexRequestSpec spec) throws InterruptedException, PineconeException {
String apiKey = System.getenv("PINECONE_API_KEY");
CreateIndexRequest createIndexRequest = new CreateIndexRequest().name(indexName).dimension(dimension).metric(metric).spec(spec);
controlPlaneClient.createIndex(createIndexRequest);
pinecone.createIndex(createIndexRequest);

// Wait until index is ready
waitUntilIndexIsReady(controlPlaneClient, indexName, 200000);
waitUntilIndexIsReady(pinecone, indexName, 200000);
// wait a bit more before we connect...
Thread.sleep(15000);

PineconeConfig config = new PineconeConfig(apiKey);
return new PineconeConnection(config, indexName);
}

public static CollectionModel createCollection(PineconeControlPlaneClient controlPlaneClient, String collectionName, String indexName, boolean waitUntilReady) throws InterruptedException {
public static CollectionModel createCollection(Pinecone pinecone, String collectionName, String indexName, boolean waitUntilReady) throws InterruptedException {
CreateCollectionRequest createCollectionRequest = new CreateCollectionRequest().name(collectionName).source(indexName);
CollectionModel collection = controlPlaneClient.createCollection(createCollectionRequest);
CollectionModel collection = pinecone.createCollection(createCollectionRequest);

assertEquals(collection.getStatus(), CollectionModel.StatusEnum.INITIALIZING);

Expand All @@ -138,7 +141,7 @@ public static CollectionModel createCollection(PineconeControlPlaneClient contro
logger.info("Waiting for collection " + collectionName + " to be ready. Waited " + timeWaited + " milliseconds...");
Thread.sleep(5000);
timeWaited += 5000;
collection = controlPlaneClient.describeCollection(collectionName);
collection = pinecone.describeCollection(collectionName);
collectionReady = collection.getStatus();
}

Expand All @@ -150,11 +153,11 @@ public static CollectionModel createCollection(PineconeControlPlaneClient contro
return collection;
}

public static IndexModel isIndexReady(String indexName, PineconeControlPlaneClient controlPlaneClient)
public static IndexModel isIndexReady(String indexName, Pinecone pinecone)
throws InterruptedException {
final IndexModel[] indexModels = new IndexModel[1];
assertWithRetry(() -> {
indexModels[0] = controlPlaneClient.describeIndex(indexName);
indexModels[0] = pinecone.describeIndex(indexName);
assert (indexModels[0].getStatus().getReady());
}, 4);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.pinecone.integration.controlPlane.pod;

import io.pinecone.configs.PineconeConnection;
import io.pinecone.clients.PineconeControlPlaneClient;
import io.pinecone.clients.Pinecone;
import io.pinecone.exceptions.PineconeException;
import io.pinecone.helpers.RandomStringBuilder;
import io.pinecone.proto.VectorServiceGrpc;
Expand Down Expand Up @@ -35,12 +35,12 @@ public class CollectionErrorTest {
private static final ArrayList<String> collections = new ArrayList<>();
private static final List<String> upsertIds = Arrays.asList("v1", "v2", "v3");
private static final int dimension = 4;
private static PineconeControlPlaneClient controlPlaneClient;
private static Pinecone controlPlaneClient;
private static final Logger logger = LoggerFactory.getLogger(CollectionErrorTest.class);

@BeforeAll
public static void setUpIndexAndCollection() throws InterruptedException {
controlPlaneClient = new PineconeControlPlaneClient(apiKey);
controlPlaneClient = new Pinecone(apiKey);
CreateIndexRequestSpecPod podSpec = new CreateIndexRequestSpecPod().pods(1).podType("p1.x1").replicas(1).environment(environment);
CreateIndexRequestSpec spec = new CreateIndexRequestSpec().pod(podSpec);
PineconeConnection dataPlaneConnection = createNewIndexAndConnect(controlPlaneClient, indexName, dimension, IndexMetric.COSINE, spec);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.pinecone.integration.controlPlane.pod;

import io.pinecone.clients.PineconeControlPlaneClient;
import io.pinecone.clients.Pinecone;
import io.pinecone.configs.*;
import io.pinecone.helpers.RandomStringBuilder;
import io.pinecone.proto.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.*;
import org.slf4j.Logger;
Expand Down Expand Up @@ -34,12 +33,12 @@ public class CollectionTest {
private static final String environment = System.getenv("PINECONE_ENVIRONMENT");
private static final int dimension = 4;
private static final Logger logger = LoggerFactory.getLogger(CollectionTest.class);
private static PineconeControlPlaneClient controlPlaneClient;
private static Pinecone controlPlaneClient;
private static CollectionModel collection;

@BeforeAll
public static void setUp() throws InterruptedException {
controlPlaneClient = new PineconeControlPlaneClient(apiKey);
controlPlaneClient = new Pinecone(apiKey);

// Create and upsert to index
CreateIndexRequestSpecPod podSpec =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package io.pinecone.integration.controlPlane.pod;

import io.pinecone.clients.PineconeControlPlaneClient;
import io.pinecone.clients.Pinecone;
import io.pinecone.exceptions.PineconeException;
import io.pinecone.exceptions.PineconeForbiddenException;
import io.pinecone.exceptions.PineconeBadRequestException;
import io.pinecone.exceptions.PineconeNotFoundException;
import org.junit.jupiter.api.*;
import org.openapitools.client.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

Expand All @@ -18,13 +16,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ConfigureIndexTest {
private static PineconeControlPlaneClient controlPlaneClient;
private static Pinecone controlPlaneClient;
private static String indexName;
private static final Logger logger = LoggerFactory.getLogger(ConfigureIndexTest.class);

@BeforeAll
public static void setUp() throws InterruptedException, IOException {
controlPlaneClient = new PineconeControlPlaneClient(System.getenv("PINECONE_API_KEY"));
controlPlaneClient = new Pinecone(System.getenv("PINECONE_API_KEY"));
indexName = createIndexIfNotExistsControlPlane(controlPlaneClient, 5, IndexModelSpec.SERIALIZED_NAME_POD);
}

Expand All @@ -49,7 +46,7 @@ public void configureIndexWithInvalidIndexName() {

@Test
public void configureIndexExceedingQuota() {
ConfigureIndexRequestSpecPod pod = new ConfigureIndexRequestSpecPod().replicas(20);
ConfigureIndexRequestSpecPod pod = new ConfigureIndexRequestSpecPod().replicas(40);
ConfigureIndexRequestSpec spec = new ConfigureIndexRequestSpec().pod(pod);
ConfigureIndexRequest configureIndexRequest = new ConfigureIndexRequest().spec(spec);
try {
Expand Down Expand Up @@ -121,7 +118,7 @@ public void changingBasePodType() {
}

@Test
public void sizeIncrease() throws InterruptedException {
public void sizeIncrease() {
try {
// Verify the starting state
IndexModel indexModel = isIndexReady(indexName, controlPlaneClient);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.pinecone.integration.controlPlane.pod;

import io.pinecone.clients.PineconeControlPlaneClient;
import io.pinecone.clients.Pinecone;
import io.pinecone.helpers.RandomStringBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -12,13 +12,13 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class CreateDescribeListAndDeleteIndexTest {
private PineconeControlPlaneClient controlPlaneClient;
private Pinecone controlPlaneClient;
private final String apiKey = System.getenv("PINECONE_API_KEY");
private final String environment = System.getenv("PINECONE_ENVIRONMENT");

@BeforeEach
public void setUp() {
controlPlaneClient = new PineconeControlPlaneClient(apiKey);
controlPlaneClient = new Pinecone(apiKey);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.pinecone.integration.controlPlane.serverless;

import io.pinecone.clients.PineconeControlPlaneClient;
import io.pinecone.clients.Pinecone;
import io.pinecone.helpers.RandomStringBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -13,11 +13,11 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class CreateDescribeListAndDeleteIndexTest {
private PineconeControlPlaneClient controlPlaneClient;
private Pinecone controlPlaneClient;

@BeforeEach
public void setUp() {
controlPlaneClient = new PineconeControlPlaneClient(System.getenv("PINECONE_API_KEY"));
controlPlaneClient = new Pinecone(System.getenv("PINECONE_API_KEY"));
}

@Test
Expand Down
Loading