| 829 | |
| 830 | def test_retrieve_report_evidence_ranks_expected_pdf_chunks(monkeypatch): |
| 831 | class FakeEmbeddingService: |
| 832 | descriptor = "fake:test:4" |
| 833 | |
| 834 | def embed_batch(self, texts): |
| 835 | vectors = [] |
| 836 | for text in texts: |
| 837 | lowered = text.lower() |
| 838 | background_score = float(sum(lowered.count(token) for token in ("background", "motivation", "challenge", "dataset shift"))) |
| 839 | method_score = float(sum(lowered.count(token) for token in ("method", "approach", "two-stage planner", "evidence retriever", "gating network"))) |
| 840 | results_score = float(sum(lowered.count(token) for token in ("results", "improves", "12%", "beats the baseline", "benchmark", "evaluation"))) |
| 841 | limitation_score = float(sum(lowered.count(token) for token in ("limitation", "limitations", "small number of domains", "future work"))) |
| 842 | vectors.append( |
| 843 | [ |
| 844 | background_score, |
| 845 | method_score, |
| 846 | results_score, |
| 847 | limitation_score, |
| 848 | ] |
| 849 | ) |
| 850 | return vectors |
| 851 | |
| 852 | @staticmethod |
| 853 | def cosine_similarity(vector1, vector2): |
| 854 | dot_product = sum(a * b for a, b in zip(vector1, vector2)) |
| 855 | norm1 = sum(a * a for a in vector1) ** 0.5 |
| 856 | norm2 = sum(b * b for b in vector2) ** 0.5 |
| 857 | if norm1 == 0 or norm2 == 0: |
| 858 | return 0.0 |
| 859 | return dot_product / (norm1 * norm2) |
| 860 | |
| 861 | class FakeEmbeddingModule: |
| 862 | @staticmethod |
no outgoing calls