Skip to content
Draft
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
11 changes: 7 additions & 4 deletions src/main/java/io/pinecone/clients/Pinecone.java
Original file line number Diff line number Diff line change
Expand Up @@ -1778,11 +1778,14 @@ public Pinecone build() {
apiClient = new ApiClient(customOkHttpClient);
} else {
apiClient = new ApiClient(buildOkHttpClient(proxyConfig));
if(host!=null && !host.isEmpty()) {
config.setHost(host);
apiClient.setBasePath(host);
}
}

// Set host regardless of whether customOkHttpClient is used
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
38 changes: 38 additions & 0 deletions src/test/java/io/pinecone/PineconeBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,42 @@ public void PineconeWithSourceTag() throws IOException {
verify(mockClient, times(1)).newCall(requestCaptor.capture());
assertEquals("lang=java; pineconeClientVersion=" + pineconeClientVersion + "; source_tag=testSourceTag", requestCaptor.getValue().header("User-Agent"));
}

@Test
public void PineconeWithHostAndCustomOkHttpClient() {
String customHost = "http://localhost:5080";
OkHttpClient customClient = new OkHttpClient.Builder().build();

// Verify that the builder doesn't throw an exception when both host and custom client are set
Pinecone client = new Pinecone.Builder("testApiKey")
.withHost(customHost)
.withOkHttpClient(customClient)
.build();

assertNotNull(client, "Pinecone client should be created successfully with both host and custom OkHttpClient");
}

@Test
public void PineconeWithHostButNoCustomOkHttpClient() {
String customHost = "http://localhost:5080";

// Verify that the builder doesn't throw an exception when host is set without custom client
Pinecone client = new Pinecone.Builder("testApiKey")
.withHost(customHost)
.build();

assertNotNull(client, "Pinecone client should be created successfully with host but no custom OkHttpClient");
}

@Test
public void PineconeWithCustomOkHttpClientButNoHost() {
OkHttpClient customClient = new OkHttpClient.Builder().build();

// Verify that the builder doesn't throw an exception when custom client is set without host
Pinecone client = new Pinecone.Builder("testApiKey")
.withOkHttpClient(customClient)
.build();

assertNotNull(client, "Pinecone client should be created successfully with custom OkHttpClient but no host");
}
}
Loading