@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.
Files changed (2) hide show
  1. package/README.md +229 -88
  2. 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
- # 📦 `@knolo/core`
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
- # @knolo/core
21
+ `@knolo/core` is **not**:
6
22
 
7
- KnoLo Core is a **local-first knowledge base engine for small language models (LLMs)**.
23
+ * A vector database wrapper
24
+ * A hosted RAG service
25
+ * A probabilistic similarity engine
8
26
 
9
- It allows you to package structured documents into a compact `.knolo` file and query them deterministically — **no embeddings, no vector databases, no cloud required**.
27
+ It is:
10
28
 
11
- Designed for:
12
- - On-device LLMs
13
- - Deterministic AI systems
14
- - Agent routing
15
- - Air-gapped or privacy-first environments
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
- ## Why KnoLo?
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
- Traditional RAG systems require:
22
- - Embeddings
23
- - Vector databases
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
- KnoLo uses:
28
- - Structured indexing
29
- - Namespace-based routing
30
- - Deterministic query resolution
31
- - Compact `.knolo` bundles
54
+ In benchmark testing (March 2026):
32
55
 
33
- This makes it:
34
- - Fast
35
- - Reproducible
36
- - Lightweight
37
- - Fully local
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
- ## 📦 Installation
64
+ # 📦 Installation
42
65
 
43
66
  ```bash
44
67
  npm install @knolo/core
45
- ````
68
+ ```
46
69
 
47
70
  ---
48
71
 
49
- ## 🚀 Basic Usage
72
+ # 🚀 Core Concepts
73
+
74
+ ## 1️⃣ Build a Pack
50
75
 
51
- ### 1️⃣ Mount a Knowledge Pack
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("./dist/knowledge.knolo");
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
- ### 2️⃣ Query the Pack
117
+ ## 3️⃣ Query (Deterministic Lexical Retrieval)
62
118
 
63
119
  ```ts
64
120
  import { query } from "@knolo/core";
65
121
 
66
- const results = query(pack, {
67
- namespace: "mobile",
68
- q: "debounce vs throttle"
122
+ const hits = query(pack, "debounce vs throttle", {
123
+ topK: 5
69
124
  });
70
125
 
71
- console.log(results);
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
- ### 3️⃣ Resolve an Agent
141
+ # 🔀 Optional: Hybrid Semantic Rerank
77
142
 
78
- ```ts
79
- import { resolveAgent } from "@knolo/core";
143
+ Semantic rerank runs **after lexical retrieval**.
144
+
145
+ It never replaces lexical grounding.
80
146
 
81
- const resolved = resolveAgent(pack, {
82
- agentId: "support-agent",
83
- query: "Explain debounce vs throttle",
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
- Supports patch variables:
163
+ ## Query with rerank
88
164
 
89
165
  ```ts
90
- resolveAgent(pack, {
91
- agentId: "support-agent",
92
- patch: { tone: "formal" },
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
- ## 🤖 Agents
190
+ # 🤖 Optional: Agent Metadata & Routing
191
+
192
+ Knolo is a knowledge engine first.
99
193
 
100
- Agents are defined inside the pack metadata.
194
+ However, packs may optionally embed structured metadata for:
101
195
 
102
- Phase 2 features include:
196
+ * System prompts
197
+ * Namespace restrictions
198
+ * Tool policies
199
+ * Routing hints
103
200
 
104
- * Agent routing profiles
105
- * Deterministic route validation
106
- * Tool policies (`allow_all`, `mixed`, `unknown`)
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
- ## 🛠 Tool Policy Helpers
207
+ # 🛠 Runtime Contracts (Advanced)
208
+
209
+ For strict deterministic workflows:
210
+
211
+ ## RouteDecisionV1
112
212
 
113
213
  ```ts
114
- import { isToolAllowed, assertToolAllowed } from "@knolo/core";
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
- isToolAllowed(agent, "web-search");
117
- assertToolAllowed(agent, "database-read");
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
- Default behavior:
234
+ Helpers:
235
+
236
+ ```ts
237
+ import {
238
+ isRouteDecisionV1,
239
+ validateRouteDecisionV1,
240
+ isToolAllowed,
241
+ assertToolCallAllowed
242
+ } from "@knolo/core";
243
+ ```
121
244
 
122
- * If no policy → allow all
123
- * Explicit deny → deterministic error
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
- ## 📁 .knolo Format
256
+ # 📁 `.knolo` Pack Format
128
257
 
129
- A `.knolo` file contains:
258
+ Binary layout:
130
259
 
131
- * Indexed documents
132
- * Namespaces
133
- * Agent registry
134
- * Metadata
135
- * Routing profiles
260
+ ```
261
+ [metaLen][meta]
262
+ [lexLen][lexicon]
263
+ [postCount][postings]
264
+ [blocksLen][blocks]
265
+ [semantic?]
266
+ ```
136
267
 
137
- Built using `@knolo/cli`.
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
- ## 🧠 Design Philosophy
276
+ ---
142
277
 
143
- KnoLo is built around:
278
+ # ⚙️ Design Guarantees
144
279
 
145
- * Determinism over probability
146
- * Structure over embeddings
147
- * Local-first AI
148
- * Small model optimization
149
- * Agent-native architecture
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
- ## 🔐 Use Cases
290
+ # 🔐 Ideal For
154
291
 
155
- * On-device assistants
156
- * Enterprise internal knowledge
157
- * Mobile AI apps
158
- * Secure environments
159
- * Offline-first systems
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
- ## 🗺 Roadmap
301
+ # 🗺 Roadmap
164
302
 
165
- * Rust core implementation
303
+ * Incremental pack updates
304
+ * Evaluation tooling
305
+ * Performance introspection APIs
166
306
  * WASM builds
167
- * Multi-language SDKs
168
- * Advanced agent routing
169
- * Deterministic tool orchestration
307
+ * Continued local-first optimization
170
308
 
171
309
  ---
172
310
 
173
- ## 📄 License
311
+ # 📄 License
312
+
313
+ Apache-2.0
314
+
315
+
174
316
 
175
- MIT
176
317
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knolo/core",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "type": "module",
5
5
  "description": "Local-first knowledge packs for small LLMs.",
6
6
  "keywords": [