knolo-core 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.
Files changed (3) hide show
  1. package/README.md +28 -19
  2. package/bin/knolo.mjs +60 -21
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,30 +1,39 @@
1
1
 
2
+
2
3
  # 🧠 KnoLo Core
3
4
 
4
- KnoLo Core is a **local-first knowledge base system** for small language models (LLMs).
5
+ [![npm version](https://img.shields.io/npm/v/knolo-core.svg)](https://www.npmjs.com/package/knolo-core)
6
+ [![npm downloads](https://img.shields.io/npm/dm/knolo-core.svg)](https://www.npmjs.com/package/knolo-core)
7
+ [![License](https://img.shields.io/npm/l/knolo-core.svg)](./LICENSE)
8
+
9
+ **KnoLo Core** is a **local-first knowledge base system** for small language models (LLMs).
5
10
  It lets you package your own documents into a compact `.knolo` file and query them deterministically — **no embeddings, no vector DBs, no cloud**. Perfect for **on-device LLMs**.
6
11
 
7
12
  ---
8
13
 
9
14
  ## ✨ Features
10
15
 
11
- * 📦 **Single-file packs** (`.knolo`) you can ship or load offline.
12
- * 🔎 **Deterministic lexical retrieval** (BM25L + phrase + heading boosts).
13
- * ⚡ **Tiny & fast** — runs in Node, browsers, and Expo.
14
- * 📑 **Context Patches**: structured snippets for direct LLM input.
15
- * 🔒 **Privacy-first**: all data stays local.
16
+ * 📦 **Single-file packs** (`.knolo`) you can ship or load offline
17
+ * 🔎 **Deterministic lexical retrieval** (BM25L + phrase + heading boosts)
18
+ * ⚡ **Tiny & fast** — runs in Node, browsers, and Expo
19
+ * 📑 **Context Patches**: structured snippets optimized for LLM prompts
20
+ * 🔒 **Privacy-first**: all data stays local
16
21
 
17
22
  ---
18
23
 
19
24
  ## 📦 Install
20
25
 
21
26
  ```bash
22
- # local build
27
+ npm install knolo-core
28
+ ```
29
+
30
+ For local development (building from source):
31
+
32
+ ```bash
33
+ git clone https://github.com/yourname/knolo-core.git
34
+ cd knolo-core
23
35
  npm install
24
36
  npm run build
25
-
26
- # or if published later
27
- npm install @knolo/core
28
37
  ```
29
38
 
30
39
  ---
@@ -34,7 +43,7 @@ npm install @knolo/core
34
43
  ### 1. Node.js (in-memory build + query)
35
44
 
36
45
  ```js
37
- import { buildPack, mountPack, query, makeContextPatch } from "./dist/index.js";
46
+ import { buildPack, mountPack, query, makeContextPatch } from "knolo-core";
38
47
 
39
48
  const docs = [
40
49
  { heading: "React Native Bridge", text: "The bridge sends messages between JS and native. You can throttle events to reduce jank." },
@@ -74,13 +83,13 @@ console.log("Context Patch:", patch);
74
83
 
75
84
  ```bash
76
85
  # writes mypack.knolo
77
- node bin/knolo.mjs docs.json mypack.knolo
86
+ npx knolo docs.json mypack.knolo
78
87
  ```
79
88
 
80
89
  **Query it in a script:**
81
90
 
82
91
  ```js
83
- import { mountPack, query } from "./dist/index.js";
92
+ import { mountPack, query } from "knolo-core";
84
93
 
85
94
  const kb = await mountPack({ src: "./mypack.knolo" });
86
95
  const hits = query(kb, "throttle events", { topK: 3 });
@@ -94,7 +103,7 @@ console.log(hits);
94
103
  ```ts
95
104
  import { Asset } from "expo-asset";
96
105
  import * as FileSystem from "expo-file-system";
97
- import { mountPack, query, makeContextPatch } from "@knolo/core";
106
+ import { mountPack, query, makeContextPatch } from "knolo-core";
98
107
 
99
108
  async function loadKnowledge() {
100
109
  const asset = Asset.fromModule(require("./assets/mypack.knolo"));
@@ -124,18 +133,18 @@ mountPack({ src: string | Uint8Array | ArrayBuffer }) -> Promise<Pack>
124
133
  query(pack, "your query", { topK?: number, requirePhrases?: string[] }) -> Hit[]
125
134
 
126
135
  // Create LLM-friendly patch
127
- makeContextPatch(hits, { budget?: "mini"|"small"|"full" }) -> ContextPatch
136
+ makeContextPatch(hits, { budget?: "mini" | "small" | "full" }) -> ContextPatch
128
137
  ```
129
138
 
130
139
  ---
131
140
 
132
141
  ## 🔮 Roadmap
133
142
 
134
- * Multi-resolution packs (summaries + facts).
135
- * Overlay store for user notes.
136
- * WASM core for very large packs.
143
+ * Multi-resolution packs (summaries + facts)
144
+ * Overlay store for user notes
145
+ * WASM core for very large packs
137
146
 
138
147
  ---
139
148
 
140
- 👉 With KnoLo, you can **carry knowledge with your model** — no servers, no dependencies, just a tiny portable pack.
149
+ 👉 With **KnoLo**, you can **carry knowledge with your model** — no servers, no dependencies, just a tiny portable pack.
141
150
 
package/bin/knolo.mjs CHANGED
@@ -1,30 +1,69 @@
1
1
  #!/usr/bin/env node
2
+ // Robust CLI that works with ESM or CJS builds and odd resolution cases.
2
3
 
3
- // Simple CLI wrapper around the KnoLo pack builder. Reads an input JSON
4
- // containing an array of documents with `heading` and `text` fields and
5
- // writes a `.knolo` binary pack. Requires that the compiled `dist` files
6
- // exist (run `npm run build` before using). This script uses ESM syntax.
4
+ import { readFileSync, writeFileSync } from "node:fs";
5
+ import path from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import { createRequire } from "node:module";
7
8
 
8
- import { readFileSync, writeFileSync } from 'node:fs';
9
- import { buildPack } from '../dist/builder.js';
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+ const require = createRequire(import.meta.url);
10
11
 
11
- async function main() {
12
- const [,, inputFile, outputFile = 'knowledge.knolo'] = process.argv;
13
- if (!inputFile) {
14
- console.log('Usage: knolo <input.json> [output.knolo]');
15
- process.exit(1);
12
+ async function tryImport(filePath) {
13
+ // 1) ESM via file URL
14
+ try {
15
+ const url = pathToFileURL(filePath).href;
16
+ return await import(url);
17
+ } catch (_) {}
18
+ // 2) CJS via require
19
+ try {
20
+ return require(filePath);
21
+ } catch (_) {}
22
+ return null;
23
+ }
24
+
25
+ function getBuildPack(mod) {
26
+ if (!mod) return undefined;
27
+ // Named export (ESM)
28
+ if (typeof mod.buildPack === "function") return mod.buildPack;
29
+ // CJS default export object: { buildPack } or function
30
+ if (mod.default) {
31
+ if (typeof mod.default === "function") return mod.default;
32
+ if (typeof mod.default.buildPack === "function") return mod.default.buildPack;
16
33
  }
17
- const json = JSON.parse(readFileSync(inputFile, 'utf8'));
18
- if (!Array.isArray(json)) {
19
- console.error('Input JSON must be an array of objects');
20
- process.exit(1);
34
+ // Some CJS setups export { buildPack } directly
35
+ if (typeof mod === "function") return mod;
36
+ if (typeof mod.buildPack === "function") return mod.buildPack;
37
+ return undefined;
38
+ }
39
+
40
+ async function loadBuildPack() {
41
+ const candidates = [
42
+ path.resolve(__dirname, "../dist/index.js"),
43
+ path.resolve(__dirname, "../dist/builder.js"),
44
+ // Also try .cjs just in case someone built CJS
45
+ path.resolve(__dirname, "../dist/index.cjs"),
46
+ path.resolve(__dirname, "../dist/builder.cjs"),
47
+ ];
48
+ for (const p of candidates) {
49
+ const mod = await tryImport(p);
50
+ const buildPack = getBuildPack(mod);
51
+ if (buildPack) return buildPack;
21
52
  }
22
- const bytes = await buildPack(json);
23
- writeFileSync(outputFile, Buffer.from(bytes));
24
- console.log(`wrote ${outputFile}`);
53
+ throw new Error("Could not locate a buildPack function in dist/");
25
54
  }
26
55
 
27
- main().catch((err) => {
28
- console.error(err);
56
+ const buildPack = await loadBuildPack();
57
+
58
+ const inFile = process.argv[2];
59
+ const outFile = process.argv[3] || "knowledge.knolo";
60
+
61
+ if (!inFile) {
62
+ console.log("Usage: knolo <input.json> [output.knolo]");
29
63
  process.exit(1);
30
- });
64
+ }
65
+
66
+ const docs = JSON.parse(readFileSync(inFile, "utf8"));
67
+ const bytes = await buildPack(docs);
68
+ writeFileSync(outFile, Buffer.from(bytes));
69
+ console.log(`wrote ${outFile}`);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "knolo-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Local-first knowledge packs for small LLMs.",
5
5
  "keywords": ["llm", "knowledge-base", "rag", "local", "expo"],
6
- "author": "Your Name",
6
+ "author": "Sam Paniagua",
7
7
  "license": "MIT",
8
8
  "main": "./dist/index.js",
9
9
  "types": "./dist/index.d.ts",