Skip to content

Commit

Permalink
Generate code based on 2024-10 api spec (#158)
Browse files Browse the repository at this point in the history
## Problem

Generate code based on 2024-10 api spec.

## Solution
OpenAPI based code was regenerated using the 2024-10 api sec which
resulted in the following changes:
1. Updated `build-oas.sh` to include all control plane, data plane, and
inference modules.
2. Inference is now broken out of control plane so the underlying
`inference` code generated by openAPI spec is now updated. This also
resulted in instantiating a separate `ApiClient` which is a part of
inference module now instead of the shared `ApiClient` class of control
plane. Also as a part of this refactoring, the `customOkHttpClient` is
now a part of the `PineconeConfig` class, so once the
`customOkHttpClient` is set by the user at the time of instantiating
`Pinecone` using its builder class, it'll be stored in the
`PineconeConfig` instance which can further be leveraged by the
`Inference` api calls as well.
3. Control and data plane modules are now prepended with `db_` so this
resulted in updating import statements for a lot of existing classes.

## Type of Change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Infrastructure change (CI configs, etc)
- [ ] Non-code change (docs, etc)
- [ ] None of the above: (explain here)

## Test Plan

Since no new functionality is added, the existing integration tests
should run fine.
  • Loading branch information
rohanshah18 committed Oct 24, 2024
1 parent 6f43b93 commit 5f74845
Show file tree
Hide file tree
Showing 135 changed files with 20,589 additions and 546 deletions.
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")

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.*;
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;
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);
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,
* 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

0 comments on commit 5f74845

Please sign in to comment.