Skip to content
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

Merged
merged 2 commits into from
Oct 18, 2024
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
2 changes: 1 addition & 1 deletion codegen/apis
Submodule apis updated from e9b47c to 6189b5
2 changes: 1 addition & 1 deletion codegen/build-oas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -eux -o pipefail

version=$1 # e.g. 2024-07
modules=("control")
modules=("db_control" "db_data" "inference")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. replaced control with db_control
  2. added db_data for bulk import (actual feature is going to be a part of the next PR).
  3. added inference which is now broken out of control plane


destination="src/main/java/org/openapitools"
build_dir="gen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example of updating import statement since db_ is now appended to control and data modules.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.pinecone.clients.Pinecone;
import io.pinecone.proto.DescribeIndexStatsResponse;
import io.pinecone.proto.NamespaceSummary;
import org.openapitools.control.client.model.*;
import org.openapitools.db_control.client.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openapitools.control.client.model.*;
import org.openapitools.db_control.client.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.control.client.model.DeletionProtection;
import org.openapitools.control.client.model.IndexModel;
import org.openapitools.control.client.model.IndexModelStatus;
import org.openapitools.control.client.model.PodSpec;
import org.openapitools.db_control.client.model.DeletionProtection;
import org.openapitools.db_control.client.model.IndexModel;
import org.openapitools.db_control.client.model.IndexModelStatus;
import org.openapitools.db_control.client.model.PodSpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.pinecone.helpers.TestResourcesManager;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.control.client.model.*;
import org.openapitools.db_control.client.model.*;

import static org.junit.jupiter.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.pinecone.helpers.RandomStringBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openapitools.control.client.model.DeletionProtection;
import org.openapitools.control.client.model.IndexModel;
import org.openapitools.db_control.client.model.DeletionProtection;
import org.openapitools.db_control.client.model.IndexModel;

public class DeletionProtectionTest {
private static final Pinecone controlPlaneClient = new Pinecone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.pinecone.helpers.TestResourcesManager;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.control.client.model.*;
import org.openapitools.db_control.client.model.*;

import java.util.Arrays;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.pinecone.helpers.RandomStringBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openapitools.control.client.model.DeletionProtection;
import org.openapitools.control.client.model.IndexModel;
import org.openapitools.db_control.client.model.DeletionProtection;
import org.openapitools.db_control.client.model.IndexModel;

public class DeletionProtectionTest {
private static final Pinecone controlPlaneClient = new Pinecone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.pinecone.clients.Pinecone;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openapitools.control.client.ApiException;
import org.openapitools.control.client.model.EmbeddingsList;
import org.openapitools.inference.client.ApiException;
import org.openapitools.inference.client.model.EmbeddingsList;

import java.util.*;

Expand Down
34 changes: 20 additions & 14 deletions src/main/java/io/pinecone/clients/Inference.java
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
*
Expand All @@ -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);
}

Expand Down
36 changes: 18 additions & 18 deletions src/main/java/io/pinecone/clients/Pinecone.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customOkHttpClient being passed to the PineconeConfig constructor at the time of initializing PineconeConfig in Pinecone class

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);
Expand All @@ -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();
}
}
30 changes: 26 additions & 4 deletions src/main/java/io/pinecone/configs/PineconeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.grpc.ManagedChannel;
import io.pinecone.exceptions.PineconeConfigurationException;
import okhttp3.OkHttpClient;

import static io.pinecone.commons.Constants.pineconeClientVersion;

Expand Down Expand Up @@ -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;

Expand All @@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customOkHttpClient is now a member of PineconeConfig. It makes a lot of sense since gRPC custom channel is already a part of this config class.

* 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;
}

/**
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/pinecone/exceptions/HttpErrorMapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.pinecone.exceptions;

import org.openapitools.control.client.ApiException;
import org.openapitools.db_control.client.ApiException;

public class HttpErrorMapper {

Expand Down
Loading