"""Minimal usage example for the Hub snapshot. python examples/quickstart.py # local snapshot (repo root) python examples/quickstart.py # straight from the Hub """ from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) from modeling_megaram import load # noqa: E402 DOCS = [ { "ext_id": "bm25", "title": "BM25", "text": ( "BM25 is a bag-of-words retrieval function that ranks documents by query " "term frequency with saturation k1 and document length normalisation b. " "Typical values are k1 equal to 1.2 and b equal to 0.75." ), }, { "ext_id": "beir", "title": "BEIR", "text": ( "BEIR is a heterogeneous benchmark of 18 information retrieval datasets, " "introduced by Thakur, Reimers and Gurevych in 2021. It measures zero-shot " "retrieval with nDCG at 10." ), }, { "ext_id": "rgb", "title": "RGB", "text": ( "RGB tests noise robustness, negative rejection, information integration " "and counterfactual robustness in retrieval augmented generation." ), }, ] def main() -> int: target = sys.argv[1] if len(sys.argv) > 1 else str(ROOT) rag = load(target) print("loaded:", rag.info()) rag.index_documents(DOCS) for q in [ "What are the typical values of k1 and b in BM25?", "How many datasets does BEIR contain?", "Which benchmark tests negative rejection?", "What is the capital of France?", # answerable from no document ]: ans = rag.answer(q) print(f"\nQ: {q}") print(f" intent={ans.intent} conf={ans.confidence:.3f} abstained={ans.abstained}") print(f" A: {ans.text}") for c in ans.citations: print(f" [{c.doc_id}] {c.quote}") return 0 if __name__ == "__main__": raise SystemExit(main())