from dataclasses import dataclass, field from .objectnode import ObjectNode from .roomnode import RoomNode @dataclass(frozen=True) class SceneGraphMatch: obj_id: str node: ObjectNode row_index: int score: int similarity: float hash_bytes: bytes @dataclass class SimpleSceneGraph: rooms: dict[str, RoomNode] = field(default_factory=dict) objects: dict[str, ObjectNode] = field(default_factory=dict) def query_by_visual_hash( self, query_hash_bytes: bytes, *, top_k: int = 1, ) -> list[SceneGraphMatch]: from .software_cam import SoftwareCamIndex index = SoftwareCamIndex.from_scene_graph(self) cam_matches = index.query(query_hash_bytes, top_k=top_k) return [ SceneGraphMatch( obj_id=match.obj_id, node=self.objects[match.obj_id], row_index=match.row_index, score=match.score, similarity=match.similarity, hash_bytes=match.hash_bytes, ) for match in cam_matches ]