@knolo/core 3.1.2 → 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 +317 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,317 @@
1
+ # 📦 `@knolo/core`
2
+
3
+ `@knolo/core` is the **deterministic retrieval engine and pack runtime** behind Knolo.
4
+
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
20
+
21
+ `@knolo/core` is **not**:
22
+
23
+ * A vector database wrapper
24
+ * A hosted RAG service
25
+ * A probabilistic similarity engine
26
+
27
+ It is:
28
+
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.
36
+
37
+ ---
38
+
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:
49
+
50
+ * Optional
51
+ * Deterministic for fixed vectors
52
+ * Lexical-first (semantic never replaces grounding)
53
+
54
+ In benchmark testing (March 2026):
55
+
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.
61
+
62
+ ---
63
+
64
+ # 📦 Installation
65
+
66
+ ```bash
67
+ npm install @knolo/core
68
+ ```
69
+
70
+ ---
71
+
72
+ # 🚀 Core Concepts
73
+
74
+ ## 1️⃣ Build a Pack
75
+
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
93
+
94
+ ```ts
95
+ import { mountPack } from "@knolo/core";
96
+
97
+ const pack = await mountPack({
98
+ src: "./dist/knowledge.knolo"
99
+ });
100
+ ```
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
+
115
+ ---
116
+
117
+ ## 3️⃣ Query (Deterministic Lexical Retrieval)
118
+
119
+ ```ts
120
+ import { query } from "@knolo/core";
121
+
122
+ const hits = query(pack, "debounce vs throttle", {
123
+ topK: 5
124
+ });
125
+
126
+ for (const hit of hits) {
127
+ console.log(hit.text);
128
+ console.log(hit.metadata); // { score, source, namespace, id }
129
+ }
130
+ ```
131
+
132
+ Properties:
133
+
134
+ * Fully deterministic
135
+ * No embedding dependency
136
+ * Namespace-aware
137
+ * Evaluation-friendly scoring
138
+
139
+ ---
140
+
141
+ # 🔀 Optional: Hybrid Semantic Rerank
142
+
143
+ Semantic rerank runs **after lexical retrieval**.
144
+
145
+ It never replaces lexical grounding.
146
+
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
+ }
160
+ });
161
+ ```
162
+
163
+ ## Query with rerank
164
+
165
+ ```ts
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
+ }
178
+ });
179
+ ```
180
+
181
+ Design principles:
182
+
183
+ * Lexical-first
184
+ * Deterministic scoring
185
+ * No external vector store
186
+ * Quantized embedding storage inside pack
187
+
188
+ ---
189
+
190
+ # 🤖 Optional: Agent Metadata & Routing
191
+
192
+ Knolo is a knowledge engine first.
193
+
194
+ However, packs may optionally embed structured metadata for:
195
+
196
+ * System prompts
197
+ * Namespace restrictions
198
+ * Tool policies
199
+ * Routing hints
200
+
201
+ Agent registries are validated once at `mountPack()`.
202
+
203
+ These features are additive and do not affect retrieval.
204
+
205
+ ---
206
+
207
+ # 🛠 Runtime Contracts (Advanced)
208
+
209
+ For strict deterministic workflows:
210
+
211
+ ## RouteDecisionV1
212
+
213
+ ```ts
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
224
+
225
+ ```ts
226
+ type ToolCallV1 = {
227
+ type: "tool_call";
228
+ callId: string;
229
+ tool: string;
230
+ args: Record<string, unknown>;
231
+ };
232
+ ```
233
+
234
+ Helpers:
235
+
236
+ ```ts
237
+ import {
238
+ isRouteDecisionV1,
239
+ validateRouteDecisionV1,
240
+ isToolAllowed,
241
+ assertToolCallAllowed
242
+ } from "@knolo/core";
243
+ ```
244
+
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.
253
+
254
+ ---
255
+
256
+ # 📁 `.knolo` Pack Format
257
+
258
+ Binary layout:
259
+
260
+ ```
261
+ [metaLen][meta]
262
+ [lexLen][lexicon]
263
+ [postCount][postings]
264
+ [blocksLen][blocks]
265
+ [semantic?]
266
+ ```
267
+
268
+ Properties:
269
+
270
+ * Versioned
271
+ * Compact
272
+ * Immutable
273
+ * Semantic section auto-detected
274
+ * Designed for fast mount + query
275
+
276
+ ---
277
+
278
+ # ⚙️ Design Guarantees
279
+
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
287
+
288
+ ---
289
+
290
+ # 🔐 Ideal For
291
+
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
298
+
299
+ ---
300
+
301
+ # 🗺 Roadmap
302
+
303
+ * Incremental pack updates
304
+ * Evaluation tooling
305
+ * Performance introspection APIs
306
+ * WASM builds
307
+ * Continued local-first optimization
308
+
309
+ ---
310
+
311
+ # 📄 License
312
+
313
+ Apache-2.0
314
+
315
+
316
+
317
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knolo/core",
3
- "version": "3.1.2",
3
+ "version": "3.1.4",
4
4
  "type": "module",
5
5
  "description": "Local-first knowledge packs for small LLMs.",
6
6
  "keywords": [