File size: 414 Bytes
5830944
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
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