@zenera/rag 1.1.10 → 1.1.11
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 +41 -0
- package/dist/common/cache.d.ts +66 -0
- package/dist/common/cache.js +172 -0
- package/dist/common/embedder.d.ts +11 -1
- package/dist/common/embedder.js +6 -17
- package/dist/common/manifest.d.ts +7 -1
- package/dist/common/progress.d.ts +16 -1
- package/dist/common/progress.js +35 -3
- package/dist/common/prose.d.ts +7 -0
- package/dist/common/prose.js +13 -0
- package/dist/docs/build.d.ts +22 -2
- package/dist/docs/build.js +52 -26
- package/dist/docs/command.js +56 -10
- package/dist/docs/load.d.ts +18 -4
- package/dist/docs/load.js +54 -63
- package/dist/docs/outline.d.ts +11 -0
- package/dist/docs/outline.js +55 -0
- package/dist/docs/parse-cache.d.ts +20 -0
- package/dist/docs/parse-cache.js +60 -0
- package/dist/docs/parse-worker.d.ts +13 -0
- package/dist/docs/parse-worker.js +21 -0
- package/dist/docs/pool.d.ts +27 -0
- package/dist/docs/pool.js +133 -0
- package/dist/docs/readme.js +23 -3
- package/dist/docs/store.d.ts +25 -1
- package/dist/docs/store.js +59 -16
- package/dist/schema/build.d.ts +16 -2
- package/dist/schema/build.js +37 -25
- package/dist/schema/command.js +36 -10
- package/dist/schema/readme.js +6 -2
- package/dist/schema/store.d.ts +9 -1
- package/dist/schema/store.js +57 -15
- package/package.json +3 -3
package/dist/schema/store.js
CHANGED
|
@@ -19,27 +19,69 @@ import { lancePath } from "./files.js";
|
|
|
19
19
|
const TABLE = 'entities';
|
|
20
20
|
/** Below this an IVF index has nothing to train on, and a flat scan is faster. */
|
|
21
21
|
const VECTOR_INDEX_MIN_ROWS = 2000;
|
|
22
|
+
/**
|
|
23
|
+
* Rows per write.
|
|
24
|
+
*
|
|
25
|
+
* Arrow addresses a batch's buffers with 32-bit offsets, so one batch carrying
|
|
26
|
+
* more than 2 GiB does not error — it panics inside the reader, on a thread
|
|
27
|
+
* whose panic never reaches this one.
|
|
28
|
+
*/
|
|
29
|
+
const WRITE_BATCH = 8192;
|
|
22
30
|
const KINDS = new Set(['method', 'type', 'property']);
|
|
23
31
|
const DIRECTIONS = new Set(['input', 'output', 'both', 'none']);
|
|
24
32
|
const METHOD_TYPES = new Set(['read_only', 'read_write', 'n/a']);
|
|
25
|
-
export async function
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
export async function openStore(dir) {
|
|
34
|
+
return new Writer(await connect(lancePath(dir)));
|
|
35
|
+
}
|
|
36
|
+
class Writer {
|
|
37
|
+
#db;
|
|
38
|
+
#table;
|
|
39
|
+
#rows = 0;
|
|
40
|
+
constructor(db) {
|
|
41
|
+
this.#db = db;
|
|
28
42
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
async add(rows, vectors) {
|
|
44
|
+
for (let from = 0; from < rows.length; from += WRITE_BATCH) {
|
|
45
|
+
const batch = rows.slice(from, from + WRITE_BATCH).map((row, i) => ({
|
|
46
|
+
...row,
|
|
47
|
+
vector: vectors[from + i],
|
|
48
|
+
}));
|
|
49
|
+
if (this.#table) {
|
|
50
|
+
await this.#table.add(batch);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// Every column is always populated — never null — so the Arrow
|
|
54
|
+
// schema is inferred from the first row without a declaration.
|
|
55
|
+
this.#table = await this.#db.createTable(TABLE, batch, { mode: 'overwrite' });
|
|
56
|
+
}
|
|
57
|
+
this.#rows += batch.length;
|
|
58
|
+
}
|
|
36
59
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
60
|
+
async finish() {
|
|
61
|
+
const table = this.#table;
|
|
62
|
+
if (!table) {
|
|
63
|
+
throw new CliError('the documents describe nothing to index', EXIT.invalid, 'they have no operations and no component schemas');
|
|
64
|
+
}
|
|
65
|
+
// A writer that panicked did not reject, so a short table is the only
|
|
66
|
+
// evidence left that the rows never landed.
|
|
67
|
+
const stored = await table.countRows();
|
|
68
|
+
if (stored !== this.#rows) {
|
|
69
|
+
throw new CliError(`the table holds ${stored} of ${this.#rows} entities`, EXIT.failed, 'the write did not finish, and a partial index answers as if it were whole');
|
|
70
|
+
}
|
|
71
|
+
await table.createIndex('text', { config: Index.fts() });
|
|
72
|
+
for (const column of ['kind', 'direction', 'methodType']) {
|
|
73
|
+
await table.createIndex(column, { config: Index.bitmap() });
|
|
74
|
+
}
|
|
75
|
+
const vector = this.#rows >= VECTOR_INDEX_MIN_ROWS;
|
|
76
|
+
if (vector) {
|
|
77
|
+
await table.createIndex('vector');
|
|
78
|
+
}
|
|
79
|
+
this.#db.close();
|
|
80
|
+
return { rows: this.#rows, fts: true, vector };
|
|
81
|
+
}
|
|
82
|
+
close() {
|
|
83
|
+
this.#db.close();
|
|
40
84
|
}
|
|
41
|
-
db.close();
|
|
42
|
-
return { rows: rows.length, fts: true, vector };
|
|
43
85
|
}
|
|
44
86
|
export class EntityStore {
|
|
45
87
|
#db;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenera/rag",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "Retrieval over a corpus: openapi/swagger documents as a searchable graph, markdown and text as searchable passages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@apidevtools/swagger-parser": "^12.0.0",
|
|
63
63
|
"@lancedb/lancedb": "^0.38.0",
|
|
64
|
-
"@zenera/cli": "^1.1.
|
|
65
|
-
"@zenera/neo": "^1.1.
|
|
64
|
+
"@zenera/cli": "^1.1.11",
|
|
65
|
+
"@zenera/neo": "^1.1.11",
|
|
66
66
|
"graphology": "^0.26.0",
|
|
67
67
|
"remark-frontmatter": "^5.0.0",
|
|
68
68
|
"remark-gfm": "^4.0.1",
|