mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-10 15:33:11 +00:00
Add custom vector fields and text fields for OpenSearch (#2652)
**Description** Add custom vector field name and text field name while indexing and querying for OpenSearch **Issues** https://github.com/hwchase17/langchain/issues/2500 Signed-off-by: Naveen Tatikonda <navtat@amazon.com>
This commit is contained in:
@@ -23,6 +23,30 @@ def test_opensearch() -> None:
|
||||
assert output == [Document(page_content="foo")]
|
||||
|
||||
|
||||
def test_opensearch_with_custom_field_name() -> None:
|
||||
"""Test indexing and search using custom vector field and text field name."""
|
||||
docsearch = OpenSearchVectorSearch.from_texts(
|
||||
texts,
|
||||
FakeEmbeddings(),
|
||||
opensearch_url=DEFAULT_OPENSEARCH_URL,
|
||||
vector_field="my_vector",
|
||||
text_field="custom_text",
|
||||
)
|
||||
output = docsearch.similarity_search(
|
||||
"foo", k=1, vector_field="my_vector", text_field="custom_text"
|
||||
)
|
||||
assert output == [Document(page_content="foo")]
|
||||
|
||||
text_input = ["test", "add", "text", "method"]
|
||||
OpenSearchVectorSearch.add_texts(
|
||||
docsearch, text_input, vector_field="my_vector", text_field="custom_text"
|
||||
)
|
||||
output = docsearch.similarity_search(
|
||||
"add", k=1, vector_field="my_vector", text_field="custom_text"
|
||||
)
|
||||
assert output == [Document(page_content="foo")]
|
||||
|
||||
|
||||
def test_opensearch_with_metadatas() -> None:
|
||||
"""Test end to end indexing and search with metadata."""
|
||||
metadatas = [{"page": i} for i in range(len(texts))]
|
||||
|
Reference in New Issue
Block a user