"""
Ask: a simple command-line chat against the ingested content.

    python ask.py

Type a question, get an answer grounded in Wayne's work with its source.
Ctrl-C to quit. Requires ANTHROPIC_API_KEY in the environment.
"""

import rag


def main():
    chunks, vectors = rag.load_store()
    print(f"Loaded {len(chunks)} chunks. Ask a question (Ctrl-C to quit).\n")
    while True:
        try:
            q = input("You: ").strip()
        except (EOFError, KeyboardInterrupt):
            print("\nGoodbye.")
            break
        if not q:
            continue
        hits = rag.retrieve(q, chunks, vectors)
        reply = rag.answer(q, hits)
        print(f"\nTrail Guide: {reply}\n")
        print("  (drew from: " + ", ".join(sorted({c['source'] for c, _ in hits})) + ")\n")


if __name__ == "__main__":
    main()
