Skip to main content

A flat, SQLite-native knowledge graph with YAML frontmatter and wikilinks

Project description

kaygee

Flat, SQLite-native knowledge graph for agent memory.

What it is

A knowledge graph stored in SQLite. Nodes have YAML frontmatter, link to each other with [[wikilinks]], and self-organize into typed tables. No schema upfront — it emerges from the data you write.

from kaygee import KnowledgeGraph

kg = KnowledgeGraph("brain.db")

kg.write("spreading-activation", """---
type: concept
description: How activation propagates through a network
tags: [cognition, search]
---
Follows [[agent-traversal]] paths and uses [[semantic-similarity]].""")

kg.write("turing", """---
type: person
role: researcher
born: 1912
---
Pioneered computation and [[agent-traversal]].""")

That's it. Types are tracked, links are resolved, backlinks work automatically.

Internally, all node data lives in a single _data table. A _type_fields table tracks which columns belong to which type. The nodes table is a thin index of name + type.

# Raw SQL is available when you need it
kg.query("SELECT name, description FROM _data WHERE name = ?", ("spreading-activation",))

Core operations

# Write and read
kg.write("name", "---\ntype: concept\n---\nBody text with [[links]].")
kg.cat("name")              # full content (frontmatter + body)
kg.body("name")             # body only
kg.frontmatter("name")      # metadata dict
kg.read("name", depth=1)    # this node + content of linked nodes

# Organize
kg.touch("name")             # create if not exists
kg.rm("name")                # delete
kg.mv("old", "new")          # rename
kg.cp("src", "dst")          # copy

# Search
kg.ls("concept")             # nodes of type
kg.find(name="activ.*")      # regex on names
kg.grep("pattern", content=True)  # regex across content
kg.tags()                    # {tag: [node, ...]} mapping

# Graph
kg.wikilinks("name")         # outgoing link targets
kg.backlinks("name")         # who links here
kg.graph()                   # full adjacency dict
kg.schema()                  # {type: [fields]} across all types

# Raw SQL
kg.query("SELECT name FROM nodes WHERE type = ?", ("concept",))

Changelog

Every mutation is recorded in an append-only changelog (enabled by default). This drives delta sync and audit trails.

kg = KnowledgeGraph("brain.db")  # changelog=True by default

kg.write("sa", "---\ntype: concept\n---\nSpreading activation.")
kg.rm("sa")

entries = kg.changelog(since_seq=0, limit=100)
# [(1, '2026-...', 'node.write', 'sa', '{"type": "concept", ...}'),
#  (2, '2026-...', 'node.rm',    'sa', '{"type": "concept"}')]

kg.changelog_truncate(before_seq=2)  # prune old entries

Operations logged: node.write, node.rm, node.mv, node.cp, node.type_change, type.add, type.rm.

Disable with KnowledgeGraph("brain.db", changelog=False) if you don't need it.

Sync

Push local changes to a remote MySQL database, scoped by team/user/project. Pull to replicate back.

from kaygee import sync_push, sync_pull

# Push changelog deltas to MySQL (only changed rows sent)
last_seq = sync_push(kg, mysql_conn, scope={"team_id": "eng"}, since_seq=0)
# Persist last_seq for next call

# Pull all rows matching scope from MySQL into local SQLite
count = sync_pull(kg, mysql_conn, scope={"team_id": "eng"})
  • Push replays changelog entries — upserts and deletes flow through, including type changes and renames.
  • Pull is a full pull filtered by scope. Writes bypass the changelog to avoid push-back loops.
  • Falls back to full-table-scan push when changelog is disabled (deletes not propagated in this mode).

Constraints

Free-form by default. Add structure when you want it.

from kaygee import Validator, freeze_schema, requires_field, requires_link, no_orphans

v = Validator()
v.add(freeze_schema("concept", ["description", "tags"]))
v.add(requires_field("concept", "description"))
v.add(requires_link("paper", target_type="person"))
v.add(no_orphans())

v.check(kg)          # raises ValidationError with all violations
kg.set_validator(v)  # gatekeeper: blocks invalid writes before they persist

Shell

from kaygee import GraphShell

sh = GraphShell(kg)
sh.run("touch", ["neuron", "---\ntype: concept\n---\nA unit of [[computation]]."])
sh.run("ls", ["concept"])
sh.run("links", ["neuron"])
sh.execute("cat neuron | grep computation")

Visualization

from kaygee import visualize

visualize(kg, path="graph.html")  # self-contained interactive HTML

Install

pip install kaygee

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaygee-0.1.1.tar.gz (114.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kaygee-0.1.1-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file kaygee-0.1.1.tar.gz.

File metadata

  • Download URL: kaygee-0.1.1.tar.gz
  • Upload date:
  • Size: 114.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for kaygee-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1b88e3eff881eb6a5cfcfbfca95e6693677e37aad31148ab63bc5f768db1f727
MD5 191de318db81945a4848df5eae0a49c5
BLAKE2b-256 aa36d104a6ae3177fd85d176014db8f973477192b4646d88b65225cc93840ce1

See more details on using hashes here.

File details

Details for the file kaygee-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kaygee-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for kaygee-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e0255eb73b4d72d54e6294be5d22c199b7cff2b2e3f6ba293eca977cf7980db
MD5 9d47e163f0c4df9aeecb8284a9b0ba4d
BLAKE2b-256 19a570b11fbf13fcad2d0d91335537504ac611fc84ec5e0e94c3a15ffd205f98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page