Skip to content

Graph store — EARS

Parent LLD: ./LLD.md

Models

  • [x] GRAPH-MODEL-001: The system shall provide Pydantic models Entity(name, label, properties), Relation(source, relation, target, properties), and ExtractedGraph(entities, relations).

  • [x] GRAPH-MODEL-002: RetrievedSubgraph shall expose entities, relations, and an LLM-ready text serialization of that subgraph.

Store interface

  • [x] GRAPH-STORE-001: AbstractGraphStore shall expose append, extend, retrieve, reset, and query(cypher, params=None).

  • [x] GRAPH-STORE-002: append shall accept one ExtractedGraph and upsert its entities and relations.

  • [x] GRAPH-STORE-003: extend shall accept a list of ExtractedGraph objects and upsert each in order.

  • [x] GRAPH-STORE-004: retrieve(query, n_results=10, hops=2) shall embed the query, select up to n_results seed entities by fusing vector similarity ranks with full-text ranks (reciprocal rank fusion), expand hops neighbors, and return a RetrievedSubgraph.

  • [x] GRAPH-STORE-006: When a relation endpoint name already exists in the store and is not listed in the same ExtractedGraph.entities, append shall reuse that node and shall not overwrite its properties.

  • [x] GRAPH-STORE-007: When a later ExtractedGraph includes a fully labeled entity whose name matches an auto-created stub (label=Entity), append shall move relations onto the labeled entity and remove the stub.

  • [x] GRAPH-STORE-005: reset shall remove stored entities and relations so a subsequent retrieve of a previous query returns an empty subgraph.

NetworkX backend

  • [x] GRAPH-NX-001: NetworkXGraphStore shall implement AbstractGraphStore in memory using networkx.

  • [x] GRAPH-NX-002: NetworkXGraphStore.query shall raise NotImplementedError because the backend has no Cypher engine.

Ladybug backend

  • [x] GRAPH-LB-001: LadybugGraphStore shall persist graphs with LadybugDB under ~/.llamabot/ladybug by default, using CREATE GRAPH {name} ANY and a typed Entity node table plus Relation rel table.

  • [x] GRAPH-LB-002: Importing LadybugGraphStore shall not import the ladybug package; constructing it without Ladybug installed shall raise ImportError that mentions pip install llamabot[graph].

  • [x] GRAPH-LB-003: Data appended to LadybugGraphStore shall be readable after closing the store and constructing a new instance with the same graph_name and storage_path. A further append on that reopened instance shall persist and be retrievable.

  • [x] GRAPH-LB-006: Constructing LadybugGraphStore on an existing database whose Entity.embedding width differs from the embedder shall raise ValueError naming both dimensions.

  • [x] GRAPH-LB-004: LadybugGraphStore.query shall execute parameterized Cypher on the named graph and return rows.

  • [x] GRAPH-LB-005: Where Ladybug vector or FTS extensions are unavailable, retrieve shall still rank stored embeddings in Python and match query tokens against entity text.

Extractor

  • [x] GRAPH-EXT-001: extract_graph(text, model_name=...) shall return an ExtractedGraph by calling StructuredBot with pydantic_model=ExtractedGraph.

  • [x] GRAPH-EXT-002: extract_graph shall accept an injected bot so tests can return a fixture graph without calling an LLM.

Packaging

  • [x] GRAPH-PKG-001: The optional extra llamabot[graph] shall install networkx, sentence-transformers, and Ladybug, matching LlamaBot’s requires-python of >=3.13,<3.15.

Verification

ID Tests / code
GRAPH-MODEL-001–002 tests/components/test_graphstore.py
GRAPH-STORE-001–007 tests/components/test_graphstore.py
GRAPH-NX-001–002 tests/components/test_graphstore.py
GRAPH-LB-001–006 tests/components/test_graphstore.py (Ladybug cases skip if not installed)
GRAPH-EXT-001–002 tests/components/test_graphstore.py
GRAPH-PKG-001 pyproject.toml