Spaces:
Running
Running
Download tests/test_rerank.py from 9mark9/lethe-agent-memory: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/9mark9/lethe-agent-memory/resolve/main/tests/test_rerank.py
- Command line
-
hf download hf://spaces/9mark9/lethe-agent-memory/tests/test_rerank.py
-
curl -L -o test_rerank.py https://huggingface.co/spaces/9mark9/lethe-agent-memory/resolve/main/tests/test_rerank.py
1.33 kB
| """Tests for the cross-encoder reranker. Run from the Space root: python -m pytest tests. | |
| These need the sentence-transformers model; they are skipped when it cannot be loaded (offline). | |
| """ | |
| import pathlib | |
| import sys | |
| from dataclasses import dataclass | |
| import pytest | |
| ROOT = pathlib.Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| import rerank # noqa: E402 | |
| class Cand: | |
| text: str | |
| def _loaded(): | |
| try: | |
| rerank._model() | |
| except Exception as e: # noqa: BLE001 - offline or no model cache | |
| pytest.skip(f"cross-encoder not available: {e}") | |
| def test_shorter_than_two_is_unchanged(): | |
| assert rerank.rerank("anything", []) == [] | |
| one = [Cand("only one")] | |
| assert rerank.rerank("anything", one) == one | |
| def test_reranks_the_quarterly_review_weak_case(_loaded): | |
| # The embedding ranker puts the distractor first because it shares "quarterly review"; the | |
| # cross-encoder should lift the memory that answers who is presenting. | |
| answer = Cand("Marcus will present the fraud dashboard at the quarterly review.") | |
| distractor = Cand("The team agreed to ship the billing fix before the quarterly review.") | |
| out = rerank.rerank("Who is presenting at the quarterly review?", [distractor, answer]) | |
| assert out[0] is answer | |