mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-09-12 01:31:08 +00:00

* 1. Prevent update_embeddings function in FAISSDocumentStore to set faiss_index as None when document store does not have any docs. 2. cleaning up tests by adding fixture for retriever. * TfidfRetriever need document store with documents during initialization as it call fit() function in constructor so fixing it by checking self.paragraphs of None * Fix naming of retriever's fixture (embedded to embedding and tfid to tfidf)
34 lines
1.7 KiB
Python
34 lines
1.7 KiB
Python
import pytest
|
|
|
|
|
|
@pytest.mark.parametrize("document_store_with_docs", [("elasticsearch")], indirect=True)
|
|
@pytest.mark.parametrize("retriever_with_docs", ["elsticsearch"], indirect=True)
|
|
def test_elasticsearch_retrieval(retriever_with_docs, document_store_with_docs):
|
|
res = retriever_with_docs.retrieve(query="Who lives in Berlin?")
|
|
assert res[0].text == "My name is Carla and I live in Berlin"
|
|
assert len(res) == 3
|
|
assert res[0].meta["name"] == "filename1"
|
|
|
|
|
|
@pytest.mark.parametrize("document_store_with_docs", [("elasticsearch")], indirect=True)
|
|
@pytest.mark.parametrize("retriever_with_docs", ["elsticsearch"], indirect=True)
|
|
def test_elasticsearch_retrieval_filters(retriever_with_docs, document_store_with_docs):
|
|
res = retriever_with_docs.retrieve(query="Who lives in Berlin?", filters={"name": ["filename1"]})
|
|
assert res[0].text == "My name is Carla and I live in Berlin"
|
|
assert len(res) == 1
|
|
assert res[0].meta["name"] == "filename1"
|
|
|
|
res = retriever_with_docs.retrieve(query="Who lives in Berlin?", filters={"name":["filename1"], "meta_field": ["not_existing_value"]})
|
|
assert len(res) == 0
|
|
|
|
res = retriever_with_docs.retrieve(query="Who lives in Berlin?", filters={"name":["filename1"], "not_existing_field": ["not_existing_value"]})
|
|
assert len(res) == 0
|
|
|
|
res = retriever_with_docs.retrieve(query="Who lives in Berlin?", filters={"name":["filename1"], "meta_field": ["test1","test2"]})
|
|
assert res[0].text == "My name is Carla and I live in Berlin"
|
|
assert len(res) == 1
|
|
assert res[0].meta["name"] == "filename1"
|
|
|
|
res = retriever_with_docs.retrieve(query="Who lives in Berlin?", filters={"name":["filename1"], "meta_field":["test2"]})
|
|
assert len(res) == 0
|