KnowledgeGraph
SQLite-backed knowledge graph with nodes, edges, and optional embeddings.
Usage
KnowledgeGraph()Stores documents, entities, and topics as nodes connected by typed, weighted edges. Supports text search, neighbor traversal, and optional vector embeddings for similarity search.
Parameters
path: str | Path = ":memory:"-
Path to the SQLite database file. Use
":memory:"for an in-memory graph (useful for testing).
Examples
Create a graph and add nodes:
import talk_box as tb
kg = tb.KnowledgeGraph(":memory:")
kg.add_node(tb.Node(
id="doc-1",
node_type=tb.NodeType.DOCUMENT,
name="README.md",
content="# Talk Box\nAI assistant framework.",
))
kg.add_node(tb.Node(
id="entity-tb",
node_type=tb.NodeType.ENTITY,
name="Talk Box",
))
kg.add_edge(tb.Edge(
source="doc-1",
target="entity-tb",
relation="mentions",
))
neighbors = kg.neighbors("doc-1")
neighbors[0].name # "Talk Box"Search nodes by text:
results = kg.search("Talk Box")
results[0].name # "Talk Box"