FOIA_Doc_Search / core /cluster.py
GodsDevProject's picture
Upload 20 files
5830944 verified
raw
history blame contribute delete
414 Bytes
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