@zenera/rag 1.1.10 → 1.1.12
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 +43 -2
- 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 +57 -11
- package/dist/docs/load.d.ts +18 -4
- package/dist/docs/load.js +55 -64
- 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/docs/tools.js +2 -2
- 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/readme.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { basename } from 'node:path';
|
|
2
2
|
import { INTERVAL_MS } from "../common/progress.js";
|
|
3
|
-
import { duration, fields, grid, message, plural, searched } from "../common/prose.js";
|
|
3
|
+
import { breakdown, duration, fields, grid, message, plural, searched } from "../common/prose.js";
|
|
4
4
|
export const PHASES = {
|
|
5
5
|
reading: 'reading the documents',
|
|
6
6
|
graph: 'building the graph',
|
|
@@ -22,9 +22,10 @@ function building(state) {
|
|
|
22
22
|
rows.push(['found', entities(state.summary)]);
|
|
23
23
|
}
|
|
24
24
|
if (state.total > 0) {
|
|
25
|
-
const percent = Math.
|
|
25
|
+
const percent = Math.floor((state.done / state.total) * 100);
|
|
26
26
|
rows.push(['embedded', `${state.done} of ${state.total} · ${percent}%`]);
|
|
27
27
|
}
|
|
28
|
+
rows.push(['timing', breakdown(state.timings)]);
|
|
28
29
|
rows.push(['updated', new Date(state.now).toISOString()]);
|
|
29
30
|
return [
|
|
30
31
|
'# Schema index — being built',
|
|
@@ -60,6 +61,8 @@ function complete(state) {
|
|
|
60
61
|
`${entities(manifest.counts)},`,
|
|
61
62
|
`${searched(manifest.indexes)}.`,
|
|
62
63
|
'',
|
|
64
|
+
`Time: ${breakdown(state.timings)}.`,
|
|
65
|
+
'',
|
|
63
66
|
'## Files',
|
|
64
67
|
'',
|
|
65
68
|
...fields([
|
|
@@ -97,6 +100,7 @@ function failed(state) {
|
|
|
97
100
|
['step', state.step],
|
|
98
101
|
['reason', message(state.reason)],
|
|
99
102
|
['started', new Date(state.started).toISOString()],
|
|
103
|
+
['timing', breakdown(state.timings)],
|
|
100
104
|
[
|
|
101
105
|
'failed',
|
|
102
106
|
`${new Date().toISOString()} (after ${duration(Date.now() - state.started)})`,
|
package/dist/schema/store.d.ts
CHANGED
|
@@ -18,7 +18,15 @@ export interface WriteResult {
|
|
|
18
18
|
fts: boolean;
|
|
19
19
|
vector: boolean;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
/** A table built a window at a time, so peak memory is not a function of size. */
|
|
22
|
+
export interface EntityWriter {
|
|
23
|
+
add(rows: readonly EntityRecord[], vectors: readonly Float32Array[]): Promise<void>;
|
|
24
|
+
/** Builds the indexes and closes. Throws if nothing was ever added. */
|
|
25
|
+
finish(): Promise<WriteResult>;
|
|
26
|
+
/** For a build that failed, so the connection does not outlive it. */
|
|
27
|
+
close(): void;
|
|
28
|
+
}
|
|
29
|
+
export declare function openStore(dir: string): Promise<EntityWriter>;
|
|
22
30
|
export declare class EntityStore {
|
|
23
31
|
#private;
|
|
24
32
|
constructor(db: Connection, table: Table, sources?: readonly string[]);
|
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.12",
|
|
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.12",
|
|
65
|
+
"@zenera/neo": "^1.1.12",
|
|
66
66
|
"graphology": "^0.26.0",
|
|
67
67
|
"remark-frontmatter": "^5.0.0",
|
|
68
68
|
"remark-gfm": "^4.0.1",
|