@@ -36,34 +36,20 @@ public static PineconeConnection createIndexIfNotExistsDataPlane(int dimension,
3636 return new PineconeConnection (config );
3737 }
3838
39- public static String createIndexIfNotExistsControlPlane (Pinecone pinecone , int dimension , String indexType ) throws IOException , InterruptedException {
40- String indexName = findIndexWithDimensionAndType (pinecone , dimension , indexType );
41-
42- return (indexName .isEmpty ()) ? createNewIndex (pinecone , dimension , indexType ) : indexName ;
43- }
44-
45- public static String findIndexWithDimensionAndType (Pinecone pinecone , int dimension , String indexType )
46- throws InterruptedException {
39+ public static String findIndexWithDimensionAndType (Pinecone pinecone , int dimension , String indexType ) {
4740 String indexName = "" ;
48- int i = 0 ;
4941 List <IndexModel > indexModels = pinecone .listIndexes ().getIndexes ();
5042 if (indexModels == null ) {
5143 return indexName ;
5244 }
53- while ( i < indexModels . size ()) {
54- IndexModel indexModel = waitUntilIndexIsReady ( pinecone , indexModels . get ( i ). getName ());
45+
46+ for ( IndexModel indexModel : indexModels ) {
5547 if (indexModel .getDimension () == dimension
56- &&
57- (
58- indexType .equalsIgnoreCase (IndexModelSpec .SERIALIZED_NAME_POD )
59- && indexModel .getSpec ().getPod () != null
60- && indexModel .getSpec ().getPod ().getReplicas () == 1
61- && indexModel .getSpec ().getPod ().getPodType ().equalsIgnoreCase ("p1.x1" )
62- )
63- || (indexType .equalsIgnoreCase (IndexModelSpec .SERIALIZED_NAME_SERVERLESS ))) {
48+ && (indexType .equalsIgnoreCase (IndexModelSpec .SERIALIZED_NAME_POD ) && indexModel .getSpec ().getPod () != null )
49+ || (indexType .equalsIgnoreCase (IndexModelSpec .SERIALIZED_NAME_SERVERLESS ) && indexModel .getSpec ().getServerless () != null )
50+ ) {
6451 return indexModel .getName ();
6552 }
66- i ++;
6753 }
6854 return indexName ;
6955 }
@@ -117,7 +103,7 @@ public static IndexModel waitUntilIndexIsReady(Pinecone pinecone, String indexNa
117103 return waitUntilIndexIsReady (pinecone , indexName , 300000 );
118104 }
119105
120- public static PineconeConnection createNewIndexAndConnect (Pinecone pinecone , String indexName , int dimension , IndexMetric metric , CreateIndexRequestSpec spec ) throws InterruptedException , PineconeException {
106+ public static PineconeConnection createNewIndexAndConnect (Pinecone pinecone , String indexName , int dimension , IndexMetric metric , CreateIndexRequestSpec spec , boolean waitUntilIndexIsReady ) throws InterruptedException , PineconeException {
121107 String apiKey = System .getenv ("PINECONE_API_KEY" );
122108 CreateIndexRequest createIndexRequest = new CreateIndexRequest ().name (indexName ).dimension (dimension ).metric (metric ).spec (spec );
123109 pinecone .createIndex (createIndexRequest );
0 commit comments