scene_service.scene_graph.relations

Edge candidate generation and LLM-based relation inference.

Functions

compute_geometry_hint(a, b)

generate_edge_candidates(nodes, *[, ...])

Return candidate pairs with precomputed geometry hints.

Classes

RelationInferer(llm_client)

Infer the spatial relation between two objects via LLM.

class scene_service.scene_graph.relations.RelationInferer(llm_client: SceneGraphLLMClient)[source]

Bases: object

Infer the spatial relation between two objects via LLM.

async infer_relation(source: SceneGraphNode, target: SceneGraphNode, hint: GeometryHint) SceneGraphEdge[source]

Call LLM to infer the relation from source to target.

Returns a SceneGraphEdge. On LLM failure the edge has relation="unknown" and method="llm_fail".

async infer_semantic_relation(source: SceneGraphNode, target: SceneGraphNode, hint: GeometryHint, known_relation: str) SceneGraphEdge[source]

Semantic-only inference for a pair whose spatial relation geometry already owns (known_relation). The LLM is constrained to the semantic vocabulary; any spatial or off-vocabulary answer collapses to "none" (geometry stays authoritative for the spatial slot). On transport failure the edge is relation="unknown" / method="llm_fail" so the builder retries it like a rate-limited pair rather than caching a false “no semantic relation”.

scene_service.scene_graph.relations.compute_geometry_hint(a: SceneGraphNode, b: SceneGraphNode) GeometryHint[source]
scene_service.scene_graph.relations.generate_edge_candidates(nodes: list[SceneGraphNode], *, max_distance: float = 2.0, min_xy_overlap: float = 0.15, max_candidates: int = 200) list[tuple[SceneGraphNode, SceneGraphNode, GeometryHint]][source]

Return candidate pairs with precomputed geometry hints.

A pair is a candidate if any of these hold:
  • center distance < max_distance

  • XY overlap ratio > min_xy_overlap

  • one bbox contains the other