Spaces:
Running on Zero
Running on Zero
Download scripts/eval_jev.py from denizkaya2022/IPARD-Vectorless-RAG: direct link, hf CLI and curl.
- Browser
- Download file 3.12 kB
-
https://huggingface.co/spaces/denizkaya2022/IPARD-Vectorless-RAG/resolve/main/scripts/eval_jev.py
- Command line
-
hf download hf://spaces/denizkaya2022/IPARD-Vectorless-RAG/scripts/eval_jev.py
-
curl -L -o eval_jev.py https://huggingface.co/spaces/denizkaya2022/IPARD-Vectorless-RAG/resolve/main/scripts/eval_jev.py
3.12 kB
| """Compare Jev with a frozen BM25 shortlist; no answer-model calls.""" | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| import agentic_rag as rag | |
| from jev_reranker import JevReranker | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--indices", default="2,19,21", help="1-based question indices") | |
| parser.add_argument("--questions", default="sorular.json") | |
| parser.add_argument("--freeze", default="eval_jev_candidates.json") | |
| parser.add_argument("--out", default="eval_jev_sonuc.json") | |
| parser.add_argument("--prepare-only", action="store_true") | |
| parser.add_argument("--frozen", action="store_true", help="Reuse saved candidates; do not retrieve again") | |
| args = parser.parse_args() | |
| ranker = JevReranker(enabled=True) | |
| if not args.prepare_only and not ranker.key: | |
| parser.error("OPENROUTER_API_KEY veya TYPESAFE_API_KEY gerekli; ortam degiskenine veya proje .env dosyasina ekle.") | |
| if args.frozen: | |
| blob = json.loads(Path(args.freeze).read_text(encoding="utf-8")) | |
| else: | |
| questions = json.loads(Path(args.questions).read_text(encoding="utf-8")) | |
| _, by_sid = rag.load_docs() | |
| rows = [] | |
| for index in [int(x) for x in args.indices.split(",")]: | |
| item = questions[index - 1] | |
| hits = rag.search_sections(item["q"], k=10) | |
| candidates = [] | |
| for hit in hits: | |
| candidates.append({"hit": hit, "preview": rag.jev_candidate(hit, by_sid)}) | |
| rows.append({"question_index": index, "q": item["q"], "candidates": candidates}) | |
| blob = {"tree_sha256": rag._sha256_file(Path(rag.TREE_PATH)), "rows": rows} | |
| Path(args.freeze).write_text(json.dumps(blob, ensure_ascii=False, indent=2), encoding="utf-8") | |
| if args.prepare_only: | |
| print(f"Sabit adaylar hazir: {args.freeze} ({len(blob['rows'])} soru); API cagrisi yok.") | |
| return | |
| output = {"model": ranker.model, "provider": ranker.provider, "tree_sha256": blob["tree_sha256"], "rows": []} | |
| for row in blob["rows"]: | |
| hits = [c["hit"] for c in row["candidates"]] | |
| previews = {(h["hit"]["sid"], h["hit"].get("nid"), h["hit"].get("page")): h["preview"] for h in row["candidates"]} | |
| def build(hit): | |
| return previews[(hit["sid"], hit.get("nid"), hit.get("page"))] | |
| ranked, info = ranker.rerank(row["q"], hits, build, measure=rag.query_measure(row["q"])) | |
| output["rows"].append({"q": row["q"], "bm25": hits, "jev": ranked, "trace": info}) | |
| print(f"Soru {row['question_index']}: {info['status']}; {info['calls']} cagri; {info.get('elapsed', 0)}s") | |
| Path(args.out).write_text(json.dumps(output, ensure_ascii=False, indent=2), encoding="utf-8") | |
| if any(r["trace"]["status"] != "ok" for r in output["rows"]): | |
| sys.exit("Jev siralamalarinin bir kismi basarisiz; bu sonuc basarili benchmark sayilamaz.") | |
| print(f"Sonuc: {args.out}. Bu deney siralamayi karsilastirir; cevap dogrulugunu olcmez.") | |
| if __name__ == "__main__": | |
| main() | |