Spaces:
Sleeping
Sleeping
| from typing import List, Dict, Any, Tuple | |
| def retrieve(query: str, vstore, embedder, k: int) -> List[Tuple[str, float]]: | |
| return vstore.search(query, embedder, k=k) | |
| def format_citations(hits: List[Tuple[str, float]], max_items: int = 5) -> List[Dict[str, Any]]: | |
| out = [] | |
| for txt, score in hits[:max_items]: | |
| src = "unknown" | |
| if "[Source:" in txt: | |
| src = txt.split("[Source:")[-1].strip("] ").strip() | |
| out.append({"source": src, "score": round(score, 3)}) | |
| return out | |