brainbank 0.8.6 → 0.9.0
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 +9 -0
- package/dist/{chunk-IRKE4KMJ.js → chunk-Z54MHEYW.js} +47 -15
- package/dist/chunk-Z54MHEYW.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/package.json +5 -4
- package/src/db/adapter.ts +3 -3
- package/src/db/sqlite-adapter.ts +32 -22
- package/src/engine/reembed.ts +2 -2
- package/src/providers/vector/hnsw-loader.ts +2 -2
- package/dist/chunk-IRKE4KMJ.js.map +0 -1
package/README.md
CHANGED
|
@@ -24,6 +24,15 @@ BrainBank gives LLMs a long-term memory that persists between sessions.
|
|
|
24
24
|
npm i -g brainbank @brainbank/code @brainbank/git @brainbank/docs
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
> [!IMPORTANT]
|
|
28
|
+
> **Node 23+ users:** `@brainbank/code` uses [tree-sitter](https://github.com/tree-sitter/node-tree-sitter) native bindings for AST parsing. On **Node 23 and 24**, V8 headers require C++20 but tree-sitter's `binding.gyp` defaults to C++17, causing the install to fail with `"C++20 or later required."`. Fix it by setting the C++ standard before install:
|
|
29
|
+
>
|
|
30
|
+
> ```bash
|
|
31
|
+
> CXXFLAGS="-std=c++20" npm i -g brainbank
|
|
32
|
+
> ```
|
|
33
|
+
>
|
|
34
|
+
> Node ≤22 is unaffected — prebuilt binaries are available and no compilation is needed.
|
|
35
|
+
|
|
27
36
|
> If you get `ERESOLVE` errors, use `npm i --legacy-peer-deps` — tree-sitter grammars have overlapping peer dep ranges.
|
|
28
37
|
|
|
29
38
|
### CLI — zero code
|
|
@@ -65,7 +65,7 @@ var HNSW = {
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
// src/db/sqlite-adapter.ts
|
|
68
|
-
import
|
|
68
|
+
import { DatabaseSync } from "node:sqlite";
|
|
69
69
|
import * as fs from "fs";
|
|
70
70
|
import * as path2 from "path";
|
|
71
71
|
var SCHEMA_VERSION = 9;
|
|
@@ -158,7 +158,7 @@ function wrapStatement(stmt) {
|
|
|
158
158
|
const info = stmt.run(...params);
|
|
159
159
|
return {
|
|
160
160
|
lastInsertRowid: info.lastInsertRowid,
|
|
161
|
-
changes: info.changes
|
|
161
|
+
changes: Number(info.changes)
|
|
162
162
|
};
|
|
163
163
|
},
|
|
164
164
|
iterate(...params) {
|
|
@@ -183,11 +183,11 @@ var SQLiteAdapter = class {
|
|
|
183
183
|
if (!fs.existsSync(dir)) {
|
|
184
184
|
fs.mkdirSync(dir, { recursive: true });
|
|
185
185
|
}
|
|
186
|
-
this._db = new
|
|
187
|
-
this._db.
|
|
188
|
-
this._db.
|
|
189
|
-
this._db.
|
|
190
|
-
this._db.
|
|
186
|
+
this._db = new DatabaseSync(dbPath);
|
|
187
|
+
this._db.exec("PRAGMA journal_mode = WAL");
|
|
188
|
+
this._db.exec("PRAGMA busy_timeout = 5000");
|
|
189
|
+
this._db.exec("PRAGMA synchronous = NORMAL");
|
|
190
|
+
this._db.exec("PRAGMA foreign_keys = ON");
|
|
191
191
|
createSchema(this);
|
|
192
192
|
}
|
|
193
193
|
/** Prepare a reusable statement. */
|
|
@@ -200,25 +200,31 @@ var SQLiteAdapter = class {
|
|
|
200
200
|
}
|
|
201
201
|
/** Run a function inside a transaction. Auto-commits on success, auto-rollbacks on error. */
|
|
202
202
|
transaction(fn) {
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
this._db.exec("BEGIN");
|
|
204
|
+
try {
|
|
205
|
+
const result = fn();
|
|
206
|
+
this._db.exec("COMMIT");
|
|
207
|
+
return result;
|
|
208
|
+
} catch (err) {
|
|
209
|
+
this._db.exec("ROLLBACK");
|
|
210
|
+
throw err;
|
|
211
|
+
}
|
|
205
212
|
}
|
|
206
213
|
/** Run a prepared statement on multiple rows. Wraps in a single transaction. */
|
|
207
214
|
batch(sql, rows) {
|
|
208
215
|
const stmt = this._db.prepare(sql);
|
|
209
|
-
|
|
216
|
+
this.transaction(() => {
|
|
210
217
|
for (const row of rows) {
|
|
211
218
|
stmt.run(...row);
|
|
212
219
|
}
|
|
213
220
|
});
|
|
214
|
-
tx();
|
|
215
221
|
}
|
|
216
222
|
/** Close the database. */
|
|
217
223
|
close() {
|
|
218
224
|
this._db.close();
|
|
219
225
|
}
|
|
220
226
|
/**
|
|
221
|
-
* Access the underlying `
|
|
227
|
+
* Access the underlying `node:sqlite` DatabaseSync instance.
|
|
222
228
|
*
|
|
223
229
|
* @deprecated Use `DatabaseAdapter` methods instead. This exists
|
|
224
230
|
* only for gradual migration of plugins that depend on driver internals.
|
|
@@ -661,6 +667,13 @@ var ContextBuilder = class {
|
|
|
661
667
|
this._configFields = _configFields;
|
|
662
668
|
this._expander = _expander;
|
|
663
669
|
}
|
|
670
|
+
_search;
|
|
671
|
+
_registry;
|
|
672
|
+
_pruner;
|
|
673
|
+
_embedding;
|
|
674
|
+
_rerankerName;
|
|
675
|
+
_configFields;
|
|
676
|
+
_expander;
|
|
664
677
|
static {
|
|
665
678
|
__name(this, "ContextBuilder");
|
|
666
679
|
}
|
|
@@ -872,6 +885,7 @@ var CompositeBM25Search = class {
|
|
|
872
885
|
constructor(_registry) {
|
|
873
886
|
this._registry = _registry;
|
|
874
887
|
}
|
|
888
|
+
_registry;
|
|
875
889
|
static {
|
|
876
890
|
__name(this, "CompositeBM25Search");
|
|
877
891
|
}
|
|
@@ -917,6 +931,7 @@ var CompositeVectorSearch = class _CompositeVectorSearch {
|
|
|
917
931
|
constructor(_c) {
|
|
918
932
|
this._c = _c;
|
|
919
933
|
}
|
|
934
|
+
_c;
|
|
920
935
|
static {
|
|
921
936
|
__name(this, "CompositeVectorSearch");
|
|
922
937
|
}
|
|
@@ -969,6 +984,11 @@ var HNSWIndex = class {
|
|
|
969
984
|
this._efConstruction = _efConstruction;
|
|
970
985
|
this._efSearch = _efSearch;
|
|
971
986
|
}
|
|
987
|
+
_dims;
|
|
988
|
+
_maxElements;
|
|
989
|
+
_M;
|
|
990
|
+
_efConstruction;
|
|
991
|
+
_efSearch;
|
|
972
992
|
static {
|
|
973
993
|
__name(this, "HNSWIndex");
|
|
974
994
|
}
|
|
@@ -1120,6 +1140,12 @@ var Collection = class {
|
|
|
1120
1140
|
this._vecs = _vecs;
|
|
1121
1141
|
this._reranker = _reranker;
|
|
1122
1142
|
}
|
|
1143
|
+
_name;
|
|
1144
|
+
_db;
|
|
1145
|
+
_embedding;
|
|
1146
|
+
_hnsw;
|
|
1147
|
+
_vecs;
|
|
1148
|
+
_reranker;
|
|
1123
1149
|
static {
|
|
1124
1150
|
__name(this, "Collection");
|
|
1125
1151
|
}
|
|
@@ -1397,6 +1423,11 @@ var KVService = class {
|
|
|
1397
1423
|
this._vecs = _vecs;
|
|
1398
1424
|
this._reranker = _reranker;
|
|
1399
1425
|
}
|
|
1426
|
+
_db;
|
|
1427
|
+
_embedding;
|
|
1428
|
+
_hnsw;
|
|
1429
|
+
_vecs;
|
|
1430
|
+
_reranker;
|
|
1400
1431
|
static {
|
|
1401
1432
|
__name(this, "KVService");
|
|
1402
1433
|
}
|
|
@@ -2097,8 +2128,8 @@ async function rebuildHnsw(db, table, hnsw, vecs) {
|
|
|
2097
2128
|
`SELECT ${table.fkColumn} as id, embedding FROM ${table.vectorTable}`
|
|
2098
2129
|
).all();
|
|
2099
2130
|
for (const row of rows) {
|
|
2100
|
-
const
|
|
2101
|
-
const vec = new Float32Array(
|
|
2131
|
+
const emb = row.embedding;
|
|
2132
|
+
const vec = new Float32Array(emb.buffer.slice(emb.byteOffset, emb.byteOffset + emb.byteLength));
|
|
2102
2133
|
hnsw.add(vec, row.id);
|
|
2103
2134
|
vecs.set(row.id, vec);
|
|
2104
2135
|
}
|
|
@@ -2138,6 +2169,7 @@ var SearchAPI = class {
|
|
|
2138
2169
|
constructor(_d) {
|
|
2139
2170
|
this._d = _d;
|
|
2140
2171
|
}
|
|
2172
|
+
_d;
|
|
2141
2173
|
static {
|
|
2142
2174
|
__name(this, "SearchAPI");
|
|
2143
2175
|
}
|
|
@@ -3283,4 +3315,4 @@ export {
|
|
|
3283
3315
|
resetFactoryCache,
|
|
3284
3316
|
createBrain
|
|
3285
3317
|
};
|
|
3286
|
-
//# sourceMappingURL=chunk-
|
|
3318
|
+
//# sourceMappingURL=chunk-Z54MHEYW.js.map
|