← Lesson
RAG vs a Lookup Tool
Joeven
Run
Reset
Python loads on first run
INVOICES = {"INV-17": {"cents": 4000, "status": "open"}} WIKI = [ "Invoices are billed monthly. See billing.md for refunds.", "Refunds for INV-* take 5-7 days. Never cash.", ] def get_invoice(invoice_id): row = INVOICES.get(invoice_id) if row is None: return {"error": "not_found", "invoice_id": invoice_id} out = {"ok": True, "invoice_id": invoice_id} out.update(row) return out def rag_invoice(question): q = set(question.lower().split()) best = None best_n = 0 for text in WIKI: n = len(q & set(text.lower().split())) if n > best_n: best_n = n best = text return {"guess": best, "score": best_n} print("tool", get_invoice("INV-17")) print("rag ", rag_invoice("status of invoice INV-17")) print("tool miss", get_invoice("INV-99"))
Run to execute this in your browser. Nothing is sent to a server.