Upload 4 files
Browse files
tests/__pycache__/test_rag_utils.cpython-313-pytest-9.0.2.pyc
ADDED
|
Binary file (6.58 kB). View file
|
|
|
tests/__pycache__/test_toy.cpython-313-pytest-9.0.2.pyc
ADDED
|
Binary file (3.9 kB). View file
|
|
|
tests/test_rag_utils.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from geomretrieval.rag_top10 import _minmax_hi, _zscore
|
| 3 |
+
|
| 4 |
+
def test_minmax_hi_is_bounded_and_monotone():
|
| 5 |
+
x=np.array([2.0,5.0,11.0],dtype=np.float32)
|
| 6 |
+
y=_minmax_hi(x)
|
| 7 |
+
assert np.allclose(y,[0.0,1/3,1.0])
|
| 8 |
+
|
| 9 |
+
def test_zscore_constant_is_zero():
|
| 10 |
+
assert np.allclose(_zscore(np.ones(4,dtype=np.float32)),0)
|
| 11 |
+
|
| 12 |
+
from geomretrieval import FrozenConfig, GeometricIndex, RAGTop10Config, RAGTop10Ranker
|
| 13 |
+
|
| 14 |
+
def test_rag_top10_ranker_runs_on_toy_index():
|
| 15 |
+
docs=[
|
| 16 |
+
'car automobile engine road vehicle',
|
| 17 |
+
'automobile vehicle insurance motor road',
|
| 18 |
+
'river bank flood erosion water',
|
| 19 |
+
'bank account credit loan interest',
|
| 20 |
+
'vitamin respiratory infection clinical study',
|
| 21 |
+
]
|
| 22 |
+
ids=[f'd{i}' for i in range(len(docs))]
|
| 23 |
+
idx=GeometricIndex.build(docs,ids,FrozenConfig(max_features=100,F=2,B=8,S=4,L=4,assoc_k=6,route_k=4,route_budget=6,rerank_pool=5,semantic_k=3,output_k=5),verbose=False)
|
| 24 |
+
ranker=RAGTop10Ranker(idx,RAGTop10Config(pool_size=5,semantic_k=3,hq_top_branches=3,branch_quality_top_docs=2))
|
| 25 |
+
out=ranker.search('automobile road insurance',k=3)
|
| 26 |
+
assert len(out)>=1
|
| 27 |
+
assert out[0] in {'d0','d1'}
|
tests/test_toy.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from geomretrieval import FrozenConfig, GeometricIndex, evaluate_run
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_toy_build_and_search():
|
| 5 |
+
docs = [
|
| 6 |
+
"car automobile engine road vehicle",
|
| 7 |
+
"automobile vehicle insurance motor road",
|
| 8 |
+
"river bank flood erosion water",
|
| 9 |
+
"bank account credit loan interest",
|
| 10 |
+
"vitamin d respiratory infection clinical study",
|
| 11 |
+
"random unrelated astronomy galaxy star",
|
| 12 |
+
]
|
| 13 |
+
ids = [f"d{i}" for i in range(len(docs))]
|
| 14 |
+
# Small toy corpus cannot support the production widths; keep the same
|
| 15 |
+
# architecture while mechanically reducing vocabulary-dependent dimensions.
|
| 16 |
+
cfg = FrozenConfig(
|
| 17 |
+
max_features=100,
|
| 18 |
+
F=2,
|
| 19 |
+
B=8,
|
| 20 |
+
S=4,
|
| 21 |
+
L=4,
|
| 22 |
+
assoc_k=6,
|
| 23 |
+
route_k=4,
|
| 24 |
+
route_budget=6,
|
| 25 |
+
rerank_pool=5,
|
| 26 |
+
semantic_k=3,
|
| 27 |
+
output_k=5,
|
| 28 |
+
)
|
| 29 |
+
idx = GeometricIndex.build(docs, ids, cfg, verbose=False)
|
| 30 |
+
out = idx.search("automobile road insurance", k=3)
|
| 31 |
+
assert 1 <= len(out) <= 3
|
| 32 |
+
assert out[0] in {"d0", "d1"}
|
| 33 |
+
|
| 34 |
+
run = {"q1": out}
|
| 35 |
+
qrels = {"q1": {"d0": 1.0, "d1": 1.0}}
|
| 36 |
+
m = evaluate_run(run, qrels, ks=(1, 3), ndcg_k=3, mrr_k=3)
|
| 37 |
+
assert m["Hit@1"] == 1.0
|
| 38 |
+
assert m["MRR@3"] == 1.0
|