|
2 | 2 |
|
3 | 3 | import io.grpc.ManagedChannel;
|
4 | 4 | import io.grpc.Metadata;
|
5 |
| -import io.grpc.StatusRuntimeException; |
6 | 5 | import io.grpc.netty.GrpcSslContexts;
|
7 | 6 | import io.grpc.netty.NegotiationType;
|
8 | 7 | import io.grpc.netty.NettyChannelBuilder;
|
@@ -36,9 +35,10 @@ public class PineconeConnection implements AutoCloseable {
|
36 | 35 | private VectorServiceGrpc.VectorServiceStub asyncStub;
|
37 | 36 |
|
38 | 37 | public PineconeConnection(PineconeClientConfig clientConfig, PineconeConnectionConfig connectionConfig) {
|
39 |
| - connectionConfig.validate(); |
40 | 38 | this.connectionConfig = connectionConfig;
|
41 | 39 | this.clientConfig = clientConfig;
|
| 40 | + validateConfigs(); |
| 41 | + |
42 | 42 | channel = connectionConfig.getCustomChannelBuilder() != null
|
43 | 43 | ? connectionConfig.getCustomChannelBuilder().apply(clientConfig, connectionConfig)
|
44 | 44 | : buildChannel(clientConfig, connectionConfig);
|
@@ -113,15 +113,37 @@ private VectorServiceGrpc.VectorServiceBlockingStub applyDefaultBlockingStubConf
|
113 | 113 | .withMaxOutboundMessageSize(DEFAULT_MAX_MESSAGE_SIZE);
|
114 | 114 | }
|
115 | 115 |
|
116 |
| - private static String getEndpoint(PineconeClientConfig clientConfig, PineconeConnectionConfig connectionConfig) { |
117 |
| - String endpoint = String.format("%s-%s.svc.%s.pinecone.io", |
118 |
| - connectionConfig.getIndexName(), |
119 |
| - clientConfig.getProjectName(), |
120 |
| - clientConfig.getEnvironment()); |
| 116 | + static String getEndpoint(PineconeClientConfig clientConfig, PineconeConnectionConfig connectionConfig) { |
| 117 | + String endpoint = (connectionConfig.getConnectionUrl() != null) ? |
| 118 | + connectionConfig.getConnectionUrl().replaceFirst("https?://", "") : |
| 119 | + String.format("%s-%s.svc.%s.pinecone.io", |
| 120 | + connectionConfig.getIndexName(), |
| 121 | + clientConfig.getProjectName(), |
| 122 | + clientConfig.getEnvironment()); |
121 | 123 |
|
122 | 124 | logger.debug("Pinecone endpoint is: " + endpoint);
|
123 | 125 |
|
124 | 126 | return endpoint;
|
| 127 | + } |
| 128 | + |
| 129 | + void validateConfigs() throws PineconeValidationException { |
| 130 | + if (this.clientConfig == null) { |
| 131 | + throw new PineconeValidationException("PineconeClientConfiguration may not be null"); |
| 132 | + } |
125 | 133 |
|
| 134 | + if (this.connectionConfig == null) { |
| 135 | + throw new PineconeValidationException("PineconeConnectionConfig may not be null"); |
| 136 | + } |
| 137 | + |
| 138 | + this.clientConfig.validate(); |
| 139 | + this.connectionConfig.validate(); |
| 140 | + |
| 141 | + if (this.connectionConfig.getIndexName() != null) { |
| 142 | + if (this.clientConfig.getEnvironment() == null || this.clientConfig.getProjectName() == null) { |
| 143 | + throw new PineconeValidationException("Cannot connect with indexName " |
| 144 | + + this.connectionConfig.getIndexName() |
| 145 | + + " unless PineconeClientConfig contains projectName and environment"); |
| 146 | + } |
| 147 | + } |
126 | 148 | }
|
127 | 149 | }
|
0 commit comments