@vainplex/openclaw-knowledge-engine 0.1.0 → 0.1.2
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.
- package/LICENSE +21 -0
- package/README.md +251 -0
- package/package.json +2 -2
- package/test/entity-extractor.test.ts +7 -7
- package/test/patterns.test.ts +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenClaw Contributors
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# @vainplex/openclaw-knowledge-engine
|
|
2
|
+
|
|
3
|
+
A real-time knowledge extraction plugin for [OpenClaw](https://github.com/openclaw/openclaw). Automatically extracts entities, facts, and relationships from conversations — building a persistent, queryable knowledge base that grows with every message.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
Every message your OpenClaw agent processes flows through the Knowledge Engine:
|
|
8
|
+
|
|
9
|
+
1. **Regex Extraction** (instant, zero cost) — Detects people, organizations, technologies, URLs, emails, and other entities using pattern matching
|
|
10
|
+
2. **LLM Enhancement** (optional, batched) — Groups messages and sends them to a local LLM for deeper entity and fact extraction
|
|
11
|
+
3. **Fact Storage** — Stores extracted knowledge as structured subject-predicate-object triples with relevance scoring
|
|
12
|
+
4. **Relevance Decay** — Automatically decays old facts so recent knowledge surfaces first
|
|
13
|
+
5. **Vector Sync** — Optionally syncs facts to ChromaDB for semantic search
|
|
14
|
+
6. **Background Maintenance** — Prunes low-relevance facts, compacts storage, runs cleanup
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
User: "We're meeting with Alex from Acme Corp next Tuesday"
|
|
18
|
+
│
|
|
19
|
+
├─ Regex → entities: [Alex (person), Acme Corp (organization)]
|
|
20
|
+
└─ LLM → facts: [Alex — works-at — Acme Corp]
|
|
21
|
+
[Meeting — scheduled-with — Acme Corp]
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### 1. Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
cd ~/.openclaw
|
|
30
|
+
npm install @vainplex/openclaw-knowledge-engine
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Sync to extensions
|
|
34
|
+
|
|
35
|
+
OpenClaw loads plugins from the `extensions/` directory:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
mkdir -p extensions/openclaw-knowledge-engine
|
|
39
|
+
cp -r node_modules/@vainplex/openclaw-knowledge-engine/{dist,package.json,openclaw.plugin.json} extensions/openclaw-knowledge-engine/
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 3. Configure
|
|
43
|
+
|
|
44
|
+
Add to your `openclaw.json`:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"plugins": {
|
|
49
|
+
"entries": {
|
|
50
|
+
"openclaw-knowledge-engine": {
|
|
51
|
+
"enabled": true,
|
|
52
|
+
"config": {
|
|
53
|
+
"workspace": "/path/to/your/workspace",
|
|
54
|
+
"extraction": {
|
|
55
|
+
"regex": { "enabled": true },
|
|
56
|
+
"llm": {
|
|
57
|
+
"enabled": true,
|
|
58
|
+
"endpoint": "http://localhost:11434/api/generate",
|
|
59
|
+
"model": "mistral:7b",
|
|
60
|
+
"batchSize": 10,
|
|
61
|
+
"cooldownMs": 30000
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 4. Restart gateway
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
openclaw gateway restart
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
| Key | Type | Default | Description |
|
|
80
|
+
|-----|------|---------|-------------|
|
|
81
|
+
| `enabled` | boolean | `true` | Enable/disable the plugin |
|
|
82
|
+
| `workspace` | string | `~/.clawd/plugins/knowledge-engine` | Storage directory for knowledge files |
|
|
83
|
+
| `extraction.regex.enabled` | boolean | `true` | High-speed regex entity extraction |
|
|
84
|
+
| `extraction.llm.enabled` | boolean | `true` | LLM-based deep extraction |
|
|
85
|
+
| `extraction.llm.model` | string | `"mistral:7b"` | Ollama/OpenAI-compatible model |
|
|
86
|
+
| `extraction.llm.endpoint` | string | `"http://localhost:11434/api/generate"` | LLM API endpoint (HTTP or HTTPS) |
|
|
87
|
+
| `extraction.llm.batchSize` | number | `10` | Messages per LLM batch |
|
|
88
|
+
| `extraction.llm.cooldownMs` | number | `30000` | Wait time before sending batch |
|
|
89
|
+
| `decay.enabled` | boolean | `true` | Periodic relevance decay |
|
|
90
|
+
| `decay.intervalHours` | number | `24` | Hours between decay cycles |
|
|
91
|
+
| `decay.rate` | number | `0.02` | Decay rate per interval (2%) |
|
|
92
|
+
| `embeddings.enabled` | boolean | `false` | Sync facts to ChromaDB |
|
|
93
|
+
| `embeddings.endpoint` | string | `"http://localhost:8000/..."` | ChromaDB API endpoint |
|
|
94
|
+
| `embeddings.collectionName` | string | `"openclaw-facts"` | Vector collection name |
|
|
95
|
+
| `embeddings.syncIntervalMinutes` | number | `15` | Minutes between vector syncs |
|
|
96
|
+
| `storage.maxEntities` | number | `5000` | Max entities before pruning |
|
|
97
|
+
| `storage.maxFacts` | number | `10000` | Max facts before pruning |
|
|
98
|
+
| `storage.writeDebounceMs` | number | `15000` | Debounce delay for disk writes |
|
|
99
|
+
|
|
100
|
+
### Minimal config (regex only, no LLM)
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"openclaw-knowledge-engine": {
|
|
105
|
+
"enabled": true,
|
|
106
|
+
"config": {
|
|
107
|
+
"extraction": {
|
|
108
|
+
"llm": { "enabled": false }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This gives you zero-cost entity extraction with no external dependencies.
|
|
116
|
+
|
|
117
|
+
### Full config (LLM + ChromaDB)
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"openclaw-knowledge-engine": {
|
|
122
|
+
"enabled": true,
|
|
123
|
+
"config": {
|
|
124
|
+
"workspace": "~/my-agent/knowledge",
|
|
125
|
+
"extraction": {
|
|
126
|
+
"llm": {
|
|
127
|
+
"enabled": true,
|
|
128
|
+
"endpoint": "http://localhost:11434/api/generate",
|
|
129
|
+
"model": "mistral:7b"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"embeddings": {
|
|
133
|
+
"enabled": true,
|
|
134
|
+
"endpoint": "http://localhost:8000/api/v1/collections/facts/add"
|
|
135
|
+
},
|
|
136
|
+
"decay": {
|
|
137
|
+
"intervalHours": 12,
|
|
138
|
+
"rate": 0.03
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## How it works
|
|
146
|
+
|
|
147
|
+
### Extraction Pipeline
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
Message received
|
|
151
|
+
│
|
|
152
|
+
├──▶ Regex Engine (sync, <1ms)
|
|
153
|
+
│ └─ Extracts: proper nouns, organizations, tech terms,
|
|
154
|
+
│ URLs, emails, monetary amounts, dates
|
|
155
|
+
│
|
|
156
|
+
└──▶ LLM Batch Queue (async, batched)
|
|
157
|
+
└─ Every N messages or after cooldown:
|
|
158
|
+
└─ Sends batch to local LLM
|
|
159
|
+
└─ Extracts: entities + fact triples
|
|
160
|
+
└─ Stores in FactStore
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Fact Lifecycle
|
|
164
|
+
|
|
165
|
+
Facts are stored as structured triples:
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"id": "f-abc123",
|
|
170
|
+
"subject": "Alex",
|
|
171
|
+
"predicate": "works-at",
|
|
172
|
+
"object": "Acme Corp",
|
|
173
|
+
"source": "extracted-llm",
|
|
174
|
+
"relevance": 0.95,
|
|
175
|
+
"createdAt": 1707123456789,
|
|
176
|
+
"lastAccessedAt": 1707123456789
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
- **Relevance** starts at 1.0 and decays over time
|
|
181
|
+
- **Accessed facts** get a relevance boost (LRU-style)
|
|
182
|
+
- **Pruning** removes facts below the relevance floor when storage limits are hit
|
|
183
|
+
- **Minimum floor** (0.1) prevents complete decay — old facts never fully disappear
|
|
184
|
+
|
|
185
|
+
### Storage
|
|
186
|
+
|
|
187
|
+
All data is persisted as JSON files in your workspace:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
workspace/
|
|
191
|
+
├── entities.json # Extracted entities with types and counts
|
|
192
|
+
└── facts.json # Fact triples with relevance scores
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Writes use atomic file operations (write to `.tmp`, then rename) to prevent corruption.
|
|
196
|
+
|
|
197
|
+
## Architecture
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
index.ts → Plugin entry point
|
|
201
|
+
src/
|
|
202
|
+
├── types.ts → All TypeScript interfaces
|
|
203
|
+
├── config.ts → Config resolution + validation
|
|
204
|
+
├── patterns.ts → Regex factories (Proxy-based, no /g state bleed)
|
|
205
|
+
├── entity-extractor.ts → Regex-based entity extraction
|
|
206
|
+
├── llm-enhancer.ts → Batched LLM extraction with cooldown
|
|
207
|
+
├── fact-store.ts → In-memory fact store with decay + pruning
|
|
208
|
+
├── hooks.ts → OpenClaw hook registration + orchestration
|
|
209
|
+
├── http-client.ts → Shared HTTP/HTTPS transport
|
|
210
|
+
├── embeddings.ts → ChromaDB vector sync
|
|
211
|
+
├── storage.ts → Atomic JSON I/O with debounce
|
|
212
|
+
└── maintenance.ts → Scheduled background tasks
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
- **12 modules**, each with a single responsibility
|
|
216
|
+
- **Zero runtime dependencies** — Node.js built-ins only
|
|
217
|
+
- **TypeScript strict** — no `any` in source code
|
|
218
|
+
- **All functions ≤40 lines**
|
|
219
|
+
|
|
220
|
+
## Hooks
|
|
221
|
+
|
|
222
|
+
| Hook | Priority | Description |
|
|
223
|
+
|------|----------|-------------|
|
|
224
|
+
| `session_start` | 200 | Loads fact store from disk |
|
|
225
|
+
| `message_received` | 100 | Extracts entities + queues LLM batch |
|
|
226
|
+
| `message_sent` | 100 | Same extraction on outbound messages |
|
|
227
|
+
| `gateway_stop` | 50 | Flushes writes, stops timers |
|
|
228
|
+
|
|
229
|
+
## Testing
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm test
|
|
233
|
+
# Runs 83 tests across 10 test files
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Tests cover: config validation, entity extraction, fact CRUD, decay, pruning, LLM batching, HTTP client, embeddings, storage atomicity, maintenance scheduling, hook orchestration.
|
|
237
|
+
|
|
238
|
+
## Part of the Vainplex Plugin Suite
|
|
239
|
+
|
|
240
|
+
| # | Plugin | Status | Description |
|
|
241
|
+
|---|--------|--------|-------------|
|
|
242
|
+
| 1 | [@vainplex/nats-eventstore](https://github.com/alberthild/openclaw-nats-eventstore) | ✅ Published | NATS JetStream event persistence |
|
|
243
|
+
| 2 | [@vainplex/openclaw-cortex](https://github.com/alberthild/openclaw-cortex) | ✅ Published | Conversation intelligence (threads, decisions, boot context) |
|
|
244
|
+
| 3 | **@vainplex/openclaw-knowledge-engine** | ✅ Published | Real-time knowledge extraction (this plugin) |
|
|
245
|
+
| 4 | @vainplex/openclaw-governance | 📋 Planned | Policy enforcement + guardrails |
|
|
246
|
+
| 5 | @vainplex/openclaw-memory-engine | 📋 Planned | Unified memory layer |
|
|
247
|
+
| 6 | @vainplex/openclaw-health-monitor | 📋 Planned | System health + auto-healing |
|
|
248
|
+
|
|
249
|
+
## License
|
|
250
|
+
|
|
251
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vainplex/openclaw-knowledge-engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "An OpenClaw plugin for real-time and batch knowledge extraction from conversational data.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"nlp",
|
|
18
18
|
"entity-extraction"
|
|
19
19
|
],
|
|
20
|
-
"author": "
|
|
20
|
+
"author": "OpenClaw Community",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
@@ -34,12 +34,12 @@ describe('EntityExtractor', () => {
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
it('should extract multiple different entities', () => {
|
|
37
|
-
const text = 'Contact Atlas via atlas@
|
|
37
|
+
const text = 'Contact Atlas via atlas@acme.com on 2026-02-17.';
|
|
38
38
|
const entities = extractor.extract(text);
|
|
39
39
|
assert.strictEqual(entities.length, 3); // Atlas (proper_noun), email, date
|
|
40
40
|
|
|
41
41
|
const names = entities.map(e => e.value).sort();
|
|
42
|
-
assert.deepStrictEqual(names, ['2026-02-17', 'Atlas', 'atlas@
|
|
42
|
+
assert.deepStrictEqual(names, ['2026-02-17', 'Atlas', 'atlas@acme.com']);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
it('should handle multiple mentions of the same entity', () => {
|
|
@@ -54,14 +54,14 @@ describe('EntityExtractor', () => {
|
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
it('should correctly identify and canonicalize an organization', () => {
|
|
57
|
-
const text = 'I work for
|
|
57
|
+
const text = 'I work for Acme GmbH. It is a German company.';
|
|
58
58
|
const entities = extractor.extract(text);
|
|
59
59
|
const orgEntity = entities.find(e => e.type === 'organization');
|
|
60
60
|
|
|
61
61
|
assert.ok(orgEntity, 'Organization entity should be found');
|
|
62
|
-
assert.strictEqual(orgEntity.value, '
|
|
63
|
-
assert.strictEqual(orgEntity.id, 'organization:
|
|
64
|
-
assert.deepStrictEqual(orgEntity.mentions, ['
|
|
62
|
+
assert.strictEqual(orgEntity.value, 'Acme'); // Canonicalized
|
|
63
|
+
assert.strictEqual(orgEntity.id, 'organization:acme');
|
|
64
|
+
assert.deepStrictEqual(orgEntity.mentions, ['Acme GmbH']);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it('should extract dates in various formats', () => {
|
|
@@ -84,7 +84,7 @@ describe('EntityExtractor', () => {
|
|
|
84
84
|
describe('mergeEntities', () => {
|
|
85
85
|
it('should merge two disjoint lists of entities', () => {
|
|
86
86
|
const listA: Entity[] = [{ id: 'person:claude', type: 'person', value: 'Claude', count: 1, importance: 0.7, lastSeen: '2026-01-01', mentions: ['Claude'], source: ['regex'] }];
|
|
87
|
-
const listB: Entity[] = [{ id: 'org:
|
|
87
|
+
const listB: Entity[] = [{ id: 'org:acme', type: 'organization', value: 'Acme', count: 1, importance: 0.8, lastSeen: '2026-01-01', mentions: ['Acme'], source: ['llm'] }];
|
|
88
88
|
|
|
89
89
|
const merged = EntityExtractor.mergeEntities(listA, listB);
|
|
90
90
|
assert.strictEqual(merged.length, 2);
|
package/test/patterns.test.ts
CHANGED
|
@@ -111,11 +111,11 @@ describe('REGEX_PATTERNS', () => {
|
|
|
111
111
|
|
|
112
112
|
it('should match organization names with suffixes', () => {
|
|
113
113
|
const testCases: TestCase[] = [
|
|
114
|
-
['He works at
|
|
114
|
+
['He works at Acme GmbH.', 'Acme GmbH'],
|
|
115
115
|
['The owner of Stark Industries, LLC is Tony Stark.', 'Stark Industries, LLC'],
|
|
116
116
|
['Globex Corp. is another example.', 'Globex Corp.'],
|
|
117
117
|
['This also catches Acme Inc. and Cyberdyne Systems Ltd.', ['Acme Inc.', 'Cyberdyne Systems Ltd.']],
|
|
118
|
-
['No match for
|
|
118
|
+
['No match for Acme alone', null],
|
|
119
119
|
];
|
|
120
120
|
runTestCases(REGEX_PATTERNS.organization_suffix, testCases);
|
|
121
121
|
});
|