agrag.retrieval.rerank.node_distance.node_distance_rerank
node_distance_rerank(results:list[SearchResult], *, graph_store:GraphStore, seed_ids:list[UUID], tracer:Tracer | None = None) -> list[SearchResult]
Rerank results by graph proximity to seed entity ids.
Uses shortest-path distance from each result entity to the closest seed entity. Entities closer to seeds rank higher. A ResolvedEntity item is measured by its closest raw member. Results without an entity item (chunks, relations) are placed at the end with a high distance penalty.
Parameters:
- results (
list[SearchResult]) – The fused results to rerank. - graph_store (
GraphStore) – The graph store for shortest-path queries. - seed_ids (
list[UUID]) – The seed entity ids to measure distance from. Seeds are the query's direct hits, not the whole candidate list: a candidate that is its own seed measures distance zero, so seeding with every candidate leaves the order unchanged. - tracer (
Tracer | None) – Opens the rerank span. None opens no recorded span.
Returns:
list[SearchResult]– Results reranked by proximity, closest first.
Raises:
Exception– Any error the graph store raises. A candidate with no path to a seed is not an error and ranks with the penalty.