"""
Post-re-ingest sanity check for the multilingual switch.

Run this AFTER you've re-ingested with the new model:

    source .venv/bin/activate
    python3 test_multilingual.py

It runs a set of English questions (to confirm English retrieval did NOT regress)
and Spanish questions (to confirm Spanish now retrieves real material), printing
the top sources each one pulls. You're eyeballing two things:

  1. ENGLISH still works — e.g. the five-fold question should surface the FAQ,
     and book questions should surface the right books. If these look as good as
     before, the multilingual model didn't cost us English quality.
  2. SPANISH now retrieves — the Spanish questions should pull relevant Wayne
     material (not random chunks). The translations question should surface the
     International Translations page.

This only checks RETRIEVAL (what the guide is given). It does not call Claude, so
it costs nothing. Whether the guide then answers faithfully is governed by the
prompt + guide-notes + the always-on translations list.
"""

import rag

ENGLISH = [
    "What are Wayne's views on the five-fold ministries?",
    "What books has Wayne written?",
    "What is the book It's Time about?",
    "Tell me about A Man Like No Other.",
]

SPANISH = [
    "¿Qué libros de Wayne están disponibles en español?",
    "¿De qué trata el libro He Loves Me?",
    "¿Existe el podcast My Friend Luis en español?",
    "¿Qué enseña Wayne sobre vivir amado por el Padre?",
]


def show(label, questions, chunks, vectors):
    print("\n" + "=" * 70)
    print(label)
    print("=" * 70)
    for q in questions:
        hits = rag.retrieve(q, chunks, vectors)
        print(f"\nQ: {q}")
        for c, score in hits[:6]:
            name = c.get("book_title") or rag.display_name(c["source"])
            print(f"   {score:+.3f}  {name[:38]:38}  {c['text'][:50].replace(chr(10), ' ')}")


def main():
    print(f"Embedding model: {rag.LOCAL_MODEL}")
    chunks, vectors = rag.load_store()
    print(f"Store: {len(chunks):,} chunks")
    show("ENGLISH — should look as good as before (no regression)", ENGLISH, chunks, vectors)
    show("SPANISH — should now retrieve relevant Wayne material", SPANISH, chunks, vectors)
    print("\nDone. If English still surfaces the right sources and Spanish pulls "
          "relevant material, the switch is good.")


if __name__ == "__main__":
    main()
