Spaces:
Sleeping
Sleeping
| from typing import List, Dict | |
| from core.faiss_vector import FaissIndex | |
| def cluster_results(results: List[dict], k: int = 5) -> Dict[str, List[dict]]: | |
| texts = [r.get("snippet","") for r in results if r.get("snippet")] | |
| index = FaissIndex() | |
| index.add(texts) | |
| clusters = {} | |
| for r in results: | |
| key = r.get("source","Unknown") | |
| clusters.setdefault(key, []).append(r) | |
| return clusters |