diff --git a/CHANGELOG.md b/CHANGELOG.md index d080a296..cdbbacd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/gradle.properties b/gradle.properties index 32160092..a9c6f414 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -pineconeClientVersion = 3.0.0 +pineconeClientVersion = 3.1.0 diff --git a/src/main/java/io/pinecone/clients/Pinecone.java b/src/main/java/io/pinecone/clients/Pinecone.java index d3b60c1b..b6d24aec 100644 --- a/src/main/java/io/pinecone/clients/Pinecone.java +++ b/src/main/java/io/pinecone/clients/Pinecone.java @@ -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. @@ -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. + *
+ * This method allows you to specify a custom base URL for Pinecone control and data plane requests. + *
+ * Example usage: + *
{@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(); + * }+ * + * @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. + *
+ * 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. + *
+ * Example usage: + *
{@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)); + * }+ * + * @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. @@ -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); diff --git a/src/main/java/io/pinecone/commons/Constants.java b/src/main/java/io/pinecone/commons/Constants.java index e9aa47c6..4344f111 100644 --- a/src/main/java/io/pinecone/commons/Constants.java +++ b/src/main/java/io/pinecone/commons/Constants.java @@ -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"; }