Skip to content

Commit

Permalink
[OpenSearch] Pass ids using from_texts and indexname in add_texts and…
Browse files Browse the repository at this point in the history
… search (#10969)

### Description
This PR makes the following changes to OpenSearch:
1. Pass optional ids with `from_texts`
2. Pass an optional index name with `add_texts` and `search` instead of
using the same index name that was used during `from_texts`

### Issue
#10967

### Maintainers
@rlancemartin, @eyurtsev, @navneet1v

Signed-off-by: Naveen Tatikonda <[email protected]>
  • Loading branch information
naveentatikonda authored Sep 23, 2023
1 parent f945426 commit b0f21e2
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def add_texts(
"""
embeddings = self.embedding_function.embed_documents(list(texts))
_validate_embeddings_and_bulk_size(len(embeddings), bulk_size)
index_name = _get_kwargs_value(kwargs, "index_name", self.index_name)
text_field = _get_kwargs_value(kwargs, "text_field", "text")
dim = len(embeddings[0])
engine = _get_kwargs_value(kwargs, "engine", "nmslib")
Expand All @@ -392,7 +393,7 @@ def add_texts(

return _bulk_ingest_embeddings(
self.client,
self.index_name,
index_name,
embeddings,
texts,
metadatas=metadatas,
Expand Down Expand Up @@ -526,6 +527,7 @@ def _raw_similarity_search_with_score(
embedding = self.embedding_function.embed_query(query)
search_type = _get_kwargs_value(kwargs, "search_type", "approximate_search")
vector_field = _get_kwargs_value(kwargs, "vector_field", "vector_field")
index_name = _get_kwargs_value(kwargs, "index_name", self.index_name)

if (
self.is_aoss
Expand Down Expand Up @@ -601,7 +603,7 @@ def _raw_similarity_search_with_score(
else:
raise ValueError("Invalid `search_type` provided as an argument")

response = self.client.search(index=self.index_name, body=search_query)
response = self.client.search(index=index_name, body=search_query)

return [hit for hit in response["hits"]["hits"]]

Expand Down Expand Up @@ -663,6 +665,7 @@ def from_texts(
embedding: Embeddings,
metadatas: Optional[List[dict]] = None,
bulk_size: int = 500,
ids: Optional[List[str]] = None,
**kwargs: Any,
) -> OpenSearchVectorSearch:
"""Construct OpenSearchVectorSearch wrapper from raw documents.
Expand Down Expand Up @@ -772,6 +775,7 @@ def from_texts(
embeddings,
texts,
metadatas=metadatas,
ids=ids,
vector_field=vector_field,
text_field=text_field,
mapping=mapping,
Expand Down

0 comments on commit b0f21e2

Please sign in to comment.