knowledge_graph
knowledge_graph
¶
Knowledge graph storage backend — entity-relation store with pattern queries.
Classes¶
Entity
dataclass
¶
Entity(entity_id: str, entity_type: str, name: str, properties: Dict[str, Any] = dict(), created_at: float = 0.0)
A node in the knowledge graph.
Relation
dataclass
¶
Relation(source_id: str, target_id: str, relation_type: str, weight: float = 1.0, properties: Dict[str, Any] = dict(), created_at: float = 0.0)
An edge between two entities.
GraphQueryResult
dataclass
¶
Result from a graph pattern query.
KnowledgeGraphMemory
¶
KnowledgeGraphMemory(db_path: Union[str, Path] = DEFAULT_CONFIG_DIR / 'knowledge_graph.db', **kwargs: Any)
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().
Source code in src/openjarvis/tools/storage/knowledge_graph.py
Functions¶
store
¶
Store content as an entity (MemoryBackend interface).
Source code in src/openjarvis/tools/storage/knowledge_graph.py
retrieve
¶
Retrieve content by entity_id (MemoryBackend interface).
Source code in src/openjarvis/tools/storage/knowledge_graph.py
search
¶
Search entities by name/type/content (MemoryBackend interface).
Source code in src/openjarvis/tools/storage/knowledge_graph.py
delete
¶
Delete an entity and its relations.
Source code in src/openjarvis/tools/storage/knowledge_graph.py
clear
¶
add_entity
¶
add_entity(entity: Entity) -> None
Add or update an entity.
Source code in src/openjarvis/tools/storage/knowledge_graph.py
get_entity
¶
get_entity(entity_id: str) -> Optional[Entity]
Get entity by ID.
Source code in src/openjarvis/tools/storage/knowledge_graph.py
add_relation
¶
add_relation(relation: Relation) -> None
Add a relation between two entities.
Source code in src/openjarvis/tools/storage/knowledge_graph.py
neighbors
¶
neighbors(entity_id: str, *, relation_type: Optional[str] = None, direction: str = 'both', limit: int = 50) -> List[Entity]
Get neighboring entities connected by relations.
Source code in src/openjarvis/tools/storage/knowledge_graph.py
query_pattern
¶
query_pattern(*, entity_type: Optional[str] = None, relation_type: Optional[str] = None, limit: int = 50) -> GraphQueryResult
Query entities and relations matching a pattern.