@knolo/core 3.1.3 → 3.1.4
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/README.md +229 -88
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,176 +1,317 @@
|
|
|
1
|
+
# 📦 `@knolo/core`
|
|
1
2
|
|
|
3
|
+
`@knolo/core` is the **deterministic retrieval engine and pack runtime** behind Knolo.
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
It lets you:
|
|
6
|
+
|
|
7
|
+
* Build structured knowledge packs
|
|
8
|
+
* Mount portable `.knolo` artifacts
|
|
9
|
+
* Run deterministic lexical retrieval
|
|
10
|
+
* Optionally apply hybrid semantic reranking
|
|
11
|
+
* Enforce strict runtime contracts for advanced workflows
|
|
12
|
+
|
|
13
|
+
No vector database required.
|
|
14
|
+
No cloud dependency required.
|
|
15
|
+
Works fully offline.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
# 🧠 What It Is
|
|
4
20
|
|
|
5
|
-
|
|
21
|
+
`@knolo/core` is **not**:
|
|
6
22
|
|
|
7
|
-
|
|
23
|
+
* A vector database wrapper
|
|
24
|
+
* A hosted RAG service
|
|
25
|
+
* A probabilistic similarity engine
|
|
8
26
|
|
|
9
|
-
It
|
|
27
|
+
It is:
|
|
10
28
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
29
|
+
* A versioned binary pack format
|
|
30
|
+
* A deterministic lexical retrieval engine
|
|
31
|
+
* An optional semantic rerank layer
|
|
32
|
+
* A portable knowledge runtime
|
|
33
|
+
|
|
34
|
+
You build once.
|
|
35
|
+
You mount anywhere — Node, browser, React Native, serverless, offline.
|
|
16
36
|
|
|
17
37
|
---
|
|
18
38
|
|
|
19
|
-
|
|
39
|
+
# 📊 Retrieval Characteristics
|
|
40
|
+
|
|
41
|
+
Lexical retrieval is:
|
|
42
|
+
|
|
43
|
+
* Deterministic
|
|
44
|
+
* Reproducible
|
|
45
|
+
* Stable across runs
|
|
46
|
+
* Independent of embeddings
|
|
47
|
+
|
|
48
|
+
Hybrid reranking is:
|
|
20
49
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
- External services
|
|
25
|
-
- Non-deterministic similarity scoring
|
|
50
|
+
* Optional
|
|
51
|
+
* Deterministic for fixed vectors
|
|
52
|
+
* Lexical-first (semantic never replaces grounding)
|
|
26
53
|
|
|
27
|
-
|
|
28
|
-
- Structured indexing
|
|
29
|
-
- Namespace-based routing
|
|
30
|
-
- Deterministic query resolution
|
|
31
|
-
- Compact `.knolo` bundles
|
|
54
|
+
In benchmark testing (March 2026):
|
|
32
55
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
* **Recall@5:** 1.000
|
|
57
|
+
* **MRR@5:** 0.867
|
|
58
|
+
* **nDCG@5:** 0.900
|
|
59
|
+
|
|
60
|
+
Strong ranking quality without requiring a vector database.
|
|
38
61
|
|
|
39
62
|
---
|
|
40
63
|
|
|
41
|
-
|
|
64
|
+
# 📦 Installation
|
|
42
65
|
|
|
43
66
|
```bash
|
|
44
67
|
npm install @knolo/core
|
|
45
|
-
|
|
68
|
+
```
|
|
46
69
|
|
|
47
70
|
---
|
|
48
71
|
|
|
49
|
-
|
|
72
|
+
# 🚀 Core Concepts
|
|
73
|
+
|
|
74
|
+
## 1️⃣ Build a Pack
|
|
50
75
|
|
|
51
|
-
|
|
76
|
+
```ts
|
|
77
|
+
import { buildPack } from "@knolo/core";
|
|
78
|
+
|
|
79
|
+
const bytes = await buildPack(docs, {
|
|
80
|
+
semantic: {
|
|
81
|
+
enabled: false
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`buildPack` produces a versioned `.knolo` binary artifact.
|
|
87
|
+
|
|
88
|
+
You can write it to disk or store it in object storage.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## 2️⃣ Mount a Pack
|
|
52
93
|
|
|
53
94
|
```ts
|
|
54
95
|
import { mountPack } from "@knolo/core";
|
|
55
96
|
|
|
56
|
-
const pack = await mountPack(
|
|
97
|
+
const pack = await mountPack({
|
|
98
|
+
src: "./dist/knowledge.knolo"
|
|
99
|
+
});
|
|
57
100
|
```
|
|
58
101
|
|
|
102
|
+
You can mount from:
|
|
103
|
+
|
|
104
|
+
* File path
|
|
105
|
+
* Buffer / Uint8Array
|
|
106
|
+
* Remote fetch response
|
|
107
|
+
* Object storage download
|
|
108
|
+
|
|
109
|
+
Mount-time validation ensures:
|
|
110
|
+
|
|
111
|
+
* Pack version compatibility
|
|
112
|
+
* Metadata integrity
|
|
113
|
+
* Optional agent registry validation
|
|
114
|
+
|
|
59
115
|
---
|
|
60
116
|
|
|
61
|
-
|
|
117
|
+
## 3️⃣ Query (Deterministic Lexical Retrieval)
|
|
62
118
|
|
|
63
119
|
```ts
|
|
64
120
|
import { query } from "@knolo/core";
|
|
65
121
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
q: "debounce vs throttle"
|
|
122
|
+
const hits = query(pack, "debounce vs throttle", {
|
|
123
|
+
topK: 5
|
|
69
124
|
});
|
|
70
125
|
|
|
71
|
-
|
|
126
|
+
for (const hit of hits) {
|
|
127
|
+
console.log(hit.text);
|
|
128
|
+
console.log(hit.metadata); // { score, source, namespace, id }
|
|
129
|
+
}
|
|
72
130
|
```
|
|
73
131
|
|
|
132
|
+
Properties:
|
|
133
|
+
|
|
134
|
+
* Fully deterministic
|
|
135
|
+
* No embedding dependency
|
|
136
|
+
* Namespace-aware
|
|
137
|
+
* Evaluation-friendly scoring
|
|
138
|
+
|
|
74
139
|
---
|
|
75
140
|
|
|
76
|
-
|
|
141
|
+
# 🔀 Optional: Hybrid Semantic Rerank
|
|
77
142
|
|
|
78
|
-
|
|
79
|
-
|
|
143
|
+
Semantic rerank runs **after lexical retrieval**.
|
|
144
|
+
|
|
145
|
+
It never replaces lexical grounding.
|
|
80
146
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
147
|
+
## Build with embeddings
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
const bytes = await buildPack(docs, {
|
|
151
|
+
semantic: {
|
|
152
|
+
enabled: true,
|
|
153
|
+
modelId: "text-embedding-3-small",
|
|
154
|
+
embeddings,
|
|
155
|
+
quantization: {
|
|
156
|
+
type: "int8_l2norm",
|
|
157
|
+
perVectorScale: true
|
|
158
|
+
}
|
|
159
|
+
}
|
|
84
160
|
});
|
|
85
161
|
```
|
|
86
162
|
|
|
87
|
-
|
|
163
|
+
## Query with rerank
|
|
88
164
|
|
|
89
165
|
```ts
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
166
|
+
import { hasSemantic } from "@knolo/core";
|
|
167
|
+
|
|
168
|
+
const hits = query(pack, "react native throttling issue", {
|
|
169
|
+
topK: 8,
|
|
170
|
+
semantic: {
|
|
171
|
+
enabled: hasSemantic(pack),
|
|
172
|
+
mode: "rerank",
|
|
173
|
+
topN: 50,
|
|
174
|
+
minLexConfidence: 0.35,
|
|
175
|
+
blend: { enabled: true, wLex: 0.75, wSem: 0.25 },
|
|
176
|
+
queryEmbedding
|
|
177
|
+
}
|
|
93
178
|
});
|
|
94
179
|
```
|
|
95
180
|
|
|
181
|
+
Design principles:
|
|
182
|
+
|
|
183
|
+
* Lexical-first
|
|
184
|
+
* Deterministic scoring
|
|
185
|
+
* No external vector store
|
|
186
|
+
* Quantized embedding storage inside pack
|
|
187
|
+
|
|
96
188
|
---
|
|
97
189
|
|
|
98
|
-
|
|
190
|
+
# 🤖 Optional: Agent Metadata & Routing
|
|
191
|
+
|
|
192
|
+
Knolo is a knowledge engine first.
|
|
99
193
|
|
|
100
|
-
|
|
194
|
+
However, packs may optionally embed structured metadata for:
|
|
101
195
|
|
|
102
|
-
|
|
196
|
+
* System prompts
|
|
197
|
+
* Namespace restrictions
|
|
198
|
+
* Tool policies
|
|
199
|
+
* Routing hints
|
|
103
200
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
* Registry validation at mount-time
|
|
201
|
+
Agent registries are validated once at `mountPack()`.
|
|
202
|
+
|
|
203
|
+
These features are additive and do not affect retrieval.
|
|
108
204
|
|
|
109
205
|
---
|
|
110
206
|
|
|
111
|
-
|
|
207
|
+
# 🛠 Runtime Contracts (Advanced)
|
|
208
|
+
|
|
209
|
+
For strict deterministic workflows:
|
|
210
|
+
|
|
211
|
+
## RouteDecisionV1
|
|
112
212
|
|
|
113
213
|
```ts
|
|
114
|
-
|
|
214
|
+
type RouteDecisionV1 = {
|
|
215
|
+
type: "route_decision";
|
|
216
|
+
intent?: string;
|
|
217
|
+
entities?: Record<string, unknown>;
|
|
218
|
+
candidates: { agentId: string; score: number }[];
|
|
219
|
+
selected: string;
|
|
220
|
+
};
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## ToolCallV1
|
|
115
224
|
|
|
116
|
-
|
|
117
|
-
|
|
225
|
+
```ts
|
|
226
|
+
type ToolCallV1 = {
|
|
227
|
+
type: "tool_call";
|
|
228
|
+
callId: string;
|
|
229
|
+
tool: string;
|
|
230
|
+
args: Record<string, unknown>;
|
|
231
|
+
};
|
|
118
232
|
```
|
|
119
233
|
|
|
120
|
-
|
|
234
|
+
Helpers:
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
import {
|
|
238
|
+
isRouteDecisionV1,
|
|
239
|
+
validateRouteDecisionV1,
|
|
240
|
+
isToolAllowed,
|
|
241
|
+
assertToolCallAllowed
|
|
242
|
+
} from "@knolo/core";
|
|
243
|
+
```
|
|
121
244
|
|
|
122
|
-
|
|
123
|
-
|
|
245
|
+
Enables:
|
|
246
|
+
|
|
247
|
+
* Deterministic routing validation
|
|
248
|
+
* Policy enforcement
|
|
249
|
+
* Tool permission checks
|
|
250
|
+
* Structured AI pipelines
|
|
251
|
+
|
|
252
|
+
These are optional — not required for standard retrieval usage.
|
|
124
253
|
|
|
125
254
|
---
|
|
126
255
|
|
|
127
|
-
|
|
256
|
+
# 📁 `.knolo` Pack Format
|
|
128
257
|
|
|
129
|
-
|
|
258
|
+
Binary layout:
|
|
130
259
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
260
|
+
```
|
|
261
|
+
[metaLen][meta]
|
|
262
|
+
[lexLen][lexicon]
|
|
263
|
+
[postCount][postings]
|
|
264
|
+
[blocksLen][blocks]
|
|
265
|
+
[semantic?]
|
|
266
|
+
```
|
|
136
267
|
|
|
137
|
-
|
|
268
|
+
Properties:
|
|
138
269
|
|
|
139
|
-
|
|
270
|
+
* Versioned
|
|
271
|
+
* Compact
|
|
272
|
+
* Immutable
|
|
273
|
+
* Semantic section auto-detected
|
|
274
|
+
* Designed for fast mount + query
|
|
140
275
|
|
|
141
|
-
|
|
276
|
+
---
|
|
142
277
|
|
|
143
|
-
|
|
278
|
+
# ⚙️ Design Guarantees
|
|
144
279
|
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
280
|
+
* Deterministic lexical retrieval
|
|
281
|
+
* Deterministic hybrid rerank (fixed vectors)
|
|
282
|
+
* No vector database required
|
|
283
|
+
* No cloud dependency required
|
|
284
|
+
* Works offline
|
|
285
|
+
* Works in React Native / Expo
|
|
286
|
+
* Portable binary artifacts
|
|
150
287
|
|
|
151
288
|
---
|
|
152
289
|
|
|
153
|
-
|
|
290
|
+
# 🔐 Ideal For
|
|
154
291
|
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* Secure environments
|
|
159
|
-
*
|
|
292
|
+
* Local-first AI systems
|
|
293
|
+
* Offline assistants
|
|
294
|
+
* On-device LLM retrieval
|
|
295
|
+
* Secure / air-gapped environments
|
|
296
|
+
* Deterministic RAG pipelines
|
|
297
|
+
* Evaluation-heavy workflows
|
|
160
298
|
|
|
161
299
|
---
|
|
162
300
|
|
|
163
|
-
|
|
301
|
+
# 🗺 Roadmap
|
|
164
302
|
|
|
165
|
-
*
|
|
303
|
+
* Incremental pack updates
|
|
304
|
+
* Evaluation tooling
|
|
305
|
+
* Performance introspection APIs
|
|
166
306
|
* WASM builds
|
|
167
|
-
*
|
|
168
|
-
* Advanced agent routing
|
|
169
|
-
* Deterministic tool orchestration
|
|
307
|
+
* Continued local-first optimization
|
|
170
308
|
|
|
171
309
|
---
|
|
172
310
|
|
|
173
|
-
|
|
311
|
+
# 📄 License
|
|
312
|
+
|
|
313
|
+
Apache-2.0
|
|
314
|
+
|
|
315
|
+
|
|
174
316
|
|
|
175
|
-
MIT
|
|
176
317
|
|