Skip to content

Commit

Permalink
pass OpenSearchClient directly to OpenSearchEmbeddingStore (langchain…
Browse files Browse the repository at this point in the history
  • Loading branch information
sboeckelmann authored Nov 25, 2023
1 parent f98c040 commit 11e7364
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class OpenSearchEmbeddingStore implements EmbeddingStore<TextSegment> {
* @param apiKey OpenSearch API key (optional)
* @param userName OpenSearch username (optional)
* @param password OpenSearch password (optional)
* @param indexName OpenSearch index name (optional). Default value: "default"
* @param indexName OpenSearch index name.
*/
public OpenSearchEmbeddingStore(String serverUrl,
String apiKey,
Expand Down Expand Up @@ -121,7 +121,7 @@ public OpenSearchEmbeddingStore(String serverUrl,
* @param serviceName The AWS signing service name, one of `es` (Amazon OpenSearch) or `aoss` (Amazon OpenSearch Serverless).
* @param region The AWS region for which requests will be signed. This should typically match the region in `serverUrl`.
* @param options The options to establish connection with the service. It must include which credentials should be used.
* @param indexName OpenSearch index name (optional). Default value: "default"
* @param indexName OpenSearch index name.
*/
public OpenSearchEmbeddingStore(String serverUrl,
String serviceName,
Expand All @@ -138,6 +138,19 @@ public OpenSearchEmbeddingStore(String serverUrl,
this.indexName = ensureNotNull(indexName, "indexName");
}

/**
* Creates an instance of OpenSearchEmbeddingStore using provided OpenSearchClient
*
* @param openSearchClient OpenSearch client provided
* @param indexName OpenSearch index name.
*/
public OpenSearchEmbeddingStore(OpenSearchClient openSearchClient,
String indexName) {

this.client = ensureNotNull(openSearchClient, "openSearchClient");
this.indexName = ensureNotNull(indexName, "indexName");
}

public static Builder builder() {
return new Builder();
}
Expand All @@ -152,6 +165,7 @@ public static class Builder {
private String region;
private AwsSdk2TransportOptions options;
private String indexName = "default";
private OpenSearchClient openSearchClient;

public Builder serverUrl(String serverUrl) {
this.serverUrl = serverUrl;
Expand Down Expand Up @@ -193,7 +207,14 @@ public Builder indexName(String indexName) {
return this;
}

public Builder openSearchClient(OpenSearchClient openSearchClient) {
this.openSearchClient = openSearchClient;
return this;
}
public OpenSearchEmbeddingStore build() {
if (openSearchClient != null) {
return new OpenSearchEmbeddingStore(openSearchClient, indexName);
}
if (!isNullOrBlank(serviceName) && !isNullOrBlank(region) && options != null) {
return new OpenSearchEmbeddingStore(serverUrl, serviceName, region, options, indexName);
}
Expand Down

0 comments on commit 11e7364

Please sign in to comment.