n8n-nodes-engram 0.6.0 → 0.7.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 +48 -2
- package/dist/embeddings/EmbeddingService.d.ts +5 -1
- package/dist/embeddings/EmbeddingService.js +97 -37
- package/dist/embeddings/EmbeddingService.js.map +1 -1
- package/dist/extraction/AssertionEvidence.d.ts +1 -0
- package/dist/extraction/AssertionEvidence.js +21 -0
- package/dist/extraction/AssertionEvidence.js.map +1 -0
- package/dist/extraction/BoundedExtraction.d.ts +15 -0
- package/dist/extraction/BoundedExtraction.js +380 -0
- package/dist/extraction/BoundedExtraction.js.map +1 -0
- package/dist/extraction/ContradictionDetector.js +31 -23
- package/dist/extraction/ContradictionDetector.js.map +1 -1
- package/dist/extraction/DurableExtraction.d.ts +22 -0
- package/dist/extraction/DurableExtraction.js +363 -0
- package/dist/extraction/DurableExtraction.js.map +1 -0
- package/dist/extraction/EdgeDeduplicator.js +60 -44
- package/dist/extraction/EdgeDeduplicator.js.map +1 -1
- package/dist/extraction/EntityDeduplicator.js +41 -31
- package/dist/extraction/EntityDeduplicator.js.map +1 -1
- package/dist/extraction/EntityExtractor.js +53 -44
- package/dist/extraction/EntityExtractor.js.map +1 -1
- package/dist/extraction/ExtractionDiagnostics.d.ts +13 -1
- package/dist/extraction/ExtractionDiagnostics.js +142 -4
- package/dist/extraction/ExtractionDiagnostics.js.map +1 -1
- package/dist/extraction/ExtractionPipeline.js +15 -7
- package/dist/extraction/ExtractionPipeline.js.map +1 -1
- package/dist/extraction/ExtractionSource.d.ts +1 -0
- package/dist/extraction/ExtractionSource.js.map +1 -1
- package/dist/extraction/LlmClient.d.ts +9 -1
- package/dist/extraction/LlmClient.js +28 -8
- package/dist/extraction/LlmClient.js.map +1 -1
- package/dist/extraction/QueueState.d.ts +294 -0
- package/dist/extraction/QueueState.js +668 -0
- package/dist/extraction/QueueState.js.map +1 -0
- package/dist/extraction/RelationshipExtractor.js +61 -52
- package/dist/extraction/RelationshipExtractor.js.map +1 -1
- package/dist/extraction/RequestBudget.d.ts +17 -0
- package/dist/extraction/RequestBudget.js +80 -0
- package/dist/extraction/RequestBudget.js.map +1 -0
- package/dist/extraction/StagedGraph.d.ts +21 -0
- package/dist/extraction/StagedGraph.js +273 -0
- package/dist/extraction/StagedGraph.js.map +1 -0
- package/dist/extraction/TemporalEvidence.d.ts +2 -0
- package/dist/extraction/TemporalEvidence.js +87 -0
- package/dist/extraction/TemporalEvidence.js.map +1 -0
- package/dist/memory/EngramChatMemory.d.ts +18 -0
- package/dist/memory/EngramChatMemory.js +196 -31
- package/dist/memory/EngramChatMemory.js.map +1 -1
- package/dist/memory/EngramChatMessageHistory.d.ts +5 -2
- package/dist/memory/EngramChatMessageHistory.js +13 -3
- package/dist/memory/EngramChatMessageHistory.js.map +1 -1
- package/dist/nodes/EngramAdmin/EngramAdmin.node.js +467 -14
- package/dist/nodes/EngramAdmin/EngramAdmin.node.js.map +1 -1
- package/dist/nodes/EngramMemory/EngramMemory.node.js +91 -0
- package/dist/nodes/EngramMemory/EngramMemory.node.js.map +1 -1
- package/dist/schemas/ExtractionOutcome.schema.d.ts +1083 -20
- package/dist/schemas/ExtractionOutcome.schema.js +53 -1
- package/dist/schemas/ExtractionOutcome.schema.js.map +1 -1
- package/dist/schemas/ExtractionPolicy.schema.d.ts +310 -0
- package/dist/schemas/ExtractionPolicy.schema.js +103 -0
- package/dist/schemas/ExtractionPolicy.schema.js.map +1 -0
- package/dist/schemas/ExtractionQueue.schema.d.ts +11492 -0
- package/dist/schemas/ExtractionQueue.schema.js +194 -0
- package/dist/schemas/ExtractionQueue.schema.js.map +1 -0
- package/dist/schemas/GraphData.schema.d.ts +20 -0
- package/dist/schemas/GraphData.schema.js +1 -0
- package/dist/schemas/GraphData.schema.js.map +1 -1
- package/dist/schemas/MemoryPolicy.schema.d.ts +2666 -22
- package/dist/schemas/MemoryPolicy.schema.js +30 -1
- package/dist/schemas/MemoryPolicy.schema.js.map +1 -1
- package/dist/schemas/StorageObservation.schema.d.ts +117 -0
- package/dist/schemas/StorageObservation.schema.js +41 -0
- package/dist/schemas/StorageObservation.schema.js.map +1 -0
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.js +3 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/search/GovernedContext.d.ts +29 -0
- package/dist/search/GovernedContext.js +232 -0
- package/dist/search/GovernedContext.js.map +1 -0
- package/dist/search/HybridSearchEngine.d.ts +4 -1
- package/dist/search/HybridSearchEngine.js +18 -10
- package/dist/search/HybridSearchEngine.js.map +1 -1
- package/dist/search/RetrievalGovernance.d.ts +7 -4
- package/dist/search/RetrievalGovernance.js +25 -6
- package/dist/search/RetrievalGovernance.js.map +1 -1
- package/dist/storage/GraphologyStorage.d.ts +20 -2
- package/dist/storage/GraphologyStorage.js +247 -19
- package/dist/storage/GraphologyStorage.js.map +1 -1
- package/dist/storage/IGraphStorage.d.ts +21 -2
- package/dist/storage/Neo4jStorage.d.ts +22 -2
- package/dist/storage/Neo4jStorage.js +324 -21
- package/dist/storage/Neo4jStorage.js.map +1 -1
- package/dist/storage/StorageDiagnostics.d.ts +6 -0
- package/dist/storage/StorageDiagnostics.js +64 -0
- package/dist/storage/StorageDiagnostics.js.map +1 -0
- package/dist/utils/advancedExtraction.d.ts +11 -0
- package/dist/utils/advancedExtraction.js +87 -0
- package/dist/utils/advancedExtraction.js.map +1 -0
- package/dist/utils/logWrapper.js +25 -8
- package/dist/utils/logWrapper.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
<a href="https://github.com/casistack/n8n-nodes-engram/blob/main/LICENSE">
|
|
20
20
|
<img src="https://img.shields.io/badge/license-AGPL--3.0-blue.svg" alt="License: AGPL-3.0" />
|
|
21
21
|
</a>
|
|
22
|
-
<img src="https://img.shields.io/badge/node-%3E%
|
|
22
|
+
<img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg" alt="Node.js" />
|
|
23
23
|
<img src="https://img.shields.io/badge/n8n-community%20node-ff6d5a.svg" alt="n8n community node" />
|
|
24
24
|
</p>
|
|
25
25
|
|
|
26
26
|
<p align="center">
|
|
27
27
|
<a href="#installation">Installation</a> ·
|
|
28
|
-
<a href="#upgrading-to-
|
|
28
|
+
<a href="#upgrading-to-v070">Upgrade</a> ·
|
|
29
29
|
<a href="#node-reference">Nodes</a> ·
|
|
30
30
|
<a href="#storage-backends">Storage</a> ·
|
|
31
31
|
<a href="#knowledge-extraction">Extraction</a> ·
|
|
@@ -101,6 +101,52 @@ npm install n8n-nodes-engram
|
|
|
101
101
|
|
|
102
102
|
---
|
|
103
103
|
|
|
104
|
+
## Upgrading to v0.7.0
|
|
105
|
+
|
|
106
|
+
These Memory v2 controls are optional. Existing workflows keep **Entity Resolution > Legacy**, **Knowledge Selection > Legacy**, **Extraction Execution > Synchronous** and **Graph Context Policy > Legacy**. Installing a newer package does not enable them or rewrite existing knowledge.
|
|
107
|
+
|
|
108
|
+
### Back Up and Install v0.7.0
|
|
109
|
+
|
|
110
|
+
1. Back up current workflows and n8n configuration. Preserve exact namespace keys and any existing alias mapping.
|
|
111
|
+
2. **Embedded:** pause writers and preserve each producer workflow's graph file, storage directory and workflow-to-file mapping. Use a separate restored store for upgrade trials. Once durable work exists, use **Extraction Queue > Export Queue Backup** for portable queue-aware recovery.
|
|
112
|
+
3. **Neo4j:** take a consistent database backup using your normal recovery procedure. Retain the same database and namespace identities. Graph writers coordinate through a shared store lock; validate concurrent write throughput during rollout.
|
|
113
|
+
4. Install `n8n-nodes-engram@0.7.0`, restart n8n, refresh the editor and confirm the installed version. Node.js 20 or newer is required. Existing v2 stores load without a bulk migration or re-extraction; earlier provenance/schema upgrades remain separate.
|
|
114
|
+
5. Run **Engram Admin > Monitoring > Diagnostics**. Saved Memory v1 nodes remain v1; upgrade selected nodes explicitly to **Memory v2** on an inactive workflow copy before enabling the new controls. Check that the copy points to the intended restored store.
|
|
115
|
+
|
|
116
|
+
### Activate Bounded Extraction First
|
|
117
|
+
|
|
118
|
+
Back up current workflows and both the graph and conversation records before changing settings. Preserve the exact namespace, including whitespace, and the existing embedded workflow-to-file mapping or Neo4j database. Begin with one conversation workflow and keep the current model, session identity and conversation window.
|
|
119
|
+
|
|
120
|
+
Select **Entity Resolution > Bounded** and **Message Write Policy > Final Turns**. Keep eligible human/final-assistant sources stored; system/tool extraction is unsupported in this mode. Exact names and explicitly verified aliases resolve before model comparisons. Defaults limit each extraction to an eight-candidate shortlist, 16 fuzzy comparisons, 32 model/embedding requests and a 30-second shared deadline. Identity ambiguity, pruned candidates and exhausted budgets remain proposed or deferred; they are not permission to merge existing identities. Legacy contradiction expiry and automatic summary updates are not performed by the bounded path.
|
|
121
|
+
|
|
122
|
+
Select **Knowledge Selection > Durable and Temporal** to keep temporary requests in conversation history without automatically accepting them as durable facts. Automatic acceptance requires accepted human provenance and complete, literal assertion evidence. Paraphrases, quotations, hypothetical or qualified statements and uncertain identities require review. This conservative policy can produce more proposed records. It does not reclassify, re-extract or delete previously stored facts. **Source Timezone** must be an explicit IANA zone such as `Europe/London`; omit it when unknown. Calendar-day resolution supports today/tomorrow/yesterday and a single explicit date. Other relative expressions remain uncertain.
|
|
123
|
+
|
|
124
|
+
**Graph Context Policy > Governed Current** reconciles search/traversal duplicates by relationship UUID, omits ungrounded entity summaries and excludes unresolved or out-of-interval plans from current context. **Governed Historical** retains historical evidence with source attribution; map historical intent explicitly in the workflow. **Governed As Of** requires an ISO timestamp with `Z` or a numeric offset and tests event-interval relevance, not what the system knew at that time. Separate **Durable Fact Token Allowance** (4096) and **Historical Evidence Token Allowance** (2048) stay within the overall graph context token cap; the recent-message window remains independent. A zero allowance disables that evidence category. Governed search and traversal share a 512-source-reference hydration allowance; candidates whose complete provenance does not fit are deferred, with `source_reference_deferred` and truncation diagnostics. Existing accepted legacy records are not automatically corrected. Genuine human JSON and quoted conversation remain in the episode ledger.
|
|
125
|
+
|
|
126
|
+
Inspect save diagnostics for per-stage elapsed time, model-call counts, available token usage, candidate/deferral counts and storage timing. Unavailable provider/backend measurements are `null`; overlapping stage/request/storage times must not be added together. Agree latency targets from your own normal and tool-assisted workloads before expanding the rollout.
|
|
127
|
+
|
|
128
|
+
### Activate a Durable Extraction Worker
|
|
129
|
+
|
|
130
|
+
Durable Queue removes model extraction from the chat save path by persisting the episode and its extraction job together. Graph facts become available only after a worker completes. It requires persistent storage, bounded resolution, Final Turns and **Retention Policy > Keep Forever**; unsupported combinations fail before the write. Use stable per-turn message/idempotency keys for retries.
|
|
131
|
+
|
|
132
|
+
1. Create a separate workflow with **Schedule Trigger > Engram Admin v2 > Extraction Queue > Process Jobs**. Start with **Worker Batch Size > 1**; each execution processes at most ten jobs sequentially. No worker runs automatically merely because the package is installed.
|
|
133
|
+
2. Configure the same backend and exact **Queue Group ID** as Memory. For embedded storage, set **Memory Workflow ID** to the original producer workflow ID and use the same custom storage directory. The worker's own workflow ID is not the producer's store. The existing producer file must be present. For Neo4j, use the same database and appropriate credentials.
|
|
134
|
+
3. Match the producer's extraction credential endpoint, model, temperature mode/value, entity types, thresholds, embedding configuration and all bounded/quality settings. Set the same nonsecret **Extraction Route ID** on producer and worker. API keys are not stored in jobs; credential rotation can retain the binding when these settings are unchanged. Route URLs containing credentials, query strings or fragments are rejected.
|
|
135
|
+
4. Activate the scheduled worker, then select **Extraction Execution > Durable Queue** on the producer. Inspect `delivery.status=queued`, job IDs, enqueue timing and `graph_fresh=false`; this is not a successful extraction result. Use **Extraction Queue > Status** for pending/failed counts, oldest pending time and bounded job summaries, then inspect worker outcomes and actual graph facts.
|
|
136
|
+
5. Verify an ordinary turn, a real tool-assisted turn, a durable preference, older-fact recall and an explicit historical query. Confirm the final pair is saved once, audits remain outside conversational context, original records retain their identity and the queue drains. Only then activate additional namespaces. Evaluate passive ingestion separately.
|
|
137
|
+
|
|
138
|
+
Jobs use fenced leases, bounded retry/backoff and atomic graph/completion writes. Restarts can recover work; retries do not resend chat messages. Configuration mismatch leaves work unclaimed. Use **Rebind Job** with an operator and reason only after reviewing corrected settings; this preserves the source/job identity and clears stale staged work. Pause, resume, retry and cancel are explicit reviewed operations. Capacity or durable-storage failures can reject the conversation write; monitor workflow errors rather than assuming every queued save is fail-soft. Snapshot preparation is capped at 100,000 records/100 MiB; source, request, response and staged-plan byte limits can defer oversized work without truncating original messages.
|
|
139
|
+
|
|
140
|
+
### Backups, Historical Artifacts and Rollback
|
|
141
|
+
|
|
142
|
+
Use **Extraction Queue > Export Queue Backup** to preserve jobs, ownership and completion markers along with graph/episode records. A generic graph export alone is not the queue recovery procedure. Imports verify checksums, namespace/endpoints and collisions; incomplete legacy source/chain references are retained with warnings. Imported active jobs are paused pending configuration review. Creating a fresh embedded import destination requires explicit review and a custom directory. Never import over newer live conversations.
|
|
143
|
+
|
|
144
|
+
The historical-artifact inspection and dry-run steps below still apply. This feature does not reinterpret historical records already labelled as genuine conversation, automatically delete extracted facts or provide a record-specific correction migration.
|
|
145
|
+
|
|
146
|
+
For rollback, first stop producers and workers and take a fresh queue-aware backup. Prefer restoring the previous policy settings on the new package. Before using an older binary, complete or explicitly cancel outstanding jobs and verify no worker remains active. Older binaries do not enforce queue ownership, leases or disk-sync protections; do not run old and new writers concurrently against a queue-bearing store. Keep the queue-aware backup and all new legitimate records. If an older package cannot safely read the retained operational metadata, use a separately reviewed recovery/export procedure; never overwrite live history with an old snapshot as routine rollback. Existing no-queue embedded stores retain their prior disk-sync behavior. Neo4j graph writers coordinate through a shared store lock to protect atomic extraction commits; measure concurrent write throughput before expanding a busy deployment.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
104
150
|
## Upgrading to v0.6.0
|
|
105
151
|
|
|
106
152
|
**Installing this release makes the controls available; it does not automatically activate history filtering or final-turn writes.** Existing saved settings retain temperature `0`, History Filter `Off`, Message Write Policy `Legacy`, and Store Tool Audit `Disabled`. Saved Memory v1 nodes remain v1 until explicitly upgraded. The temperature control is available in both v1 and v2; the history/write/query controls require Memory v2.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RequestBudget } from '../extraction/RequestBudget';
|
|
2
|
+
import { type ExtractionDiagnostics } from '../extraction/ExtractionDiagnostics';
|
|
1
3
|
export interface EmbeddingConfig {
|
|
2
4
|
apiKey: string;
|
|
3
5
|
baseUrl: string;
|
|
@@ -13,12 +15,14 @@ export interface EmbeddingResult {
|
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
17
|
export declare class EmbeddingService {
|
|
18
|
+
private diagnostics?;
|
|
19
|
+
private budget?;
|
|
16
20
|
private apiKey;
|
|
17
21
|
private baseUrl;
|
|
18
22
|
private model;
|
|
19
23
|
private dimensions;
|
|
20
24
|
private timeoutMs;
|
|
21
|
-
constructor(config: EmbeddingConfig);
|
|
25
|
+
constructor(config: EmbeddingConfig, diagnostics?: ExtractionDiagnostics | undefined, budget?: RequestBudget | undefined);
|
|
22
26
|
embed(text: string): Promise<EmbeddingResult>;
|
|
23
27
|
embedBatch(texts: string[]): Promise<EmbeddingResult[]>;
|
|
24
28
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EmbeddingService = void 0;
|
|
4
|
+
const RequestBudget_1 = require("../extraction/RequestBudget");
|
|
4
5
|
const url_1 = require("../utils/url");
|
|
6
|
+
const ExtractionDiagnostics_1 = require("../extraction/ExtractionDiagnostics");
|
|
5
7
|
class EmbeddingService {
|
|
6
|
-
constructor(config) {
|
|
8
|
+
constructor(config, diagnostics, budget) {
|
|
7
9
|
var _a;
|
|
10
|
+
this.diagnostics = diagnostics;
|
|
11
|
+
this.budget = budget;
|
|
8
12
|
this.apiKey = config.apiKey;
|
|
9
13
|
this.baseUrl = (0, url_1.normalizeHttpBaseUrl)(config.baseUrl, 'Embedding API baseUrl');
|
|
10
14
|
this.model = config.model;
|
|
@@ -16,49 +20,105 @@ class EmbeddingService {
|
|
|
16
20
|
return results[0];
|
|
17
21
|
}
|
|
18
22
|
async embedBatch(texts) {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
24
|
if (texts.length === 0)
|
|
20
25
|
return [];
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
model: this.model,
|
|
24
|
-
input: texts,
|
|
25
|
-
};
|
|
26
|
-
if (this.dimensions) {
|
|
27
|
-
body.dimensions = this.dimensions;
|
|
28
|
-
}
|
|
29
|
-
const controller = new AbortController();
|
|
30
|
-
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
31
|
-
let response;
|
|
26
|
+
const end = (_a = this.diagnostics) === null || _a === void 0 ? void 0 : _a.begin('embeddings');
|
|
27
|
+
let failed = true;
|
|
32
28
|
try {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
body
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
const url = `${this.baseUrl}/embeddings`;
|
|
30
|
+
const body = {
|
|
31
|
+
model: this.model,
|
|
32
|
+
input: texts,
|
|
33
|
+
};
|
|
34
|
+
if (this.dimensions) {
|
|
35
|
+
body.dimensions = this.dimensions;
|
|
36
|
+
}
|
|
37
|
+
const serializedBody = JSON.stringify(body);
|
|
38
|
+
const remaining = (_b = this.budget) === null || _b === void 0 ? void 0 : _b.reserve(Buffer.byteLength(serializedBody));
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const abort = () => controller.abort();
|
|
41
|
+
(_c = this.budget) === null || _c === void 0 ? void 0 : _c.controller.signal.addEventListener('abort', abort, { once: true });
|
|
42
|
+
const timeout = setTimeout(abort, Math.min(remaining !== null && remaining !== void 0 ? remaining : this.timeoutMs, this.timeoutMs));
|
|
43
|
+
const metric = (_d = this.diagnostics) === null || _d === void 0 ? void 0 : _d.beginRequest('embeddings');
|
|
44
|
+
try {
|
|
45
|
+
let response;
|
|
46
|
+
try {
|
|
47
|
+
response = await fetch(url, {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
headers: {
|
|
50
|
+
'Content-Type': 'application/json',
|
|
51
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
52
|
+
},
|
|
53
|
+
body: serializedBody,
|
|
54
|
+
signal: controller.signal,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (this.budget)
|
|
59
|
+
throw new ExtractionDiagnostics_1.ExtractionError(controller.signal.aborted ? 'timeout' : 'network');
|
|
60
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
61
|
+
throw new Error(`Embedding API request timed out after ${this.timeoutMs}ms`);
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
metric === null || metric === void 0 ? void 0 : metric.headers();
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const errorText = this.budget
|
|
68
|
+
? await (0, RequestBudget_1.readBoundedResponse)(response, this.budget.maxResponseBytes)
|
|
69
|
+
: await response.text();
|
|
70
|
+
if (this.budget)
|
|
71
|
+
throw new ExtractionDiagnostics_1.ExtractionError(response.status === 401 || response.status === 403
|
|
72
|
+
? 'authentication'
|
|
73
|
+
: response.status === 429
|
|
74
|
+
? 'rate_limit'
|
|
75
|
+
: response.status >= 500
|
|
76
|
+
? 'provider_server'
|
|
77
|
+
: 'invalid_request', response.status);
|
|
78
|
+
throw new Error(`Embedding API error (${response.status}): ${errorText}`);
|
|
79
|
+
}
|
|
80
|
+
const data = (this.budget
|
|
81
|
+
? JSON.parse(await (0, RequestBudget_1.readBoundedResponse)(response, this.budget.maxResponseBytes))
|
|
82
|
+
: await response.json());
|
|
83
|
+
(_e = this.budget) === null || _e === void 0 ? void 0 : _e.check();
|
|
84
|
+
if (this.budget &&
|
|
85
|
+
(!Array.isArray(data === null || data === void 0 ? void 0 : data.data) ||
|
|
86
|
+
data.data.length !== texts.length ||
|
|
87
|
+
data.data.some((item) => !item ||
|
|
88
|
+
!Number.isInteger(item.index) ||
|
|
89
|
+
item.index < 0 ||
|
|
90
|
+
item.index >= texts.length ||
|
|
91
|
+
!Array.isArray(item.embedding) ||
|
|
92
|
+
!item.embedding.length ||
|
|
93
|
+
!item.embedding.every(Number.isFinite)) ||
|
|
94
|
+
new Set(data.data.map((item) => item.index)).size !== texts.length))
|
|
95
|
+
throw new Error('Invalid embedding response');
|
|
96
|
+
const sorted = [...data.data].sort((a, b) => a.index - b.index);
|
|
97
|
+
metric === null || metric === void 0 ? void 0 : metric.end('completed', data.usage, true);
|
|
98
|
+
const results = sorted.map((item) => ({
|
|
99
|
+
embedding: item.embedding,
|
|
100
|
+
usage: data.usage,
|
|
101
|
+
}));
|
|
102
|
+
failed = false;
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if ((_f = this.budget) === null || _f === void 0 ? void 0 : _f.controller.signal.aborted)
|
|
107
|
+
this.budget.check();
|
|
108
|
+
if (this.budget && controller.signal.aborted)
|
|
109
|
+
throw new ExtractionDiagnostics_1.ExtractionError('timeout');
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
if (failed)
|
|
114
|
+
metric === null || metric === void 0 ? void 0 : metric.end(controller.signal.aborted ? 'cancelled' : 'failed', undefined, true);
|
|
115
|
+
clearTimeout(timeout);
|
|
116
|
+
(_g = this.budget) === null || _g === void 0 ? void 0 : _g.controller.signal.removeEventListener('abort', abort);
|
|
46
117
|
}
|
|
47
|
-
throw error;
|
|
48
118
|
}
|
|
49
119
|
finally {
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
if (!response.ok) {
|
|
53
|
-
const errorText = await response.text();
|
|
54
|
-
throw new Error(`Embedding API error (${response.status}): ${errorText}`);
|
|
120
|
+
end === null || end === void 0 ? void 0 : end(failed);
|
|
55
121
|
}
|
|
56
|
-
const data = (await response.json());
|
|
57
|
-
const sorted = [...data.data].sort((a, b) => a.index - b.index);
|
|
58
|
-
return sorted.map((item) => ({
|
|
59
|
-
embedding: item.embedding,
|
|
60
|
-
usage: data.usage,
|
|
61
|
-
}));
|
|
62
122
|
}
|
|
63
123
|
}
|
|
64
124
|
exports.EmbeddingService = EmbeddingService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbeddingService.js","sourceRoot":"","sources":["../../src/embeddings/EmbeddingService.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EmbeddingService.js","sourceRoot":"","sources":["../../src/embeddings/EmbeddingService.ts"],"names":[],"mappings":";;;AAAA,+DAAiF;AAMjF,sCAAoD;AACpD,+EAAkG;AAiBlG,MAAa,gBAAgB;IAO3B,YACE,MAAuB,EACf,WAAmC,EACnC,MAAsB;;QADtB,gBAAW,GAAX,WAAW,CAAwB;QACnC,WAAM,GAAN,MAAM,CAAgB;QAE9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAA,0BAAoB,EAAC,MAAM,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;QAC7E,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,MAAA,MAAM,CAAC,SAAS,mCAAI,KAAM,CAAC;IAC9C,CAAC;IAGD,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9C,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAGD,KAAK,CAAC,UAAU,CAAC,KAAe;;QAC9B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QAElC,MAAM,GAAG,GAAG,MAAA,IAAI,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,CAAC;YACT,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAG,MAAM,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;CACF;AA9ID,4CA8IC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isDurableAssertion(content: string, start: number, end: number): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDurableAssertion = isDurableAssertion;
|
|
4
|
+
function isDurableAssertion(content, start, end) {
|
|
5
|
+
if (start < 0 || end <= start || end > content.length)
|
|
6
|
+
return false;
|
|
7
|
+
const text = content.slice(start, end).trim();
|
|
8
|
+
const before = content.slice(0, start).trimEnd();
|
|
9
|
+
const after = content.slice(end).trimStart();
|
|
10
|
+
if (before && !/[.!?\n]$/.test(before))
|
|
11
|
+
return false;
|
|
12
|
+
if (after && !/[.!?]$/.test(text))
|
|
13
|
+
return false;
|
|
14
|
+
if (content.includes('"') || /[“”]|^\s*>/m.test(content))
|
|
15
|
+
return false;
|
|
16
|
+
return (!text.includes('?') &&
|
|
17
|
+
!/\b(said|says|according to|hypothetical|might|maybe|not|never|false|denies|denied|without|no longer|if|unless|would|suppose|supposing|assuming|incorrect|untrue)\b|\b\w+n['’]t\b/i.test(text) &&
|
|
18
|
+
!/^\s*(what|when|where|which|who|how|can you|could you|please|tell me|show me|find me|asks?\b)/i.test(text) &&
|
|
19
|
+
!/\b(today|tomorrow|yesterday|later|next\s+(week|month|tuesday|monday|wednesday|thursday|friday|saturday|sunday)|this weekend)\b/i.test(text));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=AssertionEvidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssertionEvidence.js","sourceRoot":"","sources":["../../src/extraction/AssertionEvidence.ts"],"names":[],"mappings":";;AACA,gDAqBC;AArBD,SAAgB,kBAAkB,CAAC,OAAe,EAAE,KAAa,EAAE,GAAW;IAC5E,IAAI,KAAK,GAAG,CAAC,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACpE,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;IAE7C,IAAI,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IACrD,IAAI,KAAK,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,OAAO,CACL,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QACnB,CAAC,kLAAkL,CAAC,IAAI,CACtL,IAAI,CACL;QACD,CAAC,+FAA+F,CAAC,IAAI,CACnG,IAAI,CACL;QACD,CAAC,iIAAiI,CAAC,IAAI,CACrI,IAAI,CACL,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type EmbeddingConfig } from '../embeddings';
|
|
2
|
+
import type { IGraphStorage } from '../storage/IGraphStorage';
|
|
3
|
+
import { type ExtractionPolicyInput, type ExtractionThresholdPolicy } from '../schemas';
|
|
4
|
+
import { type LlmClientConfig } from './LlmClient';
|
|
5
|
+
import { ExtractionDiagnostics } from './ExtractionDiagnostics';
|
|
6
|
+
import type { ExtractionSource } from './ExtractionSource';
|
|
7
|
+
export declare function boundedExtract(storage: IGraphStorage, group: string, sources: ExtractionSource[], config: {
|
|
8
|
+
llm: LlmClientConfig;
|
|
9
|
+
policy?: ExtractionPolicyInput;
|
|
10
|
+
types: string[];
|
|
11
|
+
threshold?: ExtractionThresholdPolicy;
|
|
12
|
+
embeddings?: EmbeddingConfig;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
deadlineMs?: number;
|
|
15
|
+
}, diagnostics: ExtractionDiagnostics): Promise<void>;
|