CLI-first cognitive indexing pipeline
Project description
KnowledgeWeaver
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 markdownkw query-cognode: answer questions from Cognode markdown on diskkw index: compile Cognodes into Postgreskw query: query the Postgres compiled indexkw 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.yamland the generated Docker env file is written to~/.knowledgeweaver/docker-compose.env. - If your Ollama model names differ from the defaults, edit
~/.knowledgeweaver/kw.yamlafterkw config initso theextraction,query_*, andembeddingmodel entries match what you have installed locally. - Run the Docker command from the repo root so
docker-compose.postgres.ymlandDockerfile.postgresare 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:
- distill raw text into Cognodes
- save Cognodes as markdown
- query markdown directly with
kw query-cognodeor compile into Postgres withkw 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 forqueryandquery-cognode
Configuration
kw looks for config in this order:
--config <path>$KW_HOME/kw.yamlifKW_HOMEis set, otherwise~/.knowledgeweaver/kw.yaml./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:
ollamaopenai-compatibleanthropic
For each model under profiles.<name>.models.<key>, you usually set:
providermodelapi_base- one auth method:
api_key,api_key_env,oauth_token, oroauth_token_env - optional tuning fields such as
timeout_seconds,temperature,max_tokens, anddimensions
kw config show redacts inline secrets and DSN passwords before printing.
Notes
- Use
kw query-cognodewhen you want the markdown-only workflow. - Use
kw querywhen you want structure-first retrieval over the compiled Postgres index. - Rebuilding Postgres should never require editing Cognodes.
- Changing
kw_homemoves Cognodes, manifests, logs, and Docker helper files together.
Project Policy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce08d918ea4b7ebe9ae3f1b7f9009953771ee9a4d74c0890bfcf73e49cb9cb32
|
|
| MD5 |
070ece4866bb15e9e95098ac0ecef55a
|
|
| BLAKE2b-256 |
d7f9dfa5e96dd1fe610a96d8a5673daf0b7057cb7ceca07813a1941b91300399
|
Provenance
The following attestation bundles were made for knowledgeweaver-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on WattTonn/KnowledgeWeaver
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
knowledgeweaver-0.1.0.tar.gz -
Subject digest:
ce08d918ea4b7ebe9ae3f1b7f9009953771ee9a4d74c0890bfcf73e49cb9cb32 - Sigstore transparency entry: 1341627050
- Sigstore integration time:
-
Permalink:
WattTonn/KnowledgeWeaver@aa4edd9ad007190530bd2d6444a9e8b635614c58 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/WattTonn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@aa4edd9ad007190530bd2d6444a9e8b635614c58 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b745033e587247e68f9b8a3c8c05e815dd5760a891d0304d2aabdc865676f033
|
|
| MD5 |
c499aa92115c8e9e6db31cbee5480131
|
|
| BLAKE2b-256 |
23ec7ca6cb8a68e7f29adca935ebdaa01bb6ae5cdcb68177792c11e604aeb06e
|
Provenance
The following attestation bundles were made for knowledgeweaver-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on WattTonn/KnowledgeWeaver
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
knowledgeweaver-0.1.0-py3-none-any.whl -
Subject digest:
b745033e587247e68f9b8a3c8c05e815dd5760a891d0304d2aabdc865676f033 - Sigstore transparency entry: 1341627053
- Sigstore integration time:
-
Permalink:
WattTonn/KnowledgeWeaver@aa4edd9ad007190530bd2d6444a9e8b635614c58 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/WattTonn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@aa4edd9ad007190530bd2d6444a9e8b635614c58 -
Trigger Event:
release
-
Statement type: