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), andExtractedGraph(entities, relations). -
[x] GRAPH-MODEL-002:
RetrievedSubgraphshall exposeentities,relations, and an LLM-readytextserialization of that subgraph.
Store interface
-
[x] GRAPH-STORE-001:
AbstractGraphStoreshall exposeappend,extend,retrieve,reset, andquery(cypher, params=None). -
[x] GRAPH-STORE-002:
appendshall accept oneExtractedGraphand upsert its entities and relations. -
[x] GRAPH-STORE-003:
extendshall accept a list ofExtractedGraphobjects and upsert each in order. -
[x] GRAPH-STORE-004:
retrieve(query, n_results=10, hops=2)shall embed the query, select up ton_resultsseed entities by fusing vector similarity ranks with full-text ranks (reciprocal rank fusion), expandhopsneighbors, and return aRetrievedSubgraph. -
[x] GRAPH-STORE-006: When a relation endpoint name already exists in the store and is not listed in the same
ExtractedGraph.entities,appendshall reuse that node and shall not overwrite its properties. -
[x] GRAPH-STORE-007: When a later
ExtractedGraphincludes a fully labeled entity whose name matches an auto-created stub (label=Entity),appendshall move relations onto the labeled entity and remove the stub. -
[x] GRAPH-STORE-005:
resetshall remove stored entities and relations so a subsequent retrieve of a previous query returns an empty subgraph.
NetworkX backend
-
[x] GRAPH-NX-001:
NetworkXGraphStoreshall implementAbstractGraphStorein memory using networkx. -
[x] GRAPH-NX-002:
NetworkXGraphStore.queryshall raiseNotImplementedErrorbecause the backend has no Cypher engine.
Ladybug backend
-
[x] GRAPH-LB-001:
LadybugGraphStoreshall persist graphs with LadybugDB under~/.llamabot/ladybugby default, usingCREATE GRAPH {name} ANYand a typedEntitynode table plusRelationrel table. -
[x] GRAPH-LB-002: Importing
LadybugGraphStoreshall not import theladybugpackage; constructing it without Ladybug installed shall raiseImportErrorthat mentionspip install llamabot[graph]. -
[x] GRAPH-LB-003: Data appended to
LadybugGraphStoreshall be readable after closing the store and constructing a new instance with the samegraph_nameandstorage_path. A furtherappendon that reopened instance shall persist and be retrievable. -
[x] GRAPH-LB-006: Constructing
LadybugGraphStoreon an existing database whoseEntity.embeddingwidth differs from the embedder shall raiseValueErrornaming both dimensions. -
[x] GRAPH-LB-004:
LadybugGraphStore.queryshall execute parameterized Cypher on the named graph and return rows. -
[x] GRAPH-LB-005: Where Ladybug vector or FTS extensions are unavailable,
retrieveshall 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 anExtractedGraphby callingStructuredBotwithpydantic_model=ExtractedGraph. -
[x] GRAPH-EXT-002:
extract_graphshall accept an injectedbotso 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’srequires-pythonof>=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 |