mirror of
https://github.com/hwchase17/langchain
synced 2024-10-29 17:07:25 +00:00
3f48eed5bd
Signed-off-by: Filip Haltmayer <filip.haltmayer@zilliz.com> Signed-off-by: Frank Liu <frank.liu@zilliz.com> Co-authored-by: Filip Haltmayer <81822489+filip-halt@users.noreply.github.com> Co-authored-by: Frank Liu <frank@frankzliu.com>
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
"""Test ElasticSearch functionality."""
|
|
|
|
from langchain.docstore.document import Document
|
|
from langchain.vectorstores.elastic_vector_search import ElasticVectorSearch
|
|
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings
|
|
|
|
|
|
def test_elasticsearch() -> None:
|
|
"""Test end to end construction and search."""
|
|
texts = ["foo", "bar", "baz"]
|
|
docsearch = ElasticVectorSearch.from_texts(
|
|
texts, FakeEmbeddings(), elasticsearch_url="http://localhost:9200"
|
|
)
|
|
output = docsearch.similarity_search("foo", k=1)
|
|
assert output == [Document(page_content="foo")]
|
|
|
|
|
|
def test_elasticsearch_with_metadatas() -> None:
|
|
"""Test end to end construction and search."""
|
|
texts = ["foo", "bar", "baz"]
|
|
metadatas = [{"page": i} for i in range(len(texts))]
|
|
docsearch = ElasticVectorSearch.from_texts(
|
|
texts,
|
|
FakeEmbeddings(),
|
|
metadatas=metadatas,
|
|
elasticsearch_url="http://localhost:9200",
|
|
)
|
|
output = docsearch.similarity_search("foo", k=1)
|
|
assert output == [Document(page_content="foo", metadata={"page": 0})]
|