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.0.tar.gz (112.7 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.0-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kaygee-0.1.0.tar.gz
  • Upload date:
  • Size: 112.7 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.0.tar.gz
Algorithm Hash digest
SHA256 f6789f6067e96803494e903799b11b152603eca786c99a8bb03302e35d30bae1
MD5 49b38301afdd8883a9acf9447a669f45
BLAKE2b-256 d844c13d903c06a96588e7840266c959021b2b3d3be65b60a5dae9187113efb8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kaygee-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4dc2d6e76f75716930a7a61d202c76ef656c23b379352725e47122dd8d9bb16e
MD5 b8fb4c20565aee8040de46e819622cea
BLAKE2b-256 5df013297cc9eee7c04c59fcb8b83217d0298a4b6d7b92cd9e7e2dae6e3cd658

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