@zenera/rag 1.1.8 → 1.1.10
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 +154 -10
- package/dist/command.js +2 -1
- package/dist/docs/assemble.d.ts +52 -0
- package/dist/docs/assemble.js +127 -0
- package/dist/docs/build.d.ts +34 -0
- package/dist/docs/build.js +108 -0
- package/dist/docs/chunk.d.ts +73 -0
- package/dist/docs/chunk.js +586 -0
- package/dist/docs/command.d.ts +3 -0
- package/dist/docs/command.js +529 -0
- package/dist/docs/files.d.ts +94 -0
- package/dist/docs/files.js +80 -0
- package/dist/docs/index.d.ts +13 -0
- package/dist/docs/index.js +13 -0
- package/dist/docs/load.d.ts +28 -0
- package/dist/docs/load.js +212 -0
- package/dist/docs/lookup.d.ts +80 -0
- package/dist/docs/lookup.js +147 -0
- package/dist/docs/parse.d.ts +95 -0
- package/dist/docs/parse.js +372 -0
- package/dist/docs/readme.d.ts +6 -0
- package/dist/docs/readme.js +122 -0
- package/dist/docs/render.d.ts +13 -0
- package/dist/docs/render.js +46 -0
- package/dist/docs/repl.d.ts +7 -0
- package/dist/docs/repl.js +130 -0
- package/dist/docs/search.d.ts +92 -0
- package/dist/docs/search.js +251 -0
- package/dist/docs/store.d.ts +55 -0
- package/dist/docs/store.js +171 -0
- package/dist/docs/tools.d.ts +10 -0
- package/dist/docs/tools.js +300 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/schema/command.js +3 -0
- package/dist/schema/query.js +1 -0
- package/dist/schema/search.d.ts +2 -0
- package/dist/schema/search.js +18 -2
- package/dist/schema/store.d.ts +4 -2
- package/dist/schema/store.js +16 -9
- package/dist/schema/tools.js +21 -2
- package/package.json +17 -4
package/dist/schema/store.js
CHANGED
|
@@ -8,10 +8,13 @@ import { lancePath } from "./files.js";
|
|
|
8
8
|
// carrying both the embedding and the full-text index, and the handful of
|
|
9
9
|
// enum columns a query filters on.
|
|
10
10
|
//
|
|
11
|
-
// Those
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
11
|
+
// Those closed vocabularies are the *only* thing that reaches the SQL
|
|
12
|
+
// predicate. `source` is one of them: its values are the document names the
|
|
13
|
+
// index itself wrote, so the store is opened with that list and checks against
|
|
14
|
+
// it. Exclusion lists — which arrive from a model, or from a shell — are
|
|
15
|
+
// applied afterwards in JavaScript. Escaping those into `where()` would work
|
|
16
|
+
// right up until it did not, and there is nothing here that a filter string
|
|
17
|
+
// buys.
|
|
15
18
|
// ---------------------------------------------------------------------------
|
|
16
19
|
const TABLE = 'entities';
|
|
17
20
|
/** Below this an IVF index has nothing to train on, and a flat scan is faster. */
|
|
@@ -41,14 +44,17 @@ export async function writeStore(dir, rows, vectors) {
|
|
|
41
44
|
export class EntityStore {
|
|
42
45
|
#db;
|
|
43
46
|
#table;
|
|
44
|
-
|
|
47
|
+
#sources;
|
|
48
|
+
constructor(db, table, sources = []) {
|
|
45
49
|
this.#db = db;
|
|
46
50
|
this.#table = table;
|
|
51
|
+
this.#sources = new Set(sources);
|
|
47
52
|
}
|
|
48
|
-
|
|
53
|
+
/** `sources` is the document vocabulary a `sources` filter is checked against. */
|
|
54
|
+
static async open(dir, sources = []) {
|
|
49
55
|
const db = await connect(lancePath(dir));
|
|
50
56
|
try {
|
|
51
|
-
return new EntityStore(db, await db.openTable(TABLE));
|
|
57
|
+
return new EntityStore(db, await db.openTable(TABLE), sources);
|
|
52
58
|
}
|
|
53
59
|
catch {
|
|
54
60
|
db.close();
|
|
@@ -60,7 +66,7 @@ export class EntityStore {
|
|
|
60
66
|
* vector, to the nearest-neighbour side, and LanceDB fuses the two.
|
|
61
67
|
*/
|
|
62
68
|
async search(text, vector, filter, limit) {
|
|
63
|
-
const predicate = where(filter);
|
|
69
|
+
const predicate = where(filter, this.#sources);
|
|
64
70
|
let query = this.#table.query().nearestToText(text).nearestTo(vector).limit(limit);
|
|
65
71
|
if (predicate) {
|
|
66
72
|
query = query.where(predicate);
|
|
@@ -78,11 +84,12 @@ export class EntityStore {
|
|
|
78
84
|
}
|
|
79
85
|
// ---------------------------------------------------------------------------
|
|
80
86
|
/** Closed vocabularies only. Anything else is a bug, and is treated as one. */
|
|
81
|
-
function where(filter) {
|
|
87
|
+
function where(filter, sources) {
|
|
82
88
|
const clauses = [
|
|
83
89
|
clause('kind', filter.kinds, KINDS),
|
|
84
90
|
clause('direction', filter.directions, DIRECTIONS),
|
|
85
91
|
clause('methodType', filter.methodTypes, METHOD_TYPES),
|
|
92
|
+
clause('source', filter.sources, sources),
|
|
86
93
|
].filter(Boolean);
|
|
87
94
|
return clauses.join(' AND ');
|
|
88
95
|
}
|
package/dist/schema/tools.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { tool } from '@zenera/neo';
|
|
2
2
|
import { loose, matcher, PatternError } from "../common/match.js";
|
|
3
|
-
import { FORMATS, isFormat, present } from "./present.js";
|
|
4
|
-
import { isEmpty, parseQuery, QueryError } from "./query.js";
|
|
5
3
|
import { toTypeScript } from "./hydrate.js";
|
|
6
4
|
import { fields, grepNodes, listNodes, propertyCount } from "./lookup.js";
|
|
5
|
+
import { FORMATS, isFormat, present } from "./present.js";
|
|
6
|
+
import { isEmpty, parseQuery, QueryError } from "./query.js";
|
|
7
7
|
import { sourceTag } from "./render.js";
|
|
8
8
|
import { stitch } from "./subgraph.js";
|
|
9
9
|
import { chainOf, traceNodes } from "./trace.js";
|
|
@@ -47,6 +47,7 @@ export function schemaTools(index, options = {}) {
|
|
|
47
47
|
// line is prompt spent saying the same word; with several it is the only
|
|
48
48
|
// way to tell two revisions of one API apart.
|
|
49
49
|
const source = options.source ?? index.manifest.sources.length > 1;
|
|
50
|
+
const names = index.manifest.sources.map((s) => s.name);
|
|
50
51
|
const searchApi = tool({
|
|
51
52
|
name: 'search_api',
|
|
52
53
|
group: GROUP,
|
|
@@ -81,6 +82,17 @@ export function schemaTools(index, options = {}) {
|
|
|
81
82
|
exclude_methods: list('Operation names to leave out.'),
|
|
82
83
|
exclude_types: list('Schema names to leave out.'),
|
|
83
84
|
exclude_properties: list('Field names to leave out.'),
|
|
85
|
+
// Naming the documents is only a choice when there is more than
|
|
86
|
+
// one, and an enum is what stops a model inventing a third.
|
|
87
|
+
...(names.length > 1
|
|
88
|
+
? {
|
|
89
|
+
sources: {
|
|
90
|
+
type: 'array',
|
|
91
|
+
items: { type: 'string', enum: names },
|
|
92
|
+
description: 'Search only these documents. Omit it to search all of them.',
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
: {}),
|
|
84
96
|
limit: {
|
|
85
97
|
type: 'integer',
|
|
86
98
|
description: `Results per phrase. Default ${DEFAULT_LIMIT}.`,
|
|
@@ -111,6 +123,13 @@ export function schemaTools(index, options = {}) {
|
|
|
111
123
|
if (isEmpty(query)) {
|
|
112
124
|
return { error: 'nothing was asked for', hint: 'fill at least one search field' };
|
|
113
125
|
}
|
|
126
|
+
const absent = (query.sources ?? []).filter((name) => !names.includes(name));
|
|
127
|
+
if (absent.length > 0) {
|
|
128
|
+
return {
|
|
129
|
+
error: `no document called ${absent.join(', ')}`,
|
|
130
|
+
hint: `it has: ${names.join(', ')}`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
114
133
|
const result = await index.search({
|
|
115
134
|
limit: DEFAULT_LIMIT,
|
|
116
135
|
max_nodes: DEFAULT_MAX_NODES,
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenera/rag",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Retrieval over
|
|
3
|
+
"version": "1.1.10",
|
|
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",
|
|
7
7
|
"ai-agents",
|
|
8
8
|
"llm",
|
|
9
|
+
"markdown",
|
|
9
10
|
"openapi",
|
|
10
11
|
"rag",
|
|
11
12
|
"vector-search"
|
|
@@ -35,6 +36,14 @@
|
|
|
35
36
|
"./tools": {
|
|
36
37
|
"types": "./dist/schema/tools.d.ts",
|
|
37
38
|
"default": "./dist/schema/tools.js"
|
|
39
|
+
},
|
|
40
|
+
"./docs": {
|
|
41
|
+
"types": "./dist/docs/index.d.ts",
|
|
42
|
+
"default": "./dist/docs/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./docs/tools": {
|
|
45
|
+
"types": "./dist/docs/tools.d.ts",
|
|
46
|
+
"default": "./dist/docs/tools.js"
|
|
38
47
|
}
|
|
39
48
|
},
|
|
40
49
|
"files": [
|
|
@@ -52,8 +61,12 @@
|
|
|
52
61
|
"dependencies": {
|
|
53
62
|
"@apidevtools/swagger-parser": "^12.0.0",
|
|
54
63
|
"@lancedb/lancedb": "^0.38.0",
|
|
64
|
+
"@zenera/cli": "^1.1.10",
|
|
65
|
+
"@zenera/neo": "^1.1.10",
|
|
55
66
|
"graphology": "^0.26.0",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
67
|
+
"remark-frontmatter": "^5.0.0",
|
|
68
|
+
"remark-gfm": "^4.0.1",
|
|
69
|
+
"remark-parse": "^11.0.0",
|
|
70
|
+
"unified": "^11.0.5"
|
|
58
71
|
}
|
|
59
72
|
}
|