Skip to main content

agrag.retrieval.methods.traversal.traverse

traverse(seed:SearchResult, *, graph_store:GraphStore, settings:RetrievalSettings, relation_type:str | None = None, direction:TraversalDirection = 'both', depth:int = 1, limit:int = 10, community_expand:bool = False, community_top_k:int = 3, filters:SearchFilters | None = None, tracer:Tracer | None = None) -> list[SearchResult]

Expand one resolved entity into its neighbours.

Parameters:

  • seed (SearchResult) – The resolved entity to expand from. A ResolvedEntity seed expands from its raw member ids, never its own id.
  • graph_store (GraphStore) – The graph to traverse.
  • settings (RetrievalSettings) – Retrieval configuration, carrying the BFS defaults this call's explicit arguments override.
  • relation_type (str | None) – Restrict the traversal to this single relationship type. None crosses every type the scope allows.
  • direction (TraversalDirection) – Which way a hop walks each relationship, relative to the seed entity.
  • depth (int) – Maximum hops. Clamped by the query builder.
  • limit (int) – Maximum neighbours returned.
  • community_expand (bool) – Also fuse in the reports of communities overlapping the seed, ranked by membership overlap.
  • community_top_k (int) – Maximum community reports to add when community_expand is set.
  • filters (SearchFilters | None) – Scope for the traversal. relation_types here is an immutable allowlist the caller set, not something a relation_type argument can widen: a request outside it is refused without querying the graph. properties document_ids, and labels constrain returned neighbour nodes.
  • tracer (Tracer | None) – Opens the root span and flows to the BFS retriever and community expansion. None opens no recorded span.

Returns:

  • list[SearchResult] – The neighbouring entities, deduplicated, highest-ranked first,
  • list[SearchResult] – with any requested community reports fused in.

Raises:

  • ScopeDeniedError – relation_type names a type the caller's scope does not permit.