-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate code based on 2024-10 api spec #158
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import io.pinecone.clients.Pinecone; | ||
import io.pinecone.exceptions.PineconeException; | ||
import io.pinecone.proto.DescribeIndexStatsResponse; | ||
import org.openapitools.control.client.model.*; | ||
import org.openapitools.db_control.client.model.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. example of updating import statement since |
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
package io.pinecone.clients; | ||
|
||
import org.openapitools.control.client.ApiClient; | ||
import org.openapitools.control.client.ApiException; | ||
import org.openapitools.control.client.api.InferenceApi; | ||
import org.openapitools.control.client.model.EmbedRequest; | ||
import org.openapitools.control.client.model.EmbedRequestInputsInner; | ||
import org.openapitools.control.client.model.EmbedRequestParameters; | ||
import org.openapitools.control.client.model.EmbeddingsList; | ||
import io.pinecone.configs.PineconeConfig; | ||
import okhttp3.OkHttpClient; | ||
import org.openapitools.inference.client.ApiClient; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. example of updating import statement since inference is broken out of control module |
||
import org.openapitools.inference.client.Configuration; | ||
import org.openapitools.inference.client.ApiException; | ||
import org.openapitools.inference.client.api.InferenceApi; | ||
import org.openapitools.inference.client.model.*; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
import static io.pinecone.clients.Pinecone.buildOkHttpClient; | ||
|
||
/** | ||
* The Inference class provides methods to interact with Pinecone's inference API through the Java SDK. It allows users | ||
* to send input data to generate embeddings using a specified model. | ||
* to send input data to generate embeddings or rank documents using a specified model. | ||
* <p> | ||
* This class utilizes the {@link InferenceApi} to make API calls to the Pinecone inference service. | ||
* | ||
|
@@ -25,11 +26,16 @@ public class Inference { | |
private final InferenceApi inferenceApi; | ||
|
||
/** | ||
* Constructs an instance of {@link Inference} class. | ||
* | ||
* @param apiClient The ApiClient object used to configure the API connection. | ||
* Constructs an instance of {@link Inference} class using PineconeConfig object. | ||
* @param config The Pinecone configuration object for interacting with inference api. | ||
*/ | ||
public Inference(ApiClient apiClient) { | ||
public Inference(PineconeConfig config) { | ||
OkHttpClient customOkHttpClient = config.getCustomOkHttpClient(); | ||
ApiClient apiClient = (customOkHttpClient != null) ? new ApiClient(customOkHttpClient) : new ApiClient(buildOkHttpClient(config.getProxyConfig())); | ||
apiClient.setApiKey(config.getApiKey()); | ||
apiClient.setUserAgent(config.getUserAgent()); | ||
apiClient.addDefaultHeader("X-Pinecone-Api-Version", Configuration.VERSION); | ||
|
||
inferenceApi = new InferenceApi(apiClient); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,11 @@ | |
import io.pinecone.configs.ProxyConfig; | ||
import io.pinecone.exceptions.*; | ||
import okhttp3.OkHttpClient; | ||
import org.openapitools.control.client.ApiClient; | ||
import org.openapitools.control.client.ApiException; | ||
import org.openapitools.control.client.Configuration; | ||
import org.openapitools.control.client.api.ManageIndexesApi; | ||
import org.openapitools.control.client.model.*; | ||
import org.openapitools.db_control.client.ApiClient; | ||
import org.openapitools.db_control.client.ApiException; | ||
import org.openapitools.db_control.client.Configuration; | ||
import org.openapitools.db_control.client.api.ManageIndexesApi; | ||
import org.openapitools.db_control.client.model.*; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.net.Proxy; | ||
|
@@ -879,13 +879,13 @@ public AsyncIndex getAsyncIndexConnection(String indexName) throws PineconeValid | |
/** | ||
* A method to create and return a new instance of the {@link Inference} client. | ||
* <p> | ||
* This method initializes the Inference client using the current ApiClient | ||
* from the {@link ManageIndexesApi}. The {@link Inference} client can then be used | ||
* to interact with Pinecone's inference API. | ||
* This method initializes the Inference client using the current {@link PineconeConfig} instance which is | ||
* initialized as a part of the Builder class. The {@link Inference} client can then be used to interact with | ||
* Pinecone's inference API. | ||
* @return A new {@link Inference} client instance. | ||
*/ | ||
public Inference getInferenceClient() { | ||
return new Inference(manageIndexesApi.getApiClient()); | ||
return new Inference(config); | ||
} | ||
|
||
PineconeConnection getConnection(String indexName) { | ||
|
@@ -1033,14 +1033,14 @@ public Builder withProxy(String proxyHost, int proxyPort) { | |
* @return A new {@link Pinecone} instance configured based on the builder parameters. | ||
*/ | ||
public Pinecone build() { | ||
PineconeConfig config = new PineconeConfig(apiKey, sourceTag, proxyConfig); | ||
PineconeConfig config = new PineconeConfig(apiKey, sourceTag, proxyConfig, customOkHttpClient); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
config.validate(); | ||
|
||
if (proxyConfig != null && customOkHttpClient != null) { | ||
throw new PineconeConfigurationException("Invalid configuration: Both Custom OkHttpClient and Proxy are set. Please configure only one of these options."); | ||
} | ||
|
||
ApiClient apiClient = (customOkHttpClient != null) ? new ApiClient(customOkHttpClient) : new ApiClient(buildOkHttpClient()); | ||
ApiClient apiClient = (customOkHttpClient != null) ? new ApiClient(customOkHttpClient) : new ApiClient(buildOkHttpClient(proxyConfig)); | ||
apiClient.setApiKey(config.getApiKey()); | ||
apiClient.setUserAgent(config.getUserAgent()); | ||
apiClient.addDefaultHeader("X-Pinecone-Api-Version", Configuration.VERSION); | ||
|
@@ -1054,14 +1054,14 @@ public Pinecone build() { | |
|
||
return new Pinecone(config, manageIndexesApi); | ||
} | ||
} | ||
|
||
private OkHttpClient buildOkHttpClient() { | ||
OkHttpClient.Builder builder = new OkHttpClient.Builder(); | ||
if(proxyConfig != null) { | ||
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyConfig.getHost(), proxyConfig.getPort())); | ||
builder.proxy(proxy); | ||
} | ||
return builder.build(); | ||
static OkHttpClient buildOkHttpClient(ProxyConfig proxyConfig) { | ||
OkHttpClient.Builder builder = new OkHttpClient.Builder(); | ||
if(proxyConfig != null) { | ||
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyConfig.getHost(), proxyConfig.getPort())); | ||
builder.proxy(proxy); | ||
} | ||
return builder.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import io.grpc.ManagedChannel; | ||
import io.pinecone.exceptions.PineconeConfigurationException; | ||
import okhttp3.OkHttpClient; | ||
|
||
import static io.pinecone.commons.Constants.pineconeClientVersion; | ||
|
||
|
@@ -51,6 +52,7 @@ public class PineconeConfig { | |
private String host; | ||
private String sourceTag; | ||
private ProxyConfig proxyConfig; | ||
private OkHttpClient customOkHttpClient; | ||
private ManagedChannel customManagedChannel; | ||
private boolean enableTLS = true; | ||
|
||
|
@@ -70,21 +72,23 @@ public PineconeConfig(String apiKey) { | |
* @param sourceTag An optional source tag to be included in the user agent. | ||
*/ | ||
public PineconeConfig(String apiKey, String sourceTag) { | ||
this(apiKey, sourceTag, null); | ||
this(apiKey, sourceTag, null, null); | ||
} | ||
|
||
/** | ||
* Constructs a {@link PineconeConfig} instance with the specified API key, source tag, control plane proxy | ||
* configuration, and data plane proxy configuration. | ||
* Constructs a {@link PineconeConfig} instance with the specified API key, source tag, a HTTP proxy configuration, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* and a custom OkHttpClient. | ||
* | ||
* @param apiKey The API key required to authenticate with the Pinecone API. | ||
* @param sourceTag An optional source tag to be included in the user agent. | ||
* @param proxyConfig The proxy configuration for control and data plane requests. Can be null if not set. | ||
* @param customOkHttpClient The custom OkHttpClient for making HTTP requests. Can be null if not set. | ||
*/ | ||
public PineconeConfig(String apiKey, String sourceTag, ProxyConfig proxyConfig) { | ||
public PineconeConfig(String apiKey, String sourceTag, ProxyConfig proxyConfig, OkHttpClient customOkHttpClient) { | ||
this.apiKey = apiKey; | ||
this.sourceTag = sourceTag; | ||
this.proxyConfig = proxyConfig; | ||
this.customOkHttpClient = customOkHttpClient; | ||
} | ||
|
||
/** | ||
|
@@ -168,6 +172,24 @@ public ManagedChannel getCustomManagedChannel() { | |
return this.customManagedChannel; | ||
} | ||
|
||
/** | ||
* Gets a custom OkHttpClient for making HTTP requests. | ||
* | ||
* @return The custom OkHttpClient for control plane or inference api calls. | ||
*/ | ||
public OkHttpClient getCustomOkHttpClient() { | ||
return customOkHttpClient; | ||
} | ||
|
||
/** | ||
* Sets a custom OkHttpClient for making HTTP requests. | ||
* | ||
* @param customOkHttpClient The custom OkHttpClient. | ||
*/ | ||
public void setCustomOkHttpClient(OkHttpClient customOkHttpClient) { | ||
this.customOkHttpClient = customOkHttpClient; | ||
} | ||
|
||
/** | ||
* Sets the custom gRPC managed channel if the user is not interested in using default gRPC channel initialized | ||
* and set in the Pinecone Builder class. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.