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

Fix match_context tests in test_utils.py #2725

Merged
merged 5 commits into from
Jun 24, 2022
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
2 changes: 2 additions & 0 deletions haystack/utils/context_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def match_context(
finally:
if pool:
pool.close()
pool.join()


def match_contexts(
Expand Down Expand Up @@ -212,3 +213,4 @@ def match_contexts(
finally:
if pool:
pool.close()
pool.join()
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ install_requires =
elastic-apm

# context matching
rapidfuzz
rapidfuzz==2.0.13

# Schema validation
jsonschema
Expand Down
8 changes: 4 additions & 4 deletions test/others/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ def test_calculate_context_similarity_on_partially_overlapping_contexts_with_noi
assert accuracy > 0.99


def test_match_context():
whole_document = TEST_CONTEXT
def test_match_context_multi_process():
whole_document = TEST_CONTEXT[:300]
ZanSara marked this conversation as resolved.
Show resolved Hide resolved
min_length = 100
margin = 5
context_size = min_length + margin
for i in range(len(whole_document) - context_size):
partial_context = whole_document[i : i + context_size]
candidates = ((str(i), TEST_CONTEXT if i == 0 else TEST_CONTEXT_2) for i in range(10))
candidates = ((str(i), TEST_CONTEXT if i == 0 else TEST_CONTEXT_2) for i in range(1000))
ZanSara marked this conversation as resolved.
Show resolved Hide resolved
results = match_context(partial_context, candidates, min_length=min_length, num_processes=2)
assert len(results) == 1
id, score = results[0]
Expand All @@ -229,7 +229,7 @@ def test_match_context_single_process():
assert score == 100.0


def test_match_contexts():
def test_match_contexts_multi_process():
whole_document = TEST_CONTEXT
min_length = 100
margin = 5
Expand Down