Skip to content

Add support for passing base path for control plane operations #168

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

Merged
merged 3 commits into from
Nov 27, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

[comment]: <> (When bumping [pc:VERSION_LATEST_RELEASE] create a new entry below)
### Unreleased version
### 3.1.0
- Add support to pass base url for control and data plane operations

### 3.0.0
- Add support for imports
- start import
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pineconeClientVersion = 3.0.0
pineconeClientVersion = 3.1.0
65 changes: 64 additions & 1 deletion src/main/java/io/pinecone/clients/Pinecone.java
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,11 @@ public static class Builder {
private final String apiKey;

// Optional fields
private String host;
private String sourceTag;
private ProxyConfig proxyConfig;
private OkHttpClient customOkHttpClient;
private boolean enableTls = true;

/**
* Constructs a new {@link Builder} with the mandatory API key.
Expand Down Expand Up @@ -1023,6 +1025,57 @@ public Builder withProxy(String proxyHost, int proxyPort) {
return this;
}

/**
* Sets a custom host URL for the control and data plane operations.
* <p>
* This method allows you to specify a custom base URL for Pinecone control and data plane requests.
* <p>
* Example usage:
* <pre>{@code
* Pinecone client = new Pinecone.Builder("PINECONE_API_KEY")
* .withHost("http://localhost:5080")
* .build();
*
* // Requests will now be sent to the specified host.
* client.listIndexes();
* }</pre>
*
* @param host The custom host URL for the Pinecone service. Must be a valid URL.
* @return This {@link Builder} instance for chaining method calls.
*/
public Builder withHost(String host) {
this.host = host;
return this;
}

/**
* Configures whether TLS (Transport Layer Security) should be enabled for data plane operations.
* <p>
* By default, TLS is enabled for data plane requests to ensure secure communication for data plane operations.
* This method can be used to disable TLS if needed (e.g., for testing or when communicating with non-secure
* endpoints). Disabling TLS in a production environment is not recommended due to potential security risks.
* <p>
* Example usage:
* <pre>{@code
* Pinecone client = new Pinecone.Builder("PINECONE_API_KEY")
* .withTlsEnabled(false)
* .build();
*
* // Get index for data plane operations
* Index index = pinecone.getIndexConnection("PINECONE_INDEX_NAME");
*
* // Requests will now be made without TLS encryption (not recommended for production use).
* index.upsert("v1", Arrays.asList(1f, 2f, 3f));
* }</pre>
*
* @param enableTls {@code true} to enable TLS (default), {@code false} to disable it.
* @return This {@link Builder} instance for chaining method calls.
*/
public Builder withTlsEnabled(boolean enableTls) {
this.enableTls = enableTls;
return this;
}

/**
* Builds and returns a {@link Pinecone} instance configured with the provided API key, optional source tag,
* and OkHttpClient.
Expand All @@ -1034,13 +1087,23 @@ public Builder withProxy(String proxyHost, int proxyPort) {
*/
public Pinecone build() {
PineconeConfig config = new PineconeConfig(apiKey, sourceTag, proxyConfig, customOkHttpClient);
config.setTLSEnabled(enableTls);
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(proxyConfig));
ApiClient apiClient;
if (customOkHttpClient != null) {
apiClient = new ApiClient(customOkHttpClient);
} else {
apiClient = new ApiClient(buildOkHttpClient(proxyConfig));
if(host!=null && !host.isEmpty()) {
config.setHost(host);
apiClient.setBasePath(host);
}
}
apiClient.setApiKey(config.getApiKey());
apiClient.setUserAgent(config.getUserAgent());
apiClient.addDefaultHeader("X-Pinecone-Api-Version", Configuration.VERSION);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/pinecone/commons/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package io.pinecone.commons;

public class Constants {
public static final String pineconeClientVersion = "v3.0.0";
public static final String pineconeClientVersion = "v3.1.0";
}
Loading