Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Elasticsearch] - BM25 retrieval: not all terms must mandatorily match #125

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _bm25_retrieval(
"query": query,
"fuzziness": fuzziness,
"type": "most_fields",
"operator": "AND",
"operator": "OR",
}
}
]
Expand Down
27 changes: 27 additions & 0 deletions integrations/elasticsearch/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,33 @@ def test_bm25_retrieval_with_fuzziness(self, document_store: ElasticsearchDocume
assert "functional" in res[1].content
assert "functional" in res[2].content

def test_bm25_not_all_terms_must_match(self, document_store: ElasticsearchDocumentStore):
"""
Test that not all terms must mandatorily match for BM25 retrieval to return a result.
"""
documents = [
Document(id=1, content="There are over 7,000 languages spoken around the world today."),
Document(
id=2,
content=(
"Elephants have been observed to behave in a way that indicates a high level of self-awareness"
" such as recognizing themselves in mirrors."
),
),
Document(
id=3,
content=(
"In certain parts of the world, like the Maldives, Puerto Rico, and San Diego, you can witness"
" the phenomenon of bioluminescent waves."
),
),
]
document_store.write_documents(documents)

res = document_store._bm25_retrieval("How much self awareness do elephants have?", top_k=3)
assert len(res) == 1
assert res[0].id == 2

def test_embedding_retrieval(self, document_store: ElasticsearchDocumentStore):
docs = [
Document(content="Most similar document", embedding=[1.0, 1.0, 1.0, 1.0]),
Expand Down