Skip to main content

CLI-first cognitive indexing pipeline

Project description

KnowledgeWeaver

CI Python License Status

KnowledgeWeaver was inspired by Andrej Karpathy's LLM Wiki note — the idea that LLMs should compile sources into a persistent intermediate layer instead of re-reading raw text on every query. In KnowledgeWeaver, that intermediate layer is made of Cognodes: small, typed units of knowledge that stay readable on disk.

Why Cognodes

Most RAG systems chunk raw documents at query time. KnowledgeWeaver does the structure work up front: each source becomes a set of typed Cognodes such as concept, fact, experience, narrative, opinion, and known_unknown. Those units can point to each other through typed relations such as depends_on, instantiates, and evidences.

That gives you:

  • readable markdown you can grep, diff, and version
  • structure-first retrieval over typed fields and relations
  • a compiled Postgres index you can delete and rebuild from markdown at any time

See cognodes/examples/karpathy-llm-wiki for a worked example.

What You Can Do

  • kw distill: turn raw text or files into Cognode markdown
  • kw query-cognode: answer questions from Cognode markdown on disk
  • kw index: compile Cognodes into Postgres
  • kw query: query the Postgres compiled index
  • kw eval-distill: run YAML distillation evals

Quickstart

Option A: local CLI loop

Before you start, make sure you have:

  • Python 3.10+
  • Docker Desktop or Docker Engine with docker compose
  • Ollama installed and running at http://localhost:11434/v1
  • local Ollama models configured for both generation and embeddings

Notes:

  • The bundled Postgres setup is started through Docker, so you do not need to install Postgres separately if you use the commands below.
  • The default config is written to ~/.knowledgeweaver/kw.yaml and the generated Docker env file is written to ~/.knowledgeweaver/docker-compose.env.
  • If your Ollama model names differ from the defaults, edit ~/.knowledgeweaver/kw.yaml after kw config init so the extraction, query_*, and embedding model entries match what you have installed locally.
  • Run the Docker command from the repo root so docker-compose.postgres.yml and Dockerfile.postgres are available.
pip install .
kw config init
# edit ~/.knowledgeweaver/kw.yaml if you need different Ollama model names
kw config validate
# start the bundled pgvector/Postgres instance on port 55432
docker compose --env-file ~/.knowledgeweaver/docker-compose.env -f docker-compose.postgres.yml up -d --build
kw db init
kw distill --text "Revenue dropped by 4% in Q2 due to lower enterprise renewals."
kw query-cognode "What caused the Q2 revenue drop?"
kw index
kw query "What caused the Q2 revenue drop?"

The default config assumes:

  • Ollama at http://localhost:11434/v1
  • local Postgres credentials stored in ~/.knowledgeweaver/docker-compose.env
  • config at ~/.knowledgeweaver/kw.yaml

Option B: using with agents

Claude Code auto-registers the bundled skills under skills/cognode-distillation/ and skills/cognode-query/.

For Codex or other agents, point them at the skill files directly and keep the Cognode markdown as the canonical artifact. The intended workflow is still:

  1. distill raw text into Cognodes
  2. save Cognodes as markdown
  3. query markdown directly with kw query-cognode or compile into Postgres with kw index

Common Commands

Show config resolution:

kw config path
kw config show
kw config validate

Distill:

kw distill --input ./notes/article.txt
kw distill --text "Revenue dropped by 4% in Q2 due to lower enterprise renewals."
cat article.txt | kw distill --stdin
kw distill --input ./inbox --recursive

Query markdown directly:

kw query-cognode "What caused the Q2 revenue drop?"

Compile and query Postgres:

kw index
kw query "What caused the Q2 revenue drop?"
kw query "What caused the Q2 revenue drop?" --debug

Initialize Postgres schema explicitly:

kw db init
kw db init --profile postgres_local

Useful flags:

  • --config: use a non-default config file
  • --profile: select a profile from the config
  • --doc-id, --title, --author, --source-uri, --created-at: attach metadata during distillation
  • --top-k: control retrieval breadth for query and query-cognode

Configuration

kw looks for config in this order:

  1. --config <path>
  2. $KW_HOME/kw.yaml if KW_HOME is set, otherwise ~/.knowledgeweaver/kw.yaml
  3. ./kw.yaml

Inside the config, kw_home is the root for generated files:

  • ${kw_home}/cognodes
  • ${kw_home}/cognodes/manifests
  • ${kw_home}/logs
  • ${kw_home}/docker-compose.env

After changing kw_home, run kw config validate again so kw refreshes docker-compose.env.

Docker

This repo includes:

Start the bundled local Postgres:

kw config validate
docker compose --env-file ~/.knowledgeweaver/docker-compose.env -f docker-compose.postgres.yml up -d --build
kw db init

The bundled setup uses port 55432.

Providers

Supported provider styles:

  • ollama
  • openai-compatible
  • anthropic

For each model under profiles.<name>.models.<key>, you usually set:

  • provider
  • model
  • api_base
  • one auth method: api_key, api_key_env, oauth_token, or oauth_token_env
  • optional tuning fields such as timeout_seconds, temperature, max_tokens, and dimensions

kw config show redacts inline secrets and DSN passwords before printing.

Notes

  • Use kw query-cognode when you want the markdown-only workflow.
  • Use kw query when you want structure-first retrieval over the compiled Postgres index.
  • Rebuilding Postgres should never require editing Cognodes.
  • Changing kw_home moves Cognodes, manifests, logs, and Docker helper files together.

Project Policy

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

knowledgeweaver-0.1.0.tar.gz (124.7 kB view details)

Uploaded Source

Built Distribution

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

knowledgeweaver-0.1.0-py3-none-any.whl (134.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: knowledgeweaver-0.1.0.tar.gz
  • Upload date:
  • Size: 124.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for knowledgeweaver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ce08d918ea4b7ebe9ae3f1b7f9009953771ee9a4d74c0890bfcf73e49cb9cb32
MD5 070ece4866bb15e9e95098ac0ecef55a
BLAKE2b-256 d7f9dfa5e96dd1fe610a96d8a5673daf0b7057cb7ceca07813a1941b91300399

See more details on using hashes here.

Provenance

The following attestation bundles were made for knowledgeweaver-0.1.0.tar.gz:

Publisher: publish-pypi.yml on WattTonn/KnowledgeWeaver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: knowledgeweaver-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 134.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for knowledgeweaver-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b745033e587247e68f9b8a3c8c05e815dd5760a891d0304d2aabdc865676f033
MD5 c499aa92115c8e9e6db31cbee5480131
BLAKE2b-256 23ec7ca6cb8a68e7f29adca935ebdaa01bb6ae5cdcb68177792c11e604aeb06e

See more details on using hashes here.

Provenance

The following attestation bundles were made for knowledgeweaver-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on WattTonn/KnowledgeWeaver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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