Skip to content

Commit

Permalink
Pass kwargs to get OpenSearch client from_texts (#2993)
Browse files Browse the repository at this point in the history
### Description
Pass kwargs to get OpenSearch client from `from_texts` function

### Issues Resolved
#2819

Signed-off-by: Naveen Tatikonda <navtat@amazon.com>
  • Loading branch information
naveentatikonda committed Apr 18, 2023
1 parent ba9cc23 commit bb619cd
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion langchain/vectorstores/opensearch_vector_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,20 @@ def from_texts(
opensearch_url = get_from_dict_or_env(
kwargs, "opensearch_url", "OPENSEARCH_URL"
)
client = _get_opensearch_client(opensearch_url)
# List of arguments that needs to be removed from kwargs
# before passing kwargs to get opensearch client
keys_list = [
"opensearch_url",
"index_name",
"is_appx_search",
"vector_field",
"text_field",
"engine",
"space_type",
"ef_search",
"ef_construction",
"m",
]
embeddings = embedding.embed_documents(texts)
_validate_embeddings_and_bulk_size(len(embeddings), bulk_size)
dim = len(embeddings[0])
Expand All @@ -488,6 +501,8 @@ def from_texts(
else:
mapping = _default_scripting_text_mapping(dim)

[kwargs.pop(key, None) for key in keys_list]
client = _get_opensearch_client(opensearch_url, **kwargs)
client.indices.create(index=index_name, body=mapping)
_bulk_ingest_embeddings(
client, index_name, embeddings, texts, metadatas, vector_field, text_field
Expand Down

0 comments on commit bb619cd

Please sign in to comment.