|
| 1 | +package io.pinecone.clients; |
| 2 | + |
| 3 | +import io.pinecone.configs.PineconeConfig; |
| 4 | +import okhttp3.OkHttpClient; |
| 5 | +import org.openapitools.db_data.client.ApiClient; |
| 6 | +import org.openapitools.db_data.client.ApiException; |
| 7 | +import org.openapitools.db_data.client.Configuration; |
| 8 | +import org.openapitools.db_data.client.api.VectorOperationsApi; |
| 9 | +import org.openapitools.db_data.client.model.*; |
| 10 | + |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +import static io.pinecone.clients.Pinecone.buildOkHttpClient; |
| 14 | + |
| 15 | +public class RestIndex { |
| 16 | + private final VectorOperationsApi vectorOperations; |
| 17 | + |
| 18 | + public RestIndex(PineconeConfig config) { |
| 19 | + OkHttpClient customOkHttpClient = config.getCustomOkHttpClient(); |
| 20 | + ApiClient apiClient = (customOkHttpClient != null) ? new ApiClient(customOkHttpClient) : new ApiClient(buildOkHttpClient(config.getProxyConfig())); |
| 21 | + apiClient.setApiKey(config.getApiKey()); |
| 22 | + apiClient.setUserAgent(config.getUserAgent()); |
| 23 | + apiClient.addDefaultHeader("X-Pinecone-Api-Version", Configuration.VERSION); |
| 24 | + |
| 25 | + this.vectorOperations = new VectorOperationsApi(apiClient); |
| 26 | + String protocol = config.isTLSEnabled() ? "https://" : "http://"; |
| 27 | + vectorOperations.setCustomBaseUrl(protocol + config.getHost()); |
| 28 | + } |
| 29 | + |
| 30 | + public void upsertRecords(String namespace, List<UpsertRecord> upsertRecord) throws ApiException { |
| 31 | + vectorOperations.upsertRecordsNamespace(namespace, upsertRecord); |
| 32 | + } |
| 33 | + |
| 34 | + public SearchRecordsResponse searchRecords(String id, String namespace, Object filter, int topK, SearchRecordsVector vector) throws ApiException { |
| 35 | + SearchRecordsRequestQuery searchRecordsRequestquery = new SearchRecordsRequestQuery() |
| 36 | + .id(id) |
| 37 | + .filter(filter) |
| 38 | + .topK(topK) |
| 39 | + .vector(vector); |
| 40 | + SearchRecordsRequest request = new SearchRecordsRequest().query(searchRecordsRequestquery); |
| 41 | + |
| 42 | + return vectorOperations.searchRecordsNamespace(namespace, request); |
| 43 | + } |
| 44 | +} |
0 commit comments