@jcode.labs/ragmir 2.14.0 → 2.16.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 +41 -30
- package/dist/client.d.ts +28 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +87 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/index-write-lock.d.ts +2 -0
- package/dist/index-write-lock.d.ts.map +1 -0
- package/dist/index-write-lock.js +46 -0
- package/dist/index-write-lock.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/ingest.d.ts +3 -1
- package/dist/ingest.d.ts.map +1 -1
- package/dist/ingest.js +25 -8
- package/dist/ingest.js.map +1 -1
- package/dist/mcp.d.ts +4 -0
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +21 -10
- package/dist/mcp.js.map +1 -1
- package/dist/operation.d.ts +4 -0
- package/dist/operation.d.ts.map +1 -0
- package/dist/operation.js +52 -0
- package/dist/operation.js.map +1 -0
- package/dist/query.d.ts +5 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +27 -4
- package/dist/query.js.map +1 -1
- package/dist/research.d.ts +3 -1
- package/dist/research.d.ts.map +1 -1
- package/dist/research.js +18 -6
- package/dist/research.js.map +1 -1
- package/dist/store.d.ts +4 -3
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +61 -35
- package/dist/store.js.map +1 -1
- package/dist/types.d.ts +8 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/examples/library-api-demo/README.md +19 -19
- package/examples/library-api-demo/run.mjs +30 -24
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @jcode.labs/ragmir
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@jcode.labs/ragmir)
|
|
4
4
|
[](https://www.npmjs.com/package/@jcode.labs/ragmir)
|
|
5
5
|
[](https://www.npmjs.com/package/@jcode.labs/ragmir)
|
|
6
6
|
[](https://github.com/jcode-works/jcode-ragmir/blob/main/LICENSE)
|
|
7
7
|
|
|
8
|
-
**Local RAG
|
|
8
|
+
**Local RAG for your coding agents.**
|
|
9
9
|
|
|
10
|
-
`@jcode.labs/ragmir` indexes the files
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
`@jcode.labs/ragmir` indexes the project files you select, keeps the index on your machine, and
|
|
11
|
+
returns bounded evidence with verifiable citations. Your coding agent or local script gets the
|
|
12
|
+
context it needs without a hosted document store. The default `local-hash` path works offline,
|
|
13
|
+
without an account or model download.
|
|
13
14
|
|
|
14
|
-
Core is
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
Core is model-agnostic. Connect the coding agent or local script you already use through generated
|
|
16
|
+
project skills, local MCP, or the JSON CLI. Use the typed Node.js API when your application owns the
|
|
17
|
+
control flow.
|
|
17
18
|
|
|
18
19
|
[Project overview](https://github.com/jcode-works/jcode-ragmir#readme) ·
|
|
19
20
|
[Documentation](https://github.com/jcode-works/jcode-ragmir/wiki) ·
|
|
20
21
|
[CLI reference](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/cli-reference.md) ·
|
|
21
22
|
[API reference](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/api-reference.md)
|
|
22
23
|
|
|
23
|
-
##
|
|
24
|
+
## What your coding agent gains
|
|
24
25
|
|
|
25
26
|
| Goal | Core interface |
|
|
26
27
|
| --- | --- |
|
|
@@ -30,12 +31,12 @@ workstation, or call the typed API from Node.js.
|
|
|
30
31
|
| Give an agent bounded project context | Local stdio MCP server and generated helpers |
|
|
31
32
|
| Index scanned PDFs | Embedded text first, with optional page-aware local OCR |
|
|
32
33
|
|
|
33
|
-
Core retrieves cited evidence. It does not require a generative model or generate answers.
|
|
34
|
-
[Ragmir Chat](https://www.npmjs.com/package/@jcode.labs/ragmir-chat) only when local
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
Core retrieves cited evidence. It does not require a generative model or generate answers. Use
|
|
35
|
+
[Ragmir Chat](https://www.npmjs.com/package/@jcode.labs/ragmir-chat) only when local GGUF synthesis
|
|
36
|
+
is useful, or [Ragmir TTS](https://www.npmjs.com/package/@jcode.labs/ragmir-tts) when you need audio
|
|
37
|
+
output.
|
|
37
38
|
|
|
38
|
-
##
|
|
39
|
+
## Connect a coding agent in minutes
|
|
39
40
|
|
|
40
41
|
Requires Node.js 20 or later.
|
|
41
42
|
|
|
@@ -62,7 +63,7 @@ The same setup works with any compatible MCP client. Hermes can launch `.ragmir/
|
|
|
62
63
|
scripts, CI, and internal tools can call the JSON CLI or the TypeScript API without a dedicated
|
|
63
64
|
connector.
|
|
64
65
|
|
|
65
|
-
## Use
|
|
66
|
+
## Use the same evidence from an automation
|
|
66
67
|
|
|
67
68
|
```bash
|
|
68
69
|
npx rgr search "Should this renewal require approval?" --compact --json
|
|
@@ -72,9 +73,9 @@ Use that command from a local shell script, a Node.js worker, or a CI step after
|
|
|
72
73
|
and its local `.ragmir/` state. The process returns machine-readable cited passages; the workflow
|
|
73
74
|
decides whether to continue, request human approval, or stop.
|
|
74
75
|
|
|
75
|
-
For long-running integrations, start the local stdio server with `npx rgr serve-mcp`.
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
For long-running agent integrations, start the local stdio server with `npx rgr serve-mcp`. For a
|
|
77
|
+
Node.js worker that owns the control flow, use `createRagmirClient()` and reuse one client per project
|
|
78
|
+
root. Ragmir does not open an HTTP port or define an authentication layer.
|
|
78
79
|
|
|
79
80
|
## Search directly from the CLI
|
|
80
81
|
|
|
@@ -112,20 +113,29 @@ multi-query retrieval pass and reports missing or weak evidence.
|
|
|
112
113
|
## TypeScript API
|
|
113
114
|
|
|
114
115
|
```ts
|
|
115
|
-
import {
|
|
116
|
-
|
|
117
|
-
await
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
116
|
+
import { createRagmirClient } from "@jcode.labs/ragmir"
|
|
117
|
+
|
|
118
|
+
const ragmir = await createRagmirClient({ cwd: process.cwd() })
|
|
119
|
+
try {
|
|
120
|
+
await ragmir.ingest({ timeoutMs: 120_000 })
|
|
121
|
+
|
|
122
|
+
const results = await ragmir.search("Which decision changed the rollout?", {
|
|
123
|
+
topK: 5,
|
|
124
|
+
timeoutMs: 10_000,
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
for (const result of results) {
|
|
128
|
+
console.log(result.citation, result.text)
|
|
129
|
+
}
|
|
130
|
+
} finally {
|
|
131
|
+
await ragmir.close()
|
|
126
132
|
}
|
|
127
133
|
```
|
|
128
134
|
|
|
135
|
+
The persistent client reuses one local database connection, supports cooperative cancellation, and
|
|
136
|
+
waits for active work before shutdown. The top-level functions remain the smallest API for one-shot
|
|
137
|
+
scripts.
|
|
138
|
+
|
|
129
139
|
Frequently used exports:
|
|
130
140
|
|
|
131
141
|
| Export | Purpose |
|
|
@@ -133,11 +143,12 @@ Frequently used exports:
|
|
|
133
143
|
| `setupProject`, `addSourceEntries` | Initialize project state and select files |
|
|
134
144
|
| `discoverKnowledgeBases`, `knowledgeBaseIdentity` | Route root and nested monorepo bases |
|
|
135
145
|
| `getKnowledgeBaseContext`, `getKnowledgeBaseSourceCatalog` | Give agents bounded readiness and source context |
|
|
146
|
+
| `createRagmirClient`, `RagmirClient` | Reuse local retrieval safely in a stateful Node.js process |
|
|
136
147
|
| `ingest`, `audit` | Build the index and compare it with files on disk |
|
|
137
148
|
| `previewChunks` | Inspect redacted chunks and distributions without writing storage |
|
|
138
149
|
| `search`, `ask`, `research`, `expandCitation` | Retrieve or expand cited passages |
|
|
139
150
|
| `doctor`, `securityAudit` | Inspect readiness and local privacy posture |
|
|
140
|
-
| `serveMcp` |
|
|
151
|
+
| `createMcpServer`, `connectMcpServer`, `serveMcp` | Construct, connect, or start the read-focused local MCP server |
|
|
141
152
|
| `configurePdfOcr`, `inspectPdfOcr` | Configure and inspect local PDF OCR |
|
|
142
153
|
|
|
143
154
|
See the [complete API reference](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/api-reference.md)
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PathLike } from "node:fs";
|
|
2
|
+
import type { AskResult, ExpandCitationOptions, ExpandedCitation, IngestOptions, IngestResult, KnowledgeBaseContextReport, KnowledgeBaseSourceCatalog, ResearchOptions, ResearchReport, SearchOptions, SearchResult } from "./types.js";
|
|
3
|
+
export interface RagmirClientOptions {
|
|
4
|
+
cwd?: PathLike;
|
|
5
|
+
}
|
|
6
|
+
export declare class RagmirClient {
|
|
7
|
+
readonly projectRoot: string;
|
|
8
|
+
private readonly config;
|
|
9
|
+
private readonly connection;
|
|
10
|
+
private readonly activeOperations;
|
|
11
|
+
private closed;
|
|
12
|
+
private closePromise;
|
|
13
|
+
private constructor();
|
|
14
|
+
get isClosed(): boolean;
|
|
15
|
+
static create(options?: RagmirClientOptions): Promise<RagmirClient>;
|
|
16
|
+
ingest(options?: Omit<IngestOptions, "cwd">): Promise<IngestResult>;
|
|
17
|
+
search(query: string, options?: Omit<SearchOptions, "cwd">): Promise<SearchResult[]>;
|
|
18
|
+
ask(query: string, options?: Omit<SearchOptions, "cwd">): Promise<AskResult>;
|
|
19
|
+
research(query: string, options?: Omit<ResearchOptions, "cwd">): Promise<ResearchReport>;
|
|
20
|
+
expandCitation(citation: string, options?: Omit<ExpandCitationOptions, "cwd">): Promise<ExpandedCitation>;
|
|
21
|
+
status(): Promise<KnowledgeBaseContextReport>;
|
|
22
|
+
sources(): Promise<KnowledgeBaseSourceCatalog>;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
private assertOpen;
|
|
25
|
+
private run;
|
|
26
|
+
}
|
|
27
|
+
export declare function createRagmirClient(options?: RagmirClientOptions): Promise<RagmirClient>;
|
|
28
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AASvC,OAAO,KAAK,EACV,SAAS,EAET,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,0BAA0B,EAC1B,0BAA0B,EAC1B,eAAe,EACf,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,EAAE,QAAQ,CAAA;CACf;AAED,qBAAa,YAAY;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8B;IAC/D,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAA2B;IAE/C,OAAO;IAMP,IAAI,QAAQ,IAAI,OAAO,CAEtB;WAEY,MAAM,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,YAAY,CAAC;IAUvE,MAAM,CAAC,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,KAAK,CAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAIvE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,KAAK,CAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAIxF,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,KAAK,CAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAIhF,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,IAAI,CAAC,eAAe,EAAE,KAAK,CAAM,GACzC,OAAO,CAAC,cAAc,CAAC;IAIpB,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAM,GAC/C,OAAO,CAAC,gBAAgB,CAAC;IAItB,MAAM,IAAI,OAAO,CAAC,0BAA0B,CAAC;IAI7C,OAAO,IAAI,OAAO,CAAC,0BAA0B,CAAC;IAI9C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,GAAG;CAgBZ;AAED,wBAAsB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,YAAY,CAAC,CAEjG"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { loadConfig } from "./config.js";
|
|
2
|
+
import { getKnowledgeBaseContext, getKnowledgeBaseSourceCatalog } from "./context-resources.js";
|
|
3
|
+
import { normalizeRagmirError, RagmirError } from "./errors.js";
|
|
4
|
+
import { ingestWithConfig } from "./ingest.js";
|
|
5
|
+
import { askWithConfig, expandCitationWithConfig, searchWithConfig } from "./query.js";
|
|
6
|
+
import { researchWithConfig } from "./research.js";
|
|
7
|
+
import { connectStore } from "./store.js";
|
|
8
|
+
export class RagmirClient {
|
|
9
|
+
projectRoot;
|
|
10
|
+
config;
|
|
11
|
+
connection;
|
|
12
|
+
activeOperations = new Set();
|
|
13
|
+
closed = false;
|
|
14
|
+
closePromise;
|
|
15
|
+
constructor(config, connection) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.connection = connection;
|
|
18
|
+
this.projectRoot = config.projectRoot;
|
|
19
|
+
}
|
|
20
|
+
get isClosed() {
|
|
21
|
+
return this.closed;
|
|
22
|
+
}
|
|
23
|
+
static async create(options = {}) {
|
|
24
|
+
try {
|
|
25
|
+
const config = await loadConfig(String(options.cwd ?? process.cwd()));
|
|
26
|
+
const connection = await connectStore(config);
|
|
27
|
+
return new RagmirClient(config, connection);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw normalizeRagmirError(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async ingest(options = {}) {
|
|
34
|
+
return this.run(() => ingestWithConfig(this.config, options, this.connection));
|
|
35
|
+
}
|
|
36
|
+
async search(query, options = {}) {
|
|
37
|
+
return this.run(() => searchWithConfig(query, options, this.config, this.connection));
|
|
38
|
+
}
|
|
39
|
+
async ask(query, options = {}) {
|
|
40
|
+
return this.run(() => askWithConfig(query, options, this.config, this.connection));
|
|
41
|
+
}
|
|
42
|
+
async research(query, options = {}) {
|
|
43
|
+
return this.run(() => researchWithConfig(query, options, this.config, this.connection));
|
|
44
|
+
}
|
|
45
|
+
async expandCitation(citation, options = {}) {
|
|
46
|
+
return this.run(() => expandCitationWithConfig(citation, options, this.config, this.connection));
|
|
47
|
+
}
|
|
48
|
+
async status() {
|
|
49
|
+
return this.run(() => getKnowledgeBaseContext(this.projectRoot));
|
|
50
|
+
}
|
|
51
|
+
async sources() {
|
|
52
|
+
return this.run(() => getKnowledgeBaseSourceCatalog(this.projectRoot));
|
|
53
|
+
}
|
|
54
|
+
async close() {
|
|
55
|
+
if (!this.closePromise) {
|
|
56
|
+
this.closed = true;
|
|
57
|
+
this.closePromise = (async () => {
|
|
58
|
+
await Promise.allSettled([...this.activeOperations]);
|
|
59
|
+
this.connection.close();
|
|
60
|
+
})();
|
|
61
|
+
}
|
|
62
|
+
await this.closePromise;
|
|
63
|
+
}
|
|
64
|
+
assertOpen() {
|
|
65
|
+
if (this.closed || !this.connection.isOpen()) {
|
|
66
|
+
throw new RagmirError("CLIENT_CLOSED", "Ragmir client is closed.");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
run(operation) {
|
|
70
|
+
this.assertOpen();
|
|
71
|
+
const active = (async () => {
|
|
72
|
+
try {
|
|
73
|
+
return await operation();
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw normalizeRagmirError(error);
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
this.activeOperations.add(active);
|
|
80
|
+
void active.then(() => this.activeOperations.delete(active), () => this.activeOperations.delete(active));
|
|
81
|
+
return active;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export async function createRagmirClient(options = {}) {
|
|
85
|
+
return RagmirClient.create(options);
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAA;AAC/F,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAoBzC,MAAM,OAAO,YAAY;IACd,WAAW,CAAQ;IACX,MAAM,CAAQ;IACd,UAAU,CAAY;IACtB,gBAAgB,GAAG,IAAI,GAAG,EAAoB,CAAA;IACvD,MAAM,GAAG,KAAK,CAAA;IACd,YAAY,CAA2B;IAE/C,YAAoB,MAAc,EAAE,UAAsB;QACxD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;IACvC,CAAC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UAAU,EAAE,CAAA;QACjB,MAAM,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACzB,IAAI,CAAC;gBACH,OAAO,MAAM,SAAS,EAAE,CAAA;YAC1B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,oBAAoB,CAAC,KAAK,CAAC,CAAA;YACnC,CAAC;QACH,CAAC,CAAC,EAAE,CAAA;QACJ,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACjC,KAAK,MAAM,CAAC,IAAI,CACd,GAAG,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,EAC1C,GAAG,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAC3C,CAAA;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,UAA+B,EAAE;IACxE,OAAO,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AACrC,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type RagmirErrorCode = "ABORTED" | "CLIENT_CLOSED" | "INTERNAL" | "INVALID_ARGUMENT" | "TIMEOUT";
|
|
2
|
+
interface RagmirErrorOptions {
|
|
3
|
+
cause?: unknown;
|
|
4
|
+
retryable?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class RagmirError extends Error {
|
|
7
|
+
readonly code: RagmirErrorCode;
|
|
8
|
+
readonly retryable: boolean;
|
|
9
|
+
constructor(code: RagmirErrorCode, message: string, options?: RagmirErrorOptions);
|
|
10
|
+
}
|
|
11
|
+
export declare function isRagmirError(error: unknown): error is RagmirError;
|
|
12
|
+
export declare function normalizeRagmirError(error: unknown): RagmirError;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,eAAe,GACf,UAAU,GACV,kBAAkB,GAClB,SAAS,CAAA;AAEb,UAAU,kBAAkB;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;IAC9B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;gBAEf,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB;CAMrF;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAShE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class RagmirError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
retryable;
|
|
4
|
+
constructor(code, message, options = {}) {
|
|
5
|
+
super(message, options.cause === undefined ? undefined : { cause: options.cause });
|
|
6
|
+
this.name = "RagmirError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.retryable = options.retryable ?? false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function isRagmirError(error) {
|
|
12
|
+
return error instanceof RagmirError;
|
|
13
|
+
}
|
|
14
|
+
export function normalizeRagmirError(error) {
|
|
15
|
+
if (isRagmirError(error)) {
|
|
16
|
+
return error;
|
|
17
|
+
}
|
|
18
|
+
return new RagmirError("INTERNAL", error instanceof Error ? error.message : "Ragmir operation failed.", { cause: error });
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAYA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAiB;IACrB,SAAS,CAAS;IAE3B,YAAY,IAAqB,EAAE,OAAe,EAAE,UAA8B,EAAE;QAClF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;QAClF,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAA;IAC7C,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,KAAK,YAAY,WAAW,CAAA;AACrC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,IAAI,WAAW,CACpB,UAAU,EACV,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,EACnE,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-write-lock.d.ts","sourceRoot":"","sources":["../src/index-write-lock.ts"],"names":[],"mappings":"AAIA,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,CAAC,CAAC,CAwBZ"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { throwIfAborted } from "./operation.js";
|
|
2
|
+
const writeQueues = new Map();
|
|
3
|
+
export async function withIndexWriteLock(key, signal, operation) {
|
|
4
|
+
const previous = writeQueues.get(key) ?? Promise.resolve();
|
|
5
|
+
let release;
|
|
6
|
+
const current = new Promise((resolve) => {
|
|
7
|
+
release = resolve;
|
|
8
|
+
});
|
|
9
|
+
const tail = previous.then(() => current, () => current);
|
|
10
|
+
writeQueues.set(key, tail);
|
|
11
|
+
void tail.then(() => {
|
|
12
|
+
if (writeQueues.get(key) === tail) {
|
|
13
|
+
writeQueues.delete(key);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
await waitForTurn(previous, signal);
|
|
18
|
+
throwIfAborted(signal);
|
|
19
|
+
return await operation();
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
release?.();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function waitForTurn(previous, signal) {
|
|
26
|
+
if (!signal) {
|
|
27
|
+
await previous;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
throwIfAborted(signal);
|
|
31
|
+
let onAbort;
|
|
32
|
+
const aborted = new Promise((resolve) => {
|
|
33
|
+
onAbort = () => resolve();
|
|
34
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
await Promise.race([previous, aborted]);
|
|
38
|
+
throwIfAborted(signal);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
if (onAbort) {
|
|
42
|
+
signal.removeEventListener("abort", onAbort);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=index-write-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-write-lock.js","sourceRoot":"","sources":["../src/index-write-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,MAAM,WAAW,GAAG,IAAI,GAAG,EAAyB,CA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E,CAAA;QACzB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3D,CAAC,CAAC,CAAA;IACF,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;QACvC,cAAc,CAAC,MAAM,CAAC,CAAA;IACxB,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC9C,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
export { accessLogUsageReport } from "./access-log.js";
|
|
2
|
+
export type { RagmirClientOptions } from "./client.js";
|
|
3
|
+
export { createRagmirClient, RagmirClient } from "./client.js";
|
|
2
4
|
export { loadConfig } from "./config.js";
|
|
3
5
|
export { getKnowledgeBaseContext, getKnowledgeBaseSourceCatalog, } from "./context-resources.js";
|
|
4
6
|
export { destroyIndex } from "./destroy.js";
|
|
5
7
|
export { doctor } from "./doctor.js";
|
|
6
8
|
export type { PullEmbeddingModelResult } from "./embeddings.js";
|
|
7
9
|
export { clearTransformersCache, pullEmbeddingModel } from "./embeddings.js";
|
|
10
|
+
export type { RagmirErrorCode } from "./errors.js";
|
|
11
|
+
export { isRagmirError, normalizeRagmirError, RagmirError } from "./errors.js";
|
|
8
12
|
export { evaluateGoldenQueries } from "./evaluate.js";
|
|
9
13
|
export { getIndexFreshnessWarning, getLexicalScanWarning, INDEX_SCHEMA_VERSION, } from "./index-diagnostics.js";
|
|
10
14
|
export { audit, ingest } from "./ingest.js";
|
|
11
15
|
export { initProject } from "./init.js";
|
|
12
16
|
export { discoverKnowledgeBases, knowledgeBaseIdentity } from "./knowledge-bases.js";
|
|
13
17
|
export { ingestionLimits } from "./limits.js";
|
|
14
|
-
export { serveMcp } from "./mcp.js";
|
|
18
|
+
export { connectMcpServer, createMcpServer, serveMcp } from "./mcp.js";
|
|
15
19
|
export type { ConfigurePdfOcrOptions, ConfigurePdfOcrResult, ExtractPdfPageOptions, OcrExecutableStatus, PdfOcrEngine, PdfOcrEngineSelection, PdfOcrStatus, } from "./ocr.js";
|
|
16
20
|
export { configurePdfOcr, extractPdfPage, inspectPdfOcr } from "./ocr.js";
|
|
17
21
|
export type { PackageManager, RagmirCommand } from "./package-manager.js";
|
|
@@ -31,6 +35,6 @@ export type { AgentHelperFile, AgentInstallMode, AgentInstallScope, AgentIntegra
|
|
|
31
35
|
export { bundledSkillPath, inspectAgentIntegration, installAgentSkills, installSkill, parseAgentTargets, SUPPORTED_AGENT_TARGETS, } from "./skill.js";
|
|
32
36
|
export type { AddSourceEntriesOptions, AddSourceEntriesResult, SourceEntriesResult, } from "./sources.js";
|
|
33
37
|
export { addSourceEntries, listSourceEntries } from "./sources.js";
|
|
34
|
-
export type { AccessLogAction, AccessLogUsageOptions, AccessLogUsageReport, AskResult, AuditReport, ChunkStats, CodeEvidence, CompactSearchResult, Config, DestroyIndexResult, DoctorReport, EvaluationCaseResult, EvaluationOptions, EvaluationResult, ExpandCitationOptions, ExpandedCitation, GoldenQuery, IndexManifest, IndexManifestFile, IngestionLimitsReport, IngestOptions, IngestResult, KnowledgeBaseContextReport, KnowledgeBaseIdentity, KnowledgeBaseInfo, KnowledgeBaseInventory, KnowledgeBaseSourceCatalog, McpOutputTool, McpOutputUsageReport, ParsedPage, PreviewChunk, PreviewChunksOptions, PreviewFile, PreviewReport, PrivacyProfile, RedactionCount, ResearchEvidence, ResearchOptions, ResearchReport, RetrievalProfile, SearchContextChunk, SearchOptions, SearchResult, SearchScoreExplanation, SecurityAuditReport, SourceDiagnostics, SourceDuplicateCandidate, SourcePathCandidate, } from "./types.js";
|
|
38
|
+
export type { AccessLogAction, AccessLogUsageOptions, AccessLogUsageReport, AskResult, AuditReport, ChunkStats, CodeEvidence, CompactSearchResult, Config, DestroyIndexResult, DoctorReport, EvaluationCaseResult, EvaluationOptions, EvaluationResult, ExpandCitationOptions, ExpandedCitation, GoldenQuery, IndexManifest, IndexManifestFile, IngestionLimitsReport, IngestOptions, IngestResult, KnowledgeBaseContextReport, KnowledgeBaseIdentity, KnowledgeBaseInfo, KnowledgeBaseInventory, KnowledgeBaseSourceCatalog, McpOutputTool, McpOutputUsageReport, OperationOptions, ParsedPage, PreviewChunk, PreviewChunksOptions, PreviewFile, PreviewReport, PrivacyProfile, RedactionCount, ResearchEvidence, ResearchOptions, ResearchReport, RetrievalProfile, SearchContextChunk, SearchOptions, SearchResult, SearchScoreExplanation, SecurityAuditReport, SourceDiagnostics, SourceDuplicateCandidate, SourcePathCandidate, } from "./types.js";
|
|
35
39
|
export { VERSION } from "./version.js";
|
|
36
40
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,YAAY,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC/D,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aA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yB,EACzB,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,YAAY,CAAA;AACnB,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAClE,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,MAAM,EACN,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,0BAA0B,EAC1B,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,0BAA0B,EAC1B,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
export { accessLogUsageReport } from "./access-log.js";
|
|
2
|
+
export { createRagmirClient, RagmirClient } from "./client.js";
|
|
2
3
|
export { loadConfig } from "./config.js";
|
|
3
4
|
export { getKnowledgeBaseContext, getKnowledgeBaseSourceCatalog, } from "./context-resources.js";
|
|
4
5
|
export { destroyIndex } from "./destroy.js";
|
|
5
6
|
export { doctor } from "./doctor.js";
|
|
6
7
|
export { clearTransformersCache, pullEmbeddingModel } from "./embeddings.js";
|
|
8
|
+
export { isRagmirError, normalizeRagmirError, RagmirError } from "./errors.js";
|
|
7
9
|
export { evaluateGoldenQueries } from "./evaluate.js";
|
|
8
10
|
export { getIndexFreshnessWarning, getLexicalScanWarning, INDEX_SCHEMA_VERSION, } from "./index-diagnostics.js";
|
|
9
11
|
export { audit, ingest } from "./ingest.js";
|
|
10
12
|
export { initProject } from "./init.js";
|
|
11
13
|
export { discoverKnowledgeBases, knowledgeBaseIdentity } from "./knowledge-bases.js";
|
|
12
14
|
export { ingestionLimits } from "./limits.js";
|
|
13
|
-
export { serveMcp } from "./mcp.js";
|
|
15
|
+
export { connectMcpServer, createMcpServer, serveMcp } from "./mcp.js";
|
|
14
16
|
export { configurePdfOcr, extractPdfPage, inspectPdfOcr } from "./ocr.js";
|
|
15
17
|
export { detectPackageManager, kbCommand, ragmirCommand, rgrCommand } from "./package-manager.js";
|
|
16
18
|
export { previewChunks } from "./preview.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,wBAAwB,CAAA;AAC/B,OAA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AA;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAczC,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,YAAY,CAAA;AAMnB,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAoDlE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/ingest.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Connection } from "@lancedb/lancedb";
|
|
2
|
+
import type { AuditReport, Config, IngestOptions, IngestResult } from "./types.js";
|
|
2
3
|
export declare function ingest(options?: IngestOptions): Promise<IngestResult>;
|
|
4
|
+
export declare function ingestWithConfig(config: Config, options?: IngestOptions, connection?: Connection): Promise<IngestResult>;
|
|
3
5
|
export declare function audit(cwd?: string): Promise<AuditReport>;
|
|
4
6
|
//# sourceMappingURL=ingest.d.ts.map
|
package/dist/ingest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ingest.d.ts","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ingest.d.ts","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AA2BlD,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EAEN,aAAa,EACb,YAAY,EAMb,MAAM,YAAY,CAAA;AAmBnB,wBAAsB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAG/E;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,aAAkB,EAC3B,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,YAAY,CAAC,CAKvB;AAmOD,wBAAsB,KAAK,CAAC,GAAG,SAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,CA+ErE"}
|
package/dist/ingest.js
CHANGED
|
@@ -7,6 +7,8 @@ import { embedTexts } from "./embeddings.js";
|
|
|
7
7
|
import { countSkippedByReason, inventorySourceFiles, summarizeUnsupportedExtensions, } from "./files.js";
|
|
8
8
|
import { INDEX_SCHEMA_VERSION } from "./index-diagnostics.js";
|
|
9
9
|
import { indexPolicyFingerprint } from "./index-policy.js";
|
|
10
|
+
import { withIndexWriteLock } from "./index-write-lock.js";
|
|
11
|
+
import { operationSignal, throwIfAborted } from "./operation.js";
|
|
10
12
|
import { parseFile } from "./parsing.js";
|
|
11
13
|
import { redactText, totalRedactions } from "./redaction.js";
|
|
12
14
|
import { openRowsTable, readEmptyTextFiles, readIndexManifest, updateRows, writeEmptyTextFiles, writeIndexManifest, writeRows, } from "./store.js";
|
|
@@ -28,13 +30,21 @@ const MIRROR_PATH_PATTERNS = [
|
|
|
28
30
|
];
|
|
29
31
|
export async function ingest(options = {}) {
|
|
30
32
|
const config = await loadConfig(String(options.cwd ?? process.cwd()));
|
|
33
|
+
return ingestWithConfig(config, options);
|
|
34
|
+
}
|
|
35
|
+
export async function ingestWithConfig(config, options = {}, connection) {
|
|
36
|
+
const signal = operationSignal(options);
|
|
37
|
+
return withIndexWriteLock(config.storageDir, signal, () => ingestUnlocked(config, options, connection, signal));
|
|
38
|
+
}
|
|
39
|
+
async function ingestUnlocked(config, options, connection, signal) {
|
|
40
|
+
throwIfAborted(signal);
|
|
31
41
|
const policyFingerprint = indexPolicyFingerprint(config);
|
|
32
42
|
const existingManifest = await readIndexManifest(config);
|
|
33
43
|
const manifestCompatible = !options.rebuild &&
|
|
34
44
|
existingManifest?.schemaVersion === INDEX_SCHEMA_VERSION &&
|
|
35
45
|
existingManifest.indexPolicyFingerprint === policyFingerprint &&
|
|
36
46
|
existingManifest.indexedFiles !== undefined;
|
|
37
|
-
const existingTable = manifestCompatible ? await openRowsTable(config) : null;
|
|
47
|
+
const existingTable = manifestCompatible ? await openRowsTable(config, connection) : null;
|
|
38
48
|
const storedEmptyFiles = manifestCompatible ? await readEmptyTextFiles(config) : [];
|
|
39
49
|
const knownFiles = new Map([...(existingManifest?.indexedFiles ?? []), ...storedEmptyFiles].map((file) => [
|
|
40
50
|
file.relativePath,
|
|
@@ -62,14 +72,16 @@ export async function ingest(options = {}) {
|
|
|
62
72
|
const errors = [];
|
|
63
73
|
const redactionCounts = [];
|
|
64
74
|
const emptyTextFiles = [];
|
|
65
|
-
const results = await mapLimit(filesToIndex, config.ingestConcurrency, async (file) => {
|
|
75
|
+
const results = await mapLimit(filesToIndex, config.ingestConcurrency, signal, async (file) => {
|
|
66
76
|
try {
|
|
67
77
|
const parsed = await parseFile(file, config);
|
|
78
|
+
throwIfAborted(signal);
|
|
68
79
|
const redacted = redactText(parsed.text, config);
|
|
69
80
|
const chunks = chunkDocument({ ...parsed, text: redacted.text }, config.chunkSize, config.chunkOverlap);
|
|
70
81
|
return { path: file.relativePath, chunks, redactions: redacted.counts, error: null };
|
|
71
82
|
}
|
|
72
83
|
catch (error) {
|
|
84
|
+
throwIfAborted(signal);
|
|
73
85
|
return {
|
|
74
86
|
path: file.relativePath,
|
|
75
87
|
chunks: [],
|
|
@@ -94,8 +106,10 @@ export async function ingest(options = {}) {
|
|
|
94
106
|
}
|
|
95
107
|
const rows = [];
|
|
96
108
|
for (let i = 0; i < allChunks.length; i += config.embeddingBatchSize) {
|
|
109
|
+
throwIfAborted(signal);
|
|
97
110
|
const batch = allChunks.slice(i, i + config.embeddingBatchSize);
|
|
98
111
|
const embeddings = await embedTexts(batch.map(chunkSearchText), config);
|
|
112
|
+
throwIfAborted(signal);
|
|
99
113
|
for (const [index, chunk] of batch.entries()) {
|
|
100
114
|
const vector = embeddings[index];
|
|
101
115
|
if (!vector) {
|
|
@@ -119,13 +133,14 @@ export async function ingest(options = {}) {
|
|
|
119
133
|
...filesToIndex.map((file) => file.relativePath),
|
|
120
134
|
...[...previousPaths].filter((relativePath) => !currentPaths.has(relativePath)),
|
|
121
135
|
];
|
|
136
|
+
throwIfAborted(signal);
|
|
122
137
|
const writeResult = !canReuse || chunkCount === 0
|
|
123
|
-
? await writeRows(rows, config)
|
|
138
|
+
? await writeRows(rows, config, connection)
|
|
124
139
|
: replacePaths.length > 0
|
|
125
|
-
? await updateRows(rows, replacePaths, config)
|
|
140
|
+
? await updateRows(rows, replacePaths, config, connection)
|
|
126
141
|
: { vectorIndexWarning: null, lexicalIndexWarning: null };
|
|
127
142
|
if (chunkCount > 0) {
|
|
128
|
-
const firstRow = rows[0] ?? (await firstStoredRow(config));
|
|
143
|
+
const firstRow = rows[0] ?? (await firstStoredRow(config, connection));
|
|
129
144
|
if (!firstRow) {
|
|
130
145
|
throw new Error("Cannot write an index manifest without indexed rows.");
|
|
131
146
|
}
|
|
@@ -205,8 +220,8 @@ function indexedFileRecords(rows) {
|
|
|
205
220
|
}
|
|
206
221
|
return [...records.values()];
|
|
207
222
|
}
|
|
208
|
-
async function firstStoredRow(config) {
|
|
209
|
-
const table = await openRowsTable(config);
|
|
223
|
+
async function firstStoredRow(config, connection) {
|
|
224
|
+
const table = await openRowsTable(config, connection);
|
|
210
225
|
if (!table) {
|
|
211
226
|
return null;
|
|
212
227
|
}
|
|
@@ -338,16 +353,18 @@ async function currentEmptyTextFiles(config, files) {
|
|
|
338
353
|
}
|
|
339
354
|
return emptyTextFiles;
|
|
340
355
|
}
|
|
341
|
-
async function mapLimit(items, concurrency, worker) {
|
|
356
|
+
async function mapLimit(items, concurrency, signal, worker) {
|
|
342
357
|
const results = new Array(items.length);
|
|
343
358
|
let nextIndex = 0;
|
|
344
359
|
async function run() {
|
|
345
360
|
while (nextIndex < items.length) {
|
|
361
|
+
throwIfAborted(signal);
|
|
346
362
|
const index = nextIndex;
|
|
347
363
|
nextIndex += 1;
|
|
348
364
|
const item = items[index];
|
|
349
365
|
if (item !== undefined) {
|
|
350
366
|
results[index] = await worker(item);
|
|
367
|
+
throwIfAborted(signal);
|
|
351
368
|
}
|
|
352
369
|
}
|
|
353
370
|
}
|