ktkn-mem 1.0.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.
Files changed (39) hide show
  1. ktkn_mem-1.0.0/.agents/skills/ktkn-librarian/SKILL.md +214 -0
  2. ktkn_mem-1.0.0/.gitignore +31 -0
  3. ktkn_mem-1.0.0/LICENSE +661 -0
  4. ktkn_mem-1.0.0/PKG-INFO +170 -0
  5. ktkn_mem-1.0.0/README.md +121 -0
  6. ktkn_mem-1.0.0/ktkn-mcp/Package.resolved +222 -0
  7. ktkn_mem-1.0.0/ktkn-mcp/Package.swift +60 -0
  8. ktkn_mem-1.0.0/ktkn-mcp/Sources/kTkNMCPServer/main.swift +504 -0
  9. ktkn_mem-1.0.0/ktkn-mcp/build.sh +82 -0
  10. ktkn_mem-1.0.0/ktkn-mcp/com.katechon.mcp-server.plist +48 -0
  11. ktkn_mem-1.0.0/ktkn_feed/__init__.py +14 -0
  12. ktkn_mem-1.0.0/ktkn_feed/__main__.py +6 -0
  13. ktkn_mem-1.0.0/ktkn_feed/bulk_youtube.py +311 -0
  14. ktkn_mem-1.0.0/ktkn_feed/content_fetcher.py +132 -0
  15. ktkn_mem-1.0.0/ktkn_feed/daemon.py +442 -0
  16. ktkn_mem-1.0.0/ktkn_feed/feeds.example.txt +26 -0
  17. ktkn_mem-1.0.0/ktkn_feed/rss.py +148 -0
  18. ktkn_mem-1.0.0/ktkn_feed/youtube.py +221 -0
  19. ktkn_mem-1.0.0/ktkn_mem/__init__.py +22 -0
  20. ktkn_mem-1.0.0/ktkn_mem/__main__.py +4 -0
  21. ktkn_mem-1.0.0/ktkn_mem/agent.py +237 -0
  22. ktkn_mem-1.0.0/ktkn_mem/chunker.py +408 -0
  23. ktkn_mem-1.0.0/ktkn_mem/cli.py +1195 -0
  24. ktkn_mem-1.0.0/ktkn_mem/config.py +307 -0
  25. ktkn_mem-1.0.0/ktkn_mem/conversation_writer.py +339 -0
  26. ktkn_mem-1.0.0/ktkn_mem/coreml_embedder.py +141 -0
  27. ktkn_mem-1.0.0/ktkn_mem/cross_db_rag.py +434 -0
  28. ktkn_mem-1.0.0/ktkn_mem/embedder.py +149 -0
  29. ktkn_mem-1.0.0/ktkn_mem/ktkn_mem.py +239 -0
  30. ktkn_mem-1.0.0/ktkn_mem/library.py +274 -0
  31. ktkn_mem-1.0.0/ktkn_mem/mlx_embedder.py +124 -0
  32. ktkn_mem-1.0.0/ktkn_mem/ollama_client.py +149 -0
  33. ktkn_mem-1.0.0/ktkn_mem/ollama_embedder.py +111 -0
  34. ktkn_mem-1.0.0/ktkn_mem/portable_embedder.py +36 -0
  35. ktkn_mem-1.0.0/ktkn_mem/rag.py +324 -0
  36. ktkn_mem-1.0.0/ktkn_mem/store.py +539 -0
  37. ktkn_mem-1.0.0/ktkn_mem/userprofile.py +233 -0
  38. ktkn_mem-1.0.0/llms.txt +76 -0
  39. ktkn_mem-1.0.0/pyproject.toml +52 -0
@@ -0,0 +1,214 @@
1
+ ---
2
+ name: ktkn-librarian
3
+ description: >
4
+ Interact with Katechon Memory (ktkn) — the sovereign semantic memory system.
5
+ Use this skill whenever you need to search a knowledge base, store memories,
6
+ manage an agent's memory namespace, or retrieve context from past conversations.
7
+ Trigger on: 'search memory', 'remember', 'store this', 'ktkn', 'katechon',
8
+ 'my notes', 'my conversations', 'what did I say about', 'find in my archive',
9
+ 'library', '.ktkn', 'memory layer', 'semantic search', 'RAG query'.
10
+ ---
11
+
12
+ # Katechon Memory — Agent Skill (The Librarian)
13
+
14
+ You are interacting with **Katechon Memory (ktkn)**, a local-first sovereign semantic memory system. Think of it as a library system:
15
+
16
+ | Library Concept | Katechon Equivalent |
17
+ |----------------|---------------------|
18
+ | **Dewey Decimal Catalog** | ANE vector index (sqlite-vec) — finds what you're looking for |
19
+ | **The Books** | FTS5 full-text store — the actual content the catalog points to |
20
+ | **The Librarian** | This skill — you, knowing how to use the catalog and retrieve books |
21
+ | **Library Card** | Your agent namespace in `~/.ktkn/agents/{your-id}/` |
22
+
23
+ ## Prerequisites
24
+
25
+ The `ktkn` CLI must be installed. Verify with:
26
+ ```bash
27
+ ktkn --help
28
+ ```
29
+
30
+ If not available, the user needs to install it:
31
+ ```bash
32
+ pip install ktkn-mem # or: pipx install ktkn-mem
33
+ ktkn init # creates ~/.ktkn/ structure
34
+ ```
35
+
36
+ ## System Layout
37
+
38
+ ```
39
+ ~/.ktkn/
40
+ ├── config.json # Global configuration
41
+ ├── models/ # Embedding model files
42
+ ├── libraries/ # Registered .ktknlib library bundles
43
+ │ └── mounts.json # {"name": "/path/to/library.ktknlib"}
44
+ ├── agents/ # Per-agent memory namespaces
45
+ │ ├── _system/ # System agent (librarian, user profiler)
46
+ │ │ ├── agent.json
47
+ │ │ └── userprofile.ktkn
48
+ │ ├── hermes-v1/ # Example agent
49
+ │ │ ├── agent.json
50
+ │ │ ├── memory.ktkn # Long-term semantic memory
51
+ │ │ ├── sessions.ktkn # Conversation history
52
+ │ │ └── working_memory.md
53
+ │ └── ...
54
+ └── feeds/ # Feed configurations (RSS, YouTube, Apple Docs)
55
+ ```
56
+
57
+ ## Core Operations
58
+
59
+ ### 1. Search a Database
60
+
61
+ Search for semantically similar content in a specific `.ktkn` database:
62
+
63
+ ```bash
64
+ ktkn search --db /path/to/database.ktkn --query "your search terms" --top-k 10
65
+ ```
66
+
67
+ **Example — Search the Gutenberg literature corpus:**
68
+ ```bash
69
+ ktkn search --db ~/.ktkn/libraries/gutenberg.ktknlib/literature.ktkn \
70
+ --query "the nature of justice and law" --top-k 5
71
+ ```
72
+
73
+ ### 2. List Available Libraries
74
+
75
+ See what knowledge stores are registered:
76
+
77
+ ```bash
78
+ ktkn lib list
79
+ ```
80
+
81
+ Output shows library name, database count, total chunks, size, and embedding model.
82
+
83
+ ### 3. Get Library Details
84
+
85
+ ```bash
86
+ ktkn lib info /path/to/library.ktknlib
87
+ ```
88
+
89
+ ### 4. RAG Query (Search + Synthesis)
90
+
91
+ Ask a question and get a synthesized answer from the archive. Requires Ollama running:
92
+
93
+ ```bash
94
+ # Single database RAG
95
+ ktkn rag --db /path/to/archive.ktkn --query "What are the user's views on governance?" \
96
+ --model granite4:micro-h --sources
97
+
98
+ # Cross-database RAG (searches all .ktkn files in directory)
99
+ ktkn rag --db-dir /path/to/ktkn.ktkns/ --query "Byzantine influence on Western theology" \
100
+ --model granite4:micro-h --sources --report
101
+ ```
102
+
103
+ **RAG modes:**
104
+ - Default: Question → Answer with citations
105
+ - `--report`: Structured markdown report with synthesis
106
+ - `--deep`: Focus on finding the USER's original ideas (not AI responses)
107
+ - `--stream`: Stream the output token by token
108
+
109
+ ### 5. Agent Memory Operations
110
+
111
+ #### Create your agent namespace (if you don't have one yet):
112
+ ```bash
113
+ ktkn agent create {your-agent-id} --display-name "Your Name"
114
+ ```
115
+
116
+ #### List all agents:
117
+ ```bash
118
+ ktkn agent list
119
+ ```
120
+
121
+ #### Store a memory:
122
+ Use the Python API (from within your agent code):
123
+ ```python
124
+ from ktkn_mem.agent import AgentMemory
125
+
126
+ agent = AgentMemory("your-agent-id")
127
+ agent.store_memory(
128
+ text="The user prefers local-first solutions over cloud dependencies.",
129
+ tags="preference,architecture",
130
+ source="conversation-2026-06-23"
131
+ )
132
+ ```
133
+
134
+ #### Search your own memories:
135
+ ```bash
136
+ ktkn agent search {your-agent-id} --query "user preferences" --top-k 5
137
+ ```
138
+
139
+ #### Read/update working memory:
140
+ ```python
141
+ from ktkn_mem.agent import AgentMemory
142
+
143
+ agent = AgentMemory("your-agent-id")
144
+ current = agent.get_working_memory()
145
+ agent.update_working_memory("# Updated Context\n- Working on: X\n- Key fact: Y")
146
+ ```
147
+
148
+ ### 6. Ingest New Content
149
+
150
+ Add new files to a database:
151
+
152
+ ```bash
153
+ ktkn ingest --dir /path/to/files --db /path/to/output.ktkn \
154
+ --model bge-base-en-v1.5 --tags "source-name"
155
+ ```
156
+
157
+ **Supported formats:** `.txt`, `.md`, `.json`, `.html`, `.pdf` (with extensions)
158
+
159
+ ### 7. Database Management
160
+
161
+ ```bash
162
+ ktkn info --db archive.ktkn # Stats: chunks, files, size, model
163
+ ktkn list --db archive.ktkn # List all source files in the database
164
+ ktkn inspect --db archive.ktkn --file "document.txt" # View chunks for a file
165
+ ktkn delete --db archive.ktkn --file "document.txt" # Remove a file's chunks
166
+ ktkn vacuum --db archive.ktkn # Reclaim space
167
+ ```
168
+
169
+ ## Important Rules
170
+
171
+ 1. **Never modify `.ktkn` files directly with SQL.** Always use the `ktkn` CLI or the Python API. The vector index and FTS index must stay in sync.
172
+
173
+ 2. **Embedding model must match.** A database created with `bge-base-en-v1.5` (768-dim) cannot be searched with `coreml-minilm` (384-dim). Check with `ktkn info --db ...` to see which model was used.
174
+
175
+ 3. **Libraries are read-only by convention.** Don't ingest into a library database. Create a new `.ktkn` for new content.
176
+
177
+ 4. **Working memory is ephemeral.** The `working_memory.md` file is for your current context window. Long-term facts should be stored in `memory.ktkn` via `store_memory()`.
178
+
179
+ 5. **Respect namespace boundaries.** Only read/write your own agent namespace. Don't modify another agent's `memory.ktkn` or `working_memory.md`.
180
+
181
+ ## Common Patterns
182
+
183
+ ### "What did the user say about X?"
184
+ ```bash
185
+ ktkn search --db ~/.ktkn/agents/_system/conversations.ktkn --query "X" --top-k 10
186
+ ```
187
+
188
+ ### "Find relevant information across all libraries"
189
+ ```bash
190
+ ktkn lib list # see what's available
191
+ ktkn rag --db-dir /path/to/ktkn.ktkns/ --query "X" --sources --report
192
+ ```
193
+
194
+ ### "Remember this for later"
195
+ ```python
196
+ from ktkn_mem.agent import AgentMemory
197
+ agent = AgentMemory("your-id")
198
+ agent.store_memory("Important fact: ...", tags="key-insight")
199
+ ```
200
+
201
+ ### "What do I know about the user?"
202
+ ```bash
203
+ ktkn profile show
204
+ ```
205
+
206
+ ## Troubleshooting
207
+
208
+ | Problem | Fix |
209
+ |---------|-----|
210
+ | `ktkn: command not found` | `pip install ktkn-mem` or activate the venv |
211
+ | `Database not found` | Check path. Use `ktkn lib list` to find mounted libraries. |
212
+ | `No results` | Try broader query terms. Check `ktkn info --db ...` to confirm DB has content. |
213
+ | `Embedding dimension mismatch` | The query model doesn't match the DB model. Check `ktkn info`. |
214
+ | `CoreML model not found` | Run `ktkn init` or set `KTKN_MODEL_PATH` env var. |
@@ -0,0 +1,31 @@
1
+ # Python
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ *.egg
9
+ .eggs/
10
+
11
+ # Virtual environments
12
+ venv/
13
+ .venv/
14
+
15
+ # Database files
16
+ *.ktkn
17
+
18
+ # Swift build
19
+ .build/
20
+ .swiftpm/
21
+ DerivedData/
22
+
23
+ # IDE
24
+ .idea/
25
+ .vscode/
26
+ *.swp
27
+ *~
28
+ .DS_Store
29
+
30
+ # Feed data (personal)
31
+ ktkn_feed/feeds.txt