"""Optional Week 6 demo: real embeddings with sentence-transformers.

Only use this if the presenter already has the package/model available.
It may require internet/model downloads and is not necessary for the main session.
"""

from sentence_transformers import SentenceTransformer, util

chunks = [
    "Annual inflation was 4.4 percent in March 2026 according to the CPI release.",
    "Mobile phone ownership was 53.7 percent nationally in the ICT factsheet.",
    "The housing survey describes household conditions and access to services.",
    "Food and transport prices contributed to changes in consumer prices.",
]
query = "What was inflation in March 2026?"

model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
chunk_embeddings = model.encode(chunks, convert_to_tensor=True)
query_embedding = model.encode(query, convert_to_tensor=True)

scores = util.cos_sim(query_embedding, chunk_embeddings)[0]
for score, chunk in sorted(zip(scores, chunks), reverse=True):
    print(f"{float(score):.2f}  {chunk}")
