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

Expose future stub on Pinecone connection #32

Merged
merged 3 commits into from
Oct 6, 2023
Merged
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
29 changes: 13 additions & 16 deletions src/main/java/io/pinecone/PineconeConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class PineconeConnection implements AutoCloseable {
*/
private VectorServiceGrpc.VectorServiceBlockingStub blockingStub;

private VectorServiceGrpc.VectorServiceStub asyncStub;
private VectorServiceGrpc.VectorServiceFutureStub futureStub;
rohanshah18 marked this conversation as resolved.
Show resolved Hide resolved

public PineconeConnection(PineconeClientConfig clientConfig, PineconeConnectionConfig connectionConfig) {
this.connectionConfig = connectionConfig;
Expand All @@ -45,13 +45,17 @@ public PineconeConnection(PineconeClientConfig clientConfig, PineconeConnectionC
? connectionConfig.getCustomChannelBuilder().apply(clientConfig, connectionConfig)
: buildChannel(clientConfig, connectionConfig);
channel.notifyWhenStateChanged(channel.getState(false), this::onConnectivityStateChanged);
Metadata metadata = assembleMetadata(clientConfig, connectionConfig);
Metadata metadata = assembleMetadata(clientConfig);
blockingStub = VectorServiceGrpc
.newBlockingStub(channel)
.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata));
asyncStub = VectorServiceGrpc
.newStub(channel)
.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata));
.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata))
.withMaxInboundMessageSize(DEFAULT_MAX_MESSAGE_SIZE)
.withMaxOutboundMessageSize(DEFAULT_MAX_MESSAGE_SIZE);
futureStub = VectorServiceGrpc
.newFutureStub(channel)
.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata))
.withMaxInboundMessageSize(DEFAULT_MAX_MESSAGE_SIZE)
.withMaxOutboundMessageSize(DEFAULT_MAX_MESSAGE_SIZE);
logger.debug("created new PineconeConnection for channel: {}", channel);
}

Expand Down Expand Up @@ -79,8 +83,8 @@ public VectorServiceGrpc.VectorServiceBlockingStub getBlockingStub() {
return blockingStub;
}

public void setBlockingStub(VectorServiceGrpc.VectorServiceBlockingStub blockingStub) {
this.blockingStub = blockingStub;
public VectorServiceGrpc.VectorServiceFutureStub getFutureStub() {
return futureStub;
}

private void onConnectivityStateChanged() {
Expand All @@ -104,20 +108,13 @@ public static ManagedChannel buildChannel(PineconeClientConfig clientConfig,
return builder.build();
}

private static Metadata assembleMetadata(PineconeClientConfig clientConfig,
PineconeConnectionConfig connectionConfig) {
private static Metadata assembleMetadata(PineconeClientConfig clientConfig) {
Metadata metadata = new Metadata();
metadata.put(Metadata.Key.of("api-key",
Metadata.ASCII_STRING_MARSHALLER), clientConfig.getApiKey());
return metadata;
}

private VectorServiceGrpc.VectorServiceBlockingStub applyDefaultBlockingStubConfig(VectorServiceGrpc.VectorServiceBlockingStub stub) {
return stub
.withMaxInboundMessageSize(DEFAULT_MAX_MESSAGE_SIZE)
.withMaxOutboundMessageSize(DEFAULT_MAX_MESSAGE_SIZE);
}

static String getEndpoint(PineconeClientConfig clientConfig, PineconeConnectionConfig connectionConfig) {
String endpoint = (connectionConfig.getConnectionUrl() != null) ?
connectionConfig.getConnectionUrl().replaceFirst("https?://", "") :
Expand Down
Loading