import sys, os
# make sure local modules can be imported if you run from elsewhere
sys.path.append(os.path.dirname(__file__))

# load .env so the OpenAI key is available (recommended)
try:
    from dotenv import load_dotenv, find_dotenv
    load_dotenv(find_dotenv(), override=False)
except Exception:
    pass

from referenz_retrieval import find_matching_referenzstories

def show(query: str, tenant_id: int = 1):
    print(f"\n=== QUERY: {query} ===")
    matches = find_matching_referenzstories(query, tenant_id=tenant_id, top_k=2)
    for m in matches:
        print(f"\nStory: {m['title']}  (score={m['score']:.3f})")
        for s in m["sections"]:
            # show just the first 100 chars of each section’s HTML
            snippet = (s["content_html"] or "")[:100].replace("\n", " ")
            print(f" - {s['section']}: {snippet}...")

if __name__ == "__main__":
    show("Kommunikationsprobleme und fehlende Entscheidungen")
    show("Führungswechsel und mangelnde Unterstützung")

