kipp-memory 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kipp_memory-0.1.0/LICENSE +21 -0
- kipp_memory-0.1.0/PKG-INFO +190 -0
- kipp_memory-0.1.0/README.md +160 -0
- kipp_memory-0.1.0/pyproject.toml +47 -0
- kipp_memory-0.1.0/setup.cfg +4 -0
- kipp_memory-0.1.0/src/kipp/__init__.py +1 -0
- kipp_memory-0.1.0/src/kipp/backup.py +155 -0
- kipp_memory-0.1.0/src/kipp/cli.py +753 -0
- kipp_memory-0.1.0/src/kipp/client.py +516 -0
- kipp_memory-0.1.0/src/kipp/embedder.py +59 -0
- kipp_memory-0.1.0/src/kipp/evaluate.py +209 -0
- kipp_memory-0.1.0/src/kipp/export.py +106 -0
- kipp_memory-0.1.0/src/kipp/extract.py +318 -0
- kipp_memory-0.1.0/src/kipp/facts.py +255 -0
- kipp_memory-0.1.0/src/kipp/maintenance.py +164 -0
- kipp_memory-0.1.0/src/kipp/mcp_server.py +507 -0
- kipp_memory-0.1.0/src/kipp/merge.py +273 -0
- kipp_memory-0.1.0/src/kipp/models.py +78 -0
- kipp_memory-0.1.0/src/kipp/pipeline.py +164 -0
- kipp_memory-0.1.0/src/kipp/repair.py +162 -0
- kipp_memory-0.1.0/src/kipp/search.py +275 -0
- kipp_memory-0.1.0/src/kipp/split.py +678 -0
- kipp_memory-0.1.0/src/kipp_memory.egg-info/PKG-INFO +190 -0
- kipp_memory-0.1.0/src/kipp_memory.egg-info/SOURCES.txt +44 -0
- kipp_memory-0.1.0/src/kipp_memory.egg-info/dependency_links.txt +1 -0
- kipp_memory-0.1.0/src/kipp_memory.egg-info/entry_points.txt +2 -0
- kipp_memory-0.1.0/src/kipp_memory.egg-info/requires.txt +6 -0
- kipp_memory-0.1.0/src/kipp_memory.egg-info/top_level.txt +1 -0
- kipp_memory-0.1.0/tests/test_backup.py +163 -0
- kipp_memory-0.1.0/tests/test_cli_domain.py +100 -0
- kipp_memory-0.1.0/tests/test_cli_extract.py +128 -0
- kipp_memory-0.1.0/tests/test_client.py +139 -0
- kipp_memory-0.1.0/tests/test_dismiss.py +95 -0
- kipp_memory-0.1.0/tests/test_embedder.py +55 -0
- kipp_memory-0.1.0/tests/test_evaluate.py +175 -0
- kipp_memory-0.1.0/tests/test_export.py +196 -0
- kipp_memory-0.1.0/tests/test_extract.py +296 -0
- kipp_memory-0.1.0/tests/test_facts.py +499 -0
- kipp_memory-0.1.0/tests/test_maintenance.py +217 -0
- kipp_memory-0.1.0/tests/test_mcp_server.py +460 -0
- kipp_memory-0.1.0/tests/test_merge.py +471 -0
- kipp_memory-0.1.0/tests/test_pipeline.py +189 -0
- kipp_memory-0.1.0/tests/test_repair.py +286 -0
- kipp_memory-0.1.0/tests/test_search.py +89 -0
- kipp_memory-0.1.0/tests/test_split.py +1007 -0
- kipp_memory-0.1.0/tests/test_threshold_tuning.py +79 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sarbloc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kipp-memory
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Entity-based persistent memory with semantic search for AI agents
|
|
5
|
+
Author: Sarbloc
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/sarbloc/kipp
|
|
8
|
+
Project-URL: Documentation, https://github.com/sarbloc/kipp/tree/main/docs
|
|
9
|
+
Project-URL: Issues, https://github.com/sarbloc/kipp/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/sarbloc/kipp/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: memory,ai-agents,mcp,qdrant,embeddings,semantic-search
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: qdrant-client<2,>=1.12
|
|
24
|
+
Requires-Dist: sentence-transformers>=3.0
|
|
25
|
+
Requires-Dist: click>=8.0
|
|
26
|
+
Requires-Dist: httpx>=0.25
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Requires-Dist: mcp<2,>=1.0
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
<h1 align="center">
|
|
32
|
+
<picture>
|
|
33
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/brand/kipp-logo-dark.svg">
|
|
34
|
+
<img src="https://raw.githubusercontent.com/sarbloc/kipp/main/docs/brand/kipp-logo.svg" alt="KIPP" width="360">
|
|
35
|
+
</picture>
|
|
36
|
+
</h1>
|
|
37
|
+
|
|
38
|
+
Memory for AI agents that keeps one current record per thing, not an
|
|
39
|
+
ever-growing log. Local, deterministic, no LLM in the loop.
|
|
40
|
+
|
|
41
|
+
- **One record per thing.** Knowledge lives in entities (`person:alice`,
|
|
42
|
+
`project:billing`) whose facts are updated in place. Storage grows with the
|
|
43
|
+
number of distinct things your agent knows about, not with time.
|
|
44
|
+
- **Found by any fact.** Every fact is indexed on its own, so a large entity
|
|
45
|
+
still comes up for the one fact that matches. There is no size cap: past 30
|
|
46
|
+
facts, KIPP suggests splitting an entity into topic entities.
|
|
47
|
+
- **History kept.** A replaced fact is marked superseded, not deleted, so you
|
|
48
|
+
can ask what was true on a past date.
|
|
49
|
+
- **Local and deterministic.** Qdrant in Docker plus a small local embedding
|
|
50
|
+
model. Merge, dedup, compaction and expiry are plain maths: no API calls, no
|
|
51
|
+
LLM, same input gives the same result.
|
|
52
|
+
- **Works with any MCP client.** Claude Code, Claude Desktop, Cursor, Codex
|
|
53
|
+
CLI, or anything else that speaks MCP over stdio.
|
|
54
|
+
|
|
55
|
+
## How it works
|
|
56
|
+
|
|
57
|
+
Your agent does two things with KIPP during a conversation:
|
|
58
|
+
|
|
59
|
+
1. **Recalls** with `memory_search` before answering questions about people,
|
|
60
|
+
projects or past decisions.
|
|
61
|
+
2. **Records** what it learns, either straight onto an entity with
|
|
62
|
+
`memory_store`, or as a raw observation with `memory_event`.
|
|
63
|
+
|
|
64
|
+
Events are a 30-day inbox. A periodic **extraction** pass files them onto
|
|
65
|
+
entities. Events that open with a `[type:id]` tag are filed automatically. The
|
|
66
|
+
rest are reviewed by an agent, which creates the entities they describe. KIPP
|
|
67
|
+
never invents entities on its own; that judgement stays with the agent.
|
|
68
|
+
|
|
69
|
+
[`docs/agent-guide.md`](https://github.com/sarbloc/kipp/blob/main/docs/agent-guide.md) has the prompt that teaches an
|
|
70
|
+
agent this loop.
|
|
71
|
+
|
|
72
|
+
## Requirements
|
|
73
|
+
|
|
74
|
+
- Docker (for Qdrant)
|
|
75
|
+
- Python 3.11+ and [pipx](https://pipx.pypa.io/)
|
|
76
|
+
- About 1 GB of disk to start: the Qdrant image plus the embedding model
|
|
77
|
+
(`all-MiniLM-L6-v2`, about 90 MB, downloaded from Hugging Face on first use)
|
|
78
|
+
|
|
79
|
+
Developed and run on Linux. macOS should work. On Windows, use WSL.
|
|
80
|
+
|
|
81
|
+
## Quick start
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
git clone https://github.com/sarbloc/kipp.git
|
|
85
|
+
cd kipp
|
|
86
|
+
|
|
87
|
+
# 1. Start Qdrant (localhost only, data in a named Docker volume)
|
|
88
|
+
docker compose up -d --wait
|
|
89
|
+
|
|
90
|
+
# 2. Install the CLI and MCP server
|
|
91
|
+
# (if `kipp` is then "command not found", run `pipx ensurepath` and open a new shell)
|
|
92
|
+
pipx install .
|
|
93
|
+
|
|
94
|
+
# 3. Create the collections
|
|
95
|
+
kipp init
|
|
96
|
+
|
|
97
|
+
# 4. Smoke test. The first command downloads the embedding model.
|
|
98
|
+
kipp store --type person --id alice --content "Leads the billing team"
|
|
99
|
+
kipp search "who runs billing"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`kipp search` should print `person:alice` as the top hit. A warning about
|
|
103
|
+
unauthenticated requests to the HF Hub is harmless: the model is public, and
|
|
104
|
+
once it's cached nothing is downloaded again.
|
|
105
|
+
|
|
106
|
+
Then:
|
|
107
|
+
|
|
108
|
+
5. **Connect your AI client:** [`docs/mcp-clients.md`](https://github.com/sarbloc/kipp/blob/main/docs/mcp-clients.md)
|
|
109
|
+
6. **Teach your agent to use it:** [`docs/agent-guide.md`](https://github.com/sarbloc/kipp/blob/main/docs/agent-guide.md)
|
|
110
|
+
7. **Set up expiry and backups:** [`docs/operations.md`](https://github.com/sarbloc/kipp/blob/main/docs/operations.md)
|
|
111
|
+
|
|
112
|
+
`scripts/install.sh` does steps 1–3 in one go, reusing a Qdrant that is
|
|
113
|
+
already running on port 6333.
|
|
114
|
+
|
|
115
|
+
### Without cloning
|
|
116
|
+
|
|
117
|
+
KIPP is on PyPI as [`kipp-memory`](https://pypi.org/project/kipp-memory/).
|
|
118
|
+
Start Qdrant yourself, then install and initialise:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
docker run -d --name kipp-qdrant --restart unless-stopped \
|
|
122
|
+
-p 127.0.0.1:6333:6333 -v kipp_qdrant:/qdrant/storage qdrant/qdrant:v1.20.0
|
|
123
|
+
pipx install kipp-memory
|
|
124
|
+
kipp init
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Docs
|
|
128
|
+
|
|
129
|
+
| Page | What it covers |
|
|
130
|
+
|------|----------------|
|
|
131
|
+
| [mcp-clients.md](https://github.com/sarbloc/kipp/blob/main/docs/mcp-clients.md) | Registering `kipp mcp` in Claude Code, Claude Desktop, Cursor, Codex CLI |
|
|
132
|
+
| [agent-guide.md](https://github.com/sarbloc/kipp/blob/main/docs/agent-guide.md) | System-prompt section, tools, tags, domains, the extraction loop |
|
|
133
|
+
| [operations.md](https://github.com/sarbloc/kipp/blob/main/docs/operations.md) | Configuration, expiry, compaction, backup and restore, systemd timers |
|
|
134
|
+
| [CHANGELOG.md](https://github.com/sarbloc/kipp/blob/main/CHANGELOG.md) | What changed in each release |
|
|
135
|
+
| [MEMORY-SYSTEM-SPEC.md](https://github.com/sarbloc/kipp/blob/main/MEMORY-SYSTEM-SPEC.md) | The original design spec |
|
|
136
|
+
|
|
137
|
+
## Architecture
|
|
138
|
+
|
|
139
|
+
- **Qdrant** stores twelve collections: three **domains** (`shared`, `dev`,
|
|
140
|
+
`personal`) × four **kinds**:
|
|
141
|
+
- `entities`: long-term knowledge, upserted in place;
|
|
142
|
+
- `events`: raw observations, expire after 30 days;
|
|
143
|
+
- `decisions`: like entities, but never expire;
|
|
144
|
+
- `facts`: the search index, one point per fact, rebuilt from entities by
|
|
145
|
+
`kipp reindex`.
|
|
146
|
+
- **Search** scores each entity by the better of its own vector and its best
|
|
147
|
+
matching fact, fused with a keyword match. Each hit returns its best facts
|
|
148
|
+
up to a word budget.
|
|
149
|
+
- **all-MiniLM-L6-v2** embeds text locally (384 dimensions).
|
|
150
|
+
- **Merge:** a new fact within cosine 0.9 of an existing one is a duplicate. The
|
|
151
|
+
existing fact's hit count goes up and the longer wording wins. Anything else
|
|
152
|
+
is appended.
|
|
153
|
+
- **No fact cap:** every fact is searched on its own, so entities can grow.
|
|
154
|
+
Past 30 current facts, writes return an `oversized` note suggesting a split
|
|
155
|
+
into topic entities (`kipp oversized` lists them; `kipp split-plan` and
|
|
156
|
+
`kipp split-apply` do the split, and children point at their `parent`).
|
|
157
|
+
`kipp compact` can trim to the top 20 by frequency × recency × permanence,
|
|
158
|
+
but it deletes facts and nothing runs it.
|
|
159
|
+
|
|
160
|
+
The `shared` domain uses the bare collection names (`entities`, `events`,
|
|
161
|
+
`decisions`, `facts`); the others are prefixed (`dev_entities`, ...).
|
|
162
|
+
MCP tools and most CLI commands take a domain, defaulting to `shared`;
|
|
163
|
+
`export` and `import` cover `shared` only.
|
|
164
|
+
|
|
165
|
+
## Upgrading from entity-memory
|
|
166
|
+
|
|
167
|
+
KIPP was called `entity-memory`. The pip distribution changed name, so pipx
|
|
168
|
+
treats it as a new app:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
pipx uninstall entity-memory
|
|
172
|
+
pipx install -e . # provides the `kipp` command
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`scripts/install.sh` does this for you. The old `memory` command is gone: call
|
|
176
|
+
`kipp` instead. The old config paths and `ENTITY_MEMORY_CONFIG` still work.
|
|
177
|
+
Qdrant data and collection names are unchanged. To move installed systemd timers to the new unit names,
|
|
178
|
+
see [`docs/operations.md`](https://github.com/sarbloc/kipp/blob/main/docs/operations.md#systemd-timers).
|
|
179
|
+
|
|
180
|
+
## OpenClaw
|
|
181
|
+
|
|
182
|
+
`skill/SKILL.md` is the OpenClaw skill manifest. Install with
|
|
183
|
+
`bash scripts/install.sh`.
|
|
184
|
+
|
|
185
|
+
## Development
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
pip install -e .
|
|
189
|
+
python3 -m pytest -q # in-memory Qdrant and a mock embedder: no services needed
|
|
190
|
+
```
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/brand/kipp-logo-dark.svg">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/sarbloc/kipp/main/docs/brand/kipp-logo.svg" alt="KIPP" width="360">
|
|
5
|
+
</picture>
|
|
6
|
+
</h1>
|
|
7
|
+
|
|
8
|
+
Memory for AI agents that keeps one current record per thing, not an
|
|
9
|
+
ever-growing log. Local, deterministic, no LLM in the loop.
|
|
10
|
+
|
|
11
|
+
- **One record per thing.** Knowledge lives in entities (`person:alice`,
|
|
12
|
+
`project:billing`) whose facts are updated in place. Storage grows with the
|
|
13
|
+
number of distinct things your agent knows about, not with time.
|
|
14
|
+
- **Found by any fact.** Every fact is indexed on its own, so a large entity
|
|
15
|
+
still comes up for the one fact that matches. There is no size cap: past 30
|
|
16
|
+
facts, KIPP suggests splitting an entity into topic entities.
|
|
17
|
+
- **History kept.** A replaced fact is marked superseded, not deleted, so you
|
|
18
|
+
can ask what was true on a past date.
|
|
19
|
+
- **Local and deterministic.** Qdrant in Docker plus a small local embedding
|
|
20
|
+
model. Merge, dedup, compaction and expiry are plain maths: no API calls, no
|
|
21
|
+
LLM, same input gives the same result.
|
|
22
|
+
- **Works with any MCP client.** Claude Code, Claude Desktop, Cursor, Codex
|
|
23
|
+
CLI, or anything else that speaks MCP over stdio.
|
|
24
|
+
|
|
25
|
+
## How it works
|
|
26
|
+
|
|
27
|
+
Your agent does two things with KIPP during a conversation:
|
|
28
|
+
|
|
29
|
+
1. **Recalls** with `memory_search` before answering questions about people,
|
|
30
|
+
projects or past decisions.
|
|
31
|
+
2. **Records** what it learns, either straight onto an entity with
|
|
32
|
+
`memory_store`, or as a raw observation with `memory_event`.
|
|
33
|
+
|
|
34
|
+
Events are a 30-day inbox. A periodic **extraction** pass files them onto
|
|
35
|
+
entities. Events that open with a `[type:id]` tag are filed automatically. The
|
|
36
|
+
rest are reviewed by an agent, which creates the entities they describe. KIPP
|
|
37
|
+
never invents entities on its own; that judgement stays with the agent.
|
|
38
|
+
|
|
39
|
+
[`docs/agent-guide.md`](https://github.com/sarbloc/kipp/blob/main/docs/agent-guide.md) has the prompt that teaches an
|
|
40
|
+
agent this loop.
|
|
41
|
+
|
|
42
|
+
## Requirements
|
|
43
|
+
|
|
44
|
+
- Docker (for Qdrant)
|
|
45
|
+
- Python 3.11+ and [pipx](https://pipx.pypa.io/)
|
|
46
|
+
- About 1 GB of disk to start: the Qdrant image plus the embedding model
|
|
47
|
+
(`all-MiniLM-L6-v2`, about 90 MB, downloaded from Hugging Face on first use)
|
|
48
|
+
|
|
49
|
+
Developed and run on Linux. macOS should work. On Windows, use WSL.
|
|
50
|
+
|
|
51
|
+
## Quick start
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
git clone https://github.com/sarbloc/kipp.git
|
|
55
|
+
cd kipp
|
|
56
|
+
|
|
57
|
+
# 1. Start Qdrant (localhost only, data in a named Docker volume)
|
|
58
|
+
docker compose up -d --wait
|
|
59
|
+
|
|
60
|
+
# 2. Install the CLI and MCP server
|
|
61
|
+
# (if `kipp` is then "command not found", run `pipx ensurepath` and open a new shell)
|
|
62
|
+
pipx install .
|
|
63
|
+
|
|
64
|
+
# 3. Create the collections
|
|
65
|
+
kipp init
|
|
66
|
+
|
|
67
|
+
# 4. Smoke test. The first command downloads the embedding model.
|
|
68
|
+
kipp store --type person --id alice --content "Leads the billing team"
|
|
69
|
+
kipp search "who runs billing"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`kipp search` should print `person:alice` as the top hit. A warning about
|
|
73
|
+
unauthenticated requests to the HF Hub is harmless: the model is public, and
|
|
74
|
+
once it's cached nothing is downloaded again.
|
|
75
|
+
|
|
76
|
+
Then:
|
|
77
|
+
|
|
78
|
+
5. **Connect your AI client:** [`docs/mcp-clients.md`](https://github.com/sarbloc/kipp/blob/main/docs/mcp-clients.md)
|
|
79
|
+
6. **Teach your agent to use it:** [`docs/agent-guide.md`](https://github.com/sarbloc/kipp/blob/main/docs/agent-guide.md)
|
|
80
|
+
7. **Set up expiry and backups:** [`docs/operations.md`](https://github.com/sarbloc/kipp/blob/main/docs/operations.md)
|
|
81
|
+
|
|
82
|
+
`scripts/install.sh` does steps 1–3 in one go, reusing a Qdrant that is
|
|
83
|
+
already running on port 6333.
|
|
84
|
+
|
|
85
|
+
### Without cloning
|
|
86
|
+
|
|
87
|
+
KIPP is on PyPI as [`kipp-memory`](https://pypi.org/project/kipp-memory/).
|
|
88
|
+
Start Qdrant yourself, then install and initialise:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
docker run -d --name kipp-qdrant --restart unless-stopped \
|
|
92
|
+
-p 127.0.0.1:6333:6333 -v kipp_qdrant:/qdrant/storage qdrant/qdrant:v1.20.0
|
|
93
|
+
pipx install kipp-memory
|
|
94
|
+
kipp init
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Docs
|
|
98
|
+
|
|
99
|
+
| Page | What it covers |
|
|
100
|
+
|------|----------------|
|
|
101
|
+
| [mcp-clients.md](https://github.com/sarbloc/kipp/blob/main/docs/mcp-clients.md) | Registering `kipp mcp` in Claude Code, Claude Desktop, Cursor, Codex CLI |
|
|
102
|
+
| [agent-guide.md](https://github.com/sarbloc/kipp/blob/main/docs/agent-guide.md) | System-prompt section, tools, tags, domains, the extraction loop |
|
|
103
|
+
| [operations.md](https://github.com/sarbloc/kipp/blob/main/docs/operations.md) | Configuration, expiry, compaction, backup and restore, systemd timers |
|
|
104
|
+
| [CHANGELOG.md](https://github.com/sarbloc/kipp/blob/main/CHANGELOG.md) | What changed in each release |
|
|
105
|
+
| [MEMORY-SYSTEM-SPEC.md](https://github.com/sarbloc/kipp/blob/main/MEMORY-SYSTEM-SPEC.md) | The original design spec |
|
|
106
|
+
|
|
107
|
+
## Architecture
|
|
108
|
+
|
|
109
|
+
- **Qdrant** stores twelve collections: three **domains** (`shared`, `dev`,
|
|
110
|
+
`personal`) × four **kinds**:
|
|
111
|
+
- `entities`: long-term knowledge, upserted in place;
|
|
112
|
+
- `events`: raw observations, expire after 30 days;
|
|
113
|
+
- `decisions`: like entities, but never expire;
|
|
114
|
+
- `facts`: the search index, one point per fact, rebuilt from entities by
|
|
115
|
+
`kipp reindex`.
|
|
116
|
+
- **Search** scores each entity by the better of its own vector and its best
|
|
117
|
+
matching fact, fused with a keyword match. Each hit returns its best facts
|
|
118
|
+
up to a word budget.
|
|
119
|
+
- **all-MiniLM-L6-v2** embeds text locally (384 dimensions).
|
|
120
|
+
- **Merge:** a new fact within cosine 0.9 of an existing one is a duplicate. The
|
|
121
|
+
existing fact's hit count goes up and the longer wording wins. Anything else
|
|
122
|
+
is appended.
|
|
123
|
+
- **No fact cap:** every fact is searched on its own, so entities can grow.
|
|
124
|
+
Past 30 current facts, writes return an `oversized` note suggesting a split
|
|
125
|
+
into topic entities (`kipp oversized` lists them; `kipp split-plan` and
|
|
126
|
+
`kipp split-apply` do the split, and children point at their `parent`).
|
|
127
|
+
`kipp compact` can trim to the top 20 by frequency × recency × permanence,
|
|
128
|
+
but it deletes facts and nothing runs it.
|
|
129
|
+
|
|
130
|
+
The `shared` domain uses the bare collection names (`entities`, `events`,
|
|
131
|
+
`decisions`, `facts`); the others are prefixed (`dev_entities`, ...).
|
|
132
|
+
MCP tools and most CLI commands take a domain, defaulting to `shared`;
|
|
133
|
+
`export` and `import` cover `shared` only.
|
|
134
|
+
|
|
135
|
+
## Upgrading from entity-memory
|
|
136
|
+
|
|
137
|
+
KIPP was called `entity-memory`. The pip distribution changed name, so pipx
|
|
138
|
+
treats it as a new app:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
pipx uninstall entity-memory
|
|
142
|
+
pipx install -e . # provides the `kipp` command
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`scripts/install.sh` does this for you. The old `memory` command is gone: call
|
|
146
|
+
`kipp` instead. The old config paths and `ENTITY_MEMORY_CONFIG` still work.
|
|
147
|
+
Qdrant data and collection names are unchanged. To move installed systemd timers to the new unit names,
|
|
148
|
+
see [`docs/operations.md`](https://github.com/sarbloc/kipp/blob/main/docs/operations.md#systemd-timers).
|
|
149
|
+
|
|
150
|
+
## OpenClaw
|
|
151
|
+
|
|
152
|
+
`skill/SKILL.md` is the OpenClaw skill manifest. Install with
|
|
153
|
+
`bash scripts/install.sh`.
|
|
154
|
+
|
|
155
|
+
## Development
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
pip install -e .
|
|
159
|
+
python3 -m pytest -q # in-memory Qdrant and a mock embedder: no services needed
|
|
160
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0"] # SPDX license string (PEP 639)
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "kipp-memory"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Entity-based persistent memory with semantic search for AI agents"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Sarbloc" }]
|
|
14
|
+
keywords = ["memory", "ai-agents", "mcp", "qdrant", "embeddings", "semantic-search"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"qdrant-client>=1.12,<2",
|
|
27
|
+
"sentence-transformers>=3.0",
|
|
28
|
+
"click>=8.0",
|
|
29
|
+
"httpx>=0.25", # direct use in backup.py (snapshot download); also transitive via qdrant-client
|
|
30
|
+
"numpy>=1.24",
|
|
31
|
+
"mcp>=1.0,<2", # FastMCP import path removed in SDK 2.x (#29)
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/sarbloc/kipp"
|
|
36
|
+
Documentation = "https://github.com/sarbloc/kipp/tree/main/docs"
|
|
37
|
+
Issues = "https://github.com/sarbloc/kipp/issues"
|
|
38
|
+
Changelog = "https://github.com/sarbloc/kipp/blob/main/CHANGELOG.md"
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
kipp = "kipp.cli:main"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Entity-based persistent memory for AI agents."""
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""Snapshot every Qdrant collection to local disk (#38).
|
|
2
|
+
|
|
3
|
+
``kipp export`` covers only the shared domain's entities, so it is not a
|
|
4
|
+
backup. This takes a native Qdrant snapshot of EVERY collection, downloads it,
|
|
5
|
+
verifies it against the checksum Qdrant reports, and deletes the server-side
|
|
6
|
+
copy (``/qdrant/snapshots`` is not on the data volume, so leftovers pile up in
|
|
7
|
+
the container's writable layer).
|
|
8
|
+
|
|
9
|
+
A run writes into ``<dest>/.partial-<stamp>/`` and is renamed to
|
|
10
|
+
``<dest>/<stamp>/`` only once every collection verified, so a directory named
|
|
11
|
+
like a stamp is always a complete backup. ``manifest.json`` records each
|
|
12
|
+
collection's exact point count and sha256 at backup time.
|
|
13
|
+
|
|
14
|
+
Same disk as the data: this covers a bad migration, a buggy repair or an
|
|
15
|
+
accidental delete — not drive failure.
|
|
16
|
+
|
|
17
|
+
Restore one collection (replaces it; Qdrant reads the file from the upload):
|
|
18
|
+
curl -X POST "$QDRANT_URL/collections/<name>/snapshots/upload?priority=snapshot" \\
|
|
19
|
+
-H "api-key: $QDRANT_API_KEY" -F snapshot=@<dest>/<stamp>/<name>.snapshot
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import hashlib
|
|
25
|
+
import json
|
|
26
|
+
import os
|
|
27
|
+
import re
|
|
28
|
+
import shutil
|
|
29
|
+
import time
|
|
30
|
+
from dataclasses import dataclass, field
|
|
31
|
+
from datetime import datetime
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
from typing import Protocol
|
|
34
|
+
|
|
35
|
+
import httpx
|
|
36
|
+
|
|
37
|
+
STAMP_RE = re.compile(r"^\d{8}T\d{6}Z$")
|
|
38
|
+
PARTIAL_PREFIX = ".partial-"
|
|
39
|
+
DEFAULT_KEEP = 7 # ~150 MB each; a week of nightly rollback
|
|
40
|
+
CHUNK = 1 << 20
|
|
41
|
+
STALE_PARTIAL_SECONDS = 24 * 3600
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class SnapshotClient(Protocol):
|
|
45
|
+
"""The slice of ``QdrantClient`` a backup needs."""
|
|
46
|
+
|
|
47
|
+
def get_collections(self): ...
|
|
48
|
+
def count(self, collection_name: str, exact: bool = True): ...
|
|
49
|
+
def create_snapshot(self, collection_name: str, wait: bool = True): ...
|
|
50
|
+
def delete_snapshot(self, collection_name: str, snapshot_name: str, wait: bool = True): ...
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass
|
|
54
|
+
class BackupResult:
|
|
55
|
+
path: Path
|
|
56
|
+
collections: dict[str, dict] = field(default_factory=dict) # name -> manifest entry
|
|
57
|
+
pruned: list[Path] = field(default_factory=list)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def backup_all(
|
|
61
|
+
client: SnapshotClient,
|
|
62
|
+
http: httpx.Client,
|
|
63
|
+
dest: Path,
|
|
64
|
+
now: datetime,
|
|
65
|
+
keep: int = DEFAULT_KEEP,
|
|
66
|
+
) -> BackupResult:
|
|
67
|
+
"""Snapshot every collection into ``dest/<stamp>/``, then prune to ``keep``.
|
|
68
|
+
|
|
69
|
+
``http`` must target the same Qdrant as ``client`` (base_url + api-key
|
|
70
|
+
header); snapshots are downloaded through it because qdrant-client's
|
|
71
|
+
generated download call decodes the binary body as text.
|
|
72
|
+
"""
|
|
73
|
+
if keep < 1:
|
|
74
|
+
raise ValueError(f"keep must be >= 1, got {keep}")
|
|
75
|
+
stamp = now.strftime("%Y%m%dT%H%M%SZ")
|
|
76
|
+
final = dest / stamp
|
|
77
|
+
if final.exists():
|
|
78
|
+
raise FileExistsError(f"backup already exists: {final}")
|
|
79
|
+
partial = dest / f"{PARTIAL_PREFIX}{stamp}"
|
|
80
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
81
|
+
partial.mkdir(mode=0o700)
|
|
82
|
+
|
|
83
|
+
result = BackupResult(path=final)
|
|
84
|
+
try:
|
|
85
|
+
names = sorted(c.name for c in client.get_collections().collections)
|
|
86
|
+
for name in names:
|
|
87
|
+
points = client.count(name, exact=True).count
|
|
88
|
+
snap = client.create_snapshot(name, wait=True)
|
|
89
|
+
if snap is None:
|
|
90
|
+
raise RuntimeError(f"Qdrant returned no snapshot for {name}")
|
|
91
|
+
try:
|
|
92
|
+
digest, size = _download(http, name, snap.name, partial / f"{name}.snapshot")
|
|
93
|
+
finally:
|
|
94
|
+
client.delete_snapshot(name, snap.name, wait=True)
|
|
95
|
+
if snap.checksum and digest != snap.checksum:
|
|
96
|
+
raise RuntimeError(
|
|
97
|
+
f"{name}: downloaded sha256 {digest} != Qdrant's {snap.checksum}"
|
|
98
|
+
)
|
|
99
|
+
result.collections[name] = {"points": points, "bytes": size, "sha256": digest}
|
|
100
|
+
_write_private(partial / "manifest.json", json.dumps(
|
|
101
|
+
{"created": now.isoformat(), "collections": result.collections}, indent=2,
|
|
102
|
+
).encode())
|
|
103
|
+
partial.rename(final)
|
|
104
|
+
except BaseException:
|
|
105
|
+
shutil.rmtree(partial, ignore_errors=True)
|
|
106
|
+
raise
|
|
107
|
+
result.pruned = prune(dest, keep)
|
|
108
|
+
return result
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _download(http: httpx.Client, collection: str, snapshot: str, path: Path) -> tuple[str, int]:
|
|
112
|
+
sha, size = hashlib.sha256(), 0
|
|
113
|
+
with http.stream("GET", f"/collections/{collection}/snapshots/{snapshot}") as resp:
|
|
114
|
+
resp.raise_for_status()
|
|
115
|
+
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
116
|
+
with os.fdopen(fd, "wb") as fh:
|
|
117
|
+
for chunk in resp.iter_bytes(CHUNK):
|
|
118
|
+
fh.write(chunk)
|
|
119
|
+
sha.update(chunk)
|
|
120
|
+
size += len(chunk)
|
|
121
|
+
if size == 0:
|
|
122
|
+
raise RuntimeError(f"{collection}: empty snapshot download")
|
|
123
|
+
return sha.hexdigest(), size
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _write_private(path: Path, data: bytes) -> None:
|
|
127
|
+
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
128
|
+
with os.fdopen(fd, "wb") as fh:
|
|
129
|
+
fh.write(data)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def prune(dest: Path, keep: int) -> list[Path]:
|
|
133
|
+
"""Delete all but the newest ``keep`` complete backups, plus stale partials.
|
|
134
|
+
|
|
135
|
+
Only directories this module names are touched: ``<stamp>`` and
|
|
136
|
+
``.partial-<stamp>``. Stamps sort chronologically as strings. A partial is
|
|
137
|
+
left by a killed run (SIGKILL skips the cleanup); it is removed once it
|
|
138
|
+
is a day old, so a concurrent run's in-flight directory is never touched.
|
|
139
|
+
"""
|
|
140
|
+
removed: list[Path] = []
|
|
141
|
+
complete = sorted(p for p in dest.iterdir() if p.is_dir() and STAMP_RE.match(p.name))
|
|
142
|
+
for old in complete[:-keep]:
|
|
143
|
+
shutil.rmtree(old)
|
|
144
|
+
removed.append(old)
|
|
145
|
+
cutoff = time.time() - STALE_PARTIAL_SECONDS
|
|
146
|
+
for p in dest.iterdir():
|
|
147
|
+
if (
|
|
148
|
+
p.is_dir()
|
|
149
|
+
and p.name.startswith(PARTIAL_PREFIX)
|
|
150
|
+
and STAMP_RE.match(p.name[len(PARTIAL_PREFIX):])
|
|
151
|
+
and p.stat().st_mtime < cutoff # never a run still in flight
|
|
152
|
+
):
|
|
153
|
+
shutil.rmtree(p)
|
|
154
|
+
removed.append(p)
|
|
155
|
+
return removed
|