55import com .google .common .util .concurrent .MoreExecutors ;
66import com .google .protobuf .Struct ;
77import io .pinecone .commons .IndexInterface ;
8+ import io .pinecone .configs .PineconeConfig ;
89import io .pinecone .configs .PineconeConnection ;
910import io .pinecone .exceptions .PineconeValidationException ;
1011import io .pinecone .proto .*;
12+ import io .pinecone .proto .DeleteRequest ;
13+ import io .pinecone .proto .DescribeIndexStatsRequest ;
14+ import io .pinecone .proto .FetchResponse ;
15+ import io .pinecone .proto .ListResponse ;
16+ import io .pinecone .proto .QueryRequest ;
17+ import io .pinecone .proto .QueryResponse ;
18+ import io .pinecone .proto .UpdateRequest ;
19+ import io .pinecone .proto .UpsertRequest ;
20+ import io .pinecone .proto .UpsertResponse ;
1121import io .pinecone .unsigned_indices_model .QueryResponseWithUnsignedIndices ;
1222import io .pinecone .unsigned_indices_model .VectorWithUnsignedIndices ;
23+ import okhttp3 .OkHttpClient ;
24+ import org .openapitools .db_data .client .ApiClient ;
25+ import org .openapitools .db_data .client .ApiException ;
26+ import org .openapitools .db_data .client .Configuration ;
27+ import org .openapitools .db_data .client .api .BulkOperationsApi ;
28+ import org .openapitools .db_data .client .model .*;
1329
1430import java .util .List ;
1531
32+ import static io .pinecone .clients .Pinecone .buildOkHttpClient ;
33+
1634
1735/**
1836 * A client for interacting with a Pinecone index via GRPC asynchronously. Allows for upserting, querying, fetching, updating, and deleting vectors.
@@ -38,6 +56,7 @@ public class AsyncIndex implements IndexInterface<ListenableFuture<UpsertRespons
3856 private final PineconeConnection connection ;
3957 private final VectorServiceGrpc .VectorServiceFutureStub asyncStub ;
4058 private final String indexName ;
59+ BulkOperationsApi bulkOperations ;
4160
4261 /**
4362 * Constructs an {@link AsyncIndex} instance for interacting with a Pinecone index.
@@ -55,14 +74,24 @@ public class AsyncIndex implements IndexInterface<ListenableFuture<UpsertRespons
5574 * @param indexName The name of the index to interact with. The index host will be automatically resolved.
5675 * @throws PineconeValidationException if the connection object is null.
5776 */
58- public AsyncIndex (PineconeConnection connection , String indexName ) {
77+ public AsyncIndex (PineconeConfig config , PineconeConnection connection , String indexName ) {
5978 if (connection == null ) {
6079 throw new PineconeValidationException ("Pinecone connection object cannot be null." );
6180 }
6281
6382 this .indexName = indexName ;
6483 this .connection = connection ;
6584 this .asyncStub = connection .getAsyncStub ();
85+
86+ OkHttpClient customOkHttpClient = config .getCustomOkHttpClient ();
87+ ApiClient apiClient = (customOkHttpClient != null ) ? new ApiClient (customOkHttpClient ) : new ApiClient (buildOkHttpClient (config .getProxyConfig ()));
88+ apiClient .setApiKey (config .getApiKey ());
89+ apiClient .setUserAgent (config .getUserAgent ());
90+ apiClient .addDefaultHeader ("X-Pinecone-Api-Version" , Configuration .VERSION );
91+
92+ this .bulkOperations = new BulkOperationsApi (apiClient );
93+ String protocol = config .isTLSEnabled () ? "https://" : "http://" ;
94+ bulkOperations .setCustomBaseUrl (protocol + config .getHost ());
6695 }
6796
6897 /**
@@ -1039,6 +1068,175 @@ public ListenableFuture<ListResponse> list(String namespace, String prefix, Stri
10391068 return asyncStub .list (listRequest );
10401069 }
10411070
1071+ /**
1072+ * <p>Initiates an asynchronous import of vectors from object storage into a specified index.</p>
1073+ *
1074+ * <p>The method constructs a {@link StartImportRequest} using the provided URI for the data and optional
1075+ * storage integration ID. It also allows for specifying how to respond to errors during the import process
1076+ * through the {@link ImportErrorMode}. The import operation is then initiated via a call to the
1077+ * underlying {@link BulkOperationsApi}.</p>
1078+ *
1079+ * <p>Example:
1080+ * <pre>{@code
1081+ * import org.openapitools.db_data.client.ApiException;
1082+ * import org.openapitools.db_data.client.model.ImportErrorMode;
1083+ *
1084+ * ...
1085+ *
1086+ * String uri = "s3://path/to/file.parquet";
1087+ * String integrationId = "123-456-789";
1088+ * StartImportResponse response = asyncIndex.startImport(uri, integrationId, ImportErrorMode.OnErrorEnum.CONTINUE);
1089+ * }</pre>
1090+ *
1091+ * @param uri The URI prefix under which the data to import is available.
1092+ * @param integrationId The ID of the storage integration to access the data. Can be null or empty.
1093+ * @param errorMode Indicates how to respond to errors during the import process. Can be null.
1094+ * @return {@link StartImportResponse} containing the details of the initiated import operation.
1095+ * @throws ApiException if there are issues processing the request or communicating with the server.
1096+ * This includes network issues, server errors, or serialization issues with the request or response.
1097+ */
1098+ public StartImportResponse startImport (String uri , String integrationId , ImportErrorMode .OnErrorEnum errorMode ) throws ApiException {
1099+ StartImportRequest importRequest = new StartImportRequest ();
1100+ importRequest .setUri (uri );
1101+ if (integrationId != null && !integrationId .isEmpty ()) {
1102+ importRequest .setIntegrationId (integrationId );
1103+ }
1104+ if (errorMode != null ) {
1105+ ImportErrorMode importErrorMode = new ImportErrorMode ().onError (errorMode );
1106+ importRequest .setErrorMode (importErrorMode );
1107+ }
1108+
1109+ return bulkOperations .startBulkImport (importRequest );
1110+ }
1111+
1112+ /**
1113+ * <p>Lists all recent and ongoing import operations for the specified index with default limit and pagination.</p>
1114+ *
1115+ * <p>The method constructs a request to fetch a list of import operations, limited by the default value set to 100
1116+ * number of operations to return per page. The pagination token is set to null as well by default.</p>
1117+ *
1118+ *
1119+ * <p>Example:
1120+ * <pre>{@code
1121+ * import org.openapitools.db_data.client.ApiException;
1122+ * import org.openapitools.db_data.client.model.ListImportsResponse;
1123+ *
1124+ * ...
1125+ *
1126+ * ListImportsResponse response = asyncIndex.listImports();
1127+ * }</pre>
1128+ *
1129+ * @return {@link ListImportsResponse} containing the list of recent and ongoing import operations.
1130+ * @throws ApiException if there are issues processing the request or communicating with the server.
1131+ * This includes network issues, server errors, or serialization issues with the request or response.
1132+ */
1133+ public ListImportsResponse listImports () throws ApiException {
1134+ return listImports (100 , null );
1135+ }
1136+
1137+ /**
1138+ * <p>Lists all recent and ongoing import operations for the specified index based on limit.</p>
1139+ *
1140+ * <p>The method constructs a request to fetch a list of import operations, limited by the specified
1141+ * maximum number of operations to return per page. The pagination token is set to null by default.</p>
1142+ *
1143+ *
1144+ * <p>Example:
1145+ * <pre>{@code
1146+ * import org.openapitools.db_data.client.ApiException;
1147+ * import org.openapitools.db_data.client.model.ListImportsResponse;
1148+ *
1149+ * ...
1150+ * int limit = 10;
1151+ * ListImportsResponse response = asyncIndex.listImports(limit);
1152+ * }</pre>
1153+ *
1154+ * @param limit The maximum number of operations to return per page. Default is 100.
1155+ * @return {@link ListImportsResponse} containing the list of recent and ongoing import operations.
1156+ * @throws ApiException if there are issues processing the request or communicating with the server.
1157+ * This includes network issues, server errors, or serialization issues with the request or response.
1158+ */
1159+ public ListImportsResponse listImports (Integer limit ) throws ApiException {
1160+ return listImports (limit , null );
1161+ }
1162+
1163+ /**
1164+ * <p>Lists all recent and ongoing import operations for the specified index.</p>
1165+ *
1166+ * <p>The method constructs a request to fetch a list of import operations, limited by the specified
1167+ * maximum number of operations to return per page. The pagination token allows for
1168+ * deterministic pagination through the list of import operations.</p>
1169+ *
1170+ * <p>Example:
1171+ * <pre>{@code
1172+ * import org.openapitools.db_data.client.ApiException;
1173+ * import org.openapitools.db_data.client.model.ListImportsResponse;
1174+ *
1175+ * ...
1176+ * int limit = 10;
1177+ * String paginationToken = "some-pagination-token";
1178+ * ListImportsResponse response = asyncIndex.listImports(limit, paginationToken);
1179+ * }</pre>
1180+ *
1181+ * @param limit The maximum number of operations to return per page. Default is 100.
1182+ * @param paginationToken The token to continue a previous listing operation. Can be null or empty.
1183+ * @return {@link ListImportsResponse} containing the list of recent and ongoing import operations.
1184+ * @throws ApiException if there are issues processing the request or communicating with the server.
1185+ * This includes network issues, server errors, or serialization issues with the request or response.
1186+ */
1187+ public ListImportsResponse listImports (Integer limit , String paginationToken ) throws ApiException {
1188+ return bulkOperations .listBulkImports (limit , paginationToken );
1189+ }
1190+
1191+ /**
1192+ * <p>Retrieves detailed information about a specific import operation using its unique identifier.</p>
1193+ *
1194+ * <p>The method constructs a request to fetch details of the specified import operation by its ID,
1195+ * allowing users to monitor the status and results of the import process.</p>
1196+ *
1197+ * <p>Example:
1198+ * <pre>{@code
1199+ * import org.openapitools.db_data.client.ApiException;
1200+ * import org.openapitools.db_data.client.model.ImportModel;
1201+ *
1202+ * ...
1203+ *
1204+ * String importId = "1";
1205+ * ImportModel importDetails = asyncIndex.describeImport(importId);
1206+ * }</pre>
1207+ *
1208+ * @param id The unique identifier for the import operation.
1209+ * @return {@link ImportModel} containing details of the specified import operation.
1210+ * @throws ApiException if there are issues processing the request or communicating with the server.
1211+ * This includes network issues, server errors, or serialization issues with the request or response.
1212+ */
1213+ public ImportModel describeImport (String id ) throws ApiException {
1214+ return bulkOperations .describeBulkImport (id );
1215+ }
1216+
1217+ /**
1218+ * <p>Attempts to cancel an ongoing import operation using its unique identifier.</p>
1219+ *
1220+ * <p>The method issues a request to cancel the specified import operation if it has not yet finished.
1221+ * If the operation is already completed, the method has no effect.</p>
1222+ *
1223+ * <p>Example:
1224+ * <pre>{@code
1225+ * import org.openapitools.db_data.client.ApiException;
1226+ *
1227+ * ...
1228+ * String importId = "2";
1229+ * asyncIndex.cancelImport(importId);
1230+ * }</pre>
1231+ *
1232+ * @param id The unique identifier for the import operation to cancel.
1233+ * @throws ApiException if there are issues processing the request or communicating with the server.
1234+ * This includes network issues, server errors, or serialization issues with the request or response.
1235+ */
1236+ public void cancelImport (String id ) throws ApiException {
1237+ bulkOperations .cancelBulkImport (id );
1238+ }
1239+
10421240 /**
10431241 * {@inheritDoc}
10441242 * Closes the current index connection gracefully, releasing any resources associated with it. This method should
0 commit comments