Skip to content

knowledge_graph

diapason.tools.storage.knowledge_graph

Knowledge graph storage backend — entity-relation store with pattern queries.

Entity dataclass

A node in the knowledge graph.

GraphQueryResult dataclass

Result from a graph pattern query.

KnowledgeGraphMemory

SQLite-backed knowledge graph implementing MemoryBackend ABC.

Provides standard store/retrieve/delete/clear operations plus graph-specific operations: add_entity(), add_relation(), query_pattern(), neighbors().

add_entity(entity)

Add or update an entity.

add_relation(relation)

Add a relation between two entities.

clear()

Remove all entities and relations.

delete(key)

Delete an entity and its relations.

get_entity(entity_id)

Get entity by ID.

neighbors(entity_id, *, relation_type=None, direction='both', limit=50)

Get neighboring entities connected by relations.

query_pattern(*, entity_type=None, relation_type=None, limit=50)

Query entities and relations matching a pattern.

retrieve(key)

Retrieve content by entity_id (MemoryBackend interface).

search(query, top_k=5, **kwargs)

Search entities by name/type/content (MemoryBackend interface).

store(key, content, metadata=None)

Store content as an entity (MemoryBackend interface).

Relation dataclass

An edge between two entities.