@utaba/deep-memory 0.12.1 → 0.15.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/dist/{StorageProvider-CrMaJuZ3.d.cts → StorageProvider-BGtKZZt4.d.cts} +1 -1
- package/dist/{StorageProvider-B5U72e5S.d.ts → StorageProvider-D_o2Hksf.d.ts} +1 -1
- package/dist/index.cjs +142 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -9
- package/dist/index.d.ts +59 -9
- package/dist/index.js +141 -66
- package/dist/index.js.map +1 -1
- package/dist/{portability-BrUmvSaH.d.cts → portability-P1hL-bOa.d.cts} +19 -0
- package/dist/{portability-BrUmvSaH.d.ts → portability-P1hL-bOa.d.ts} +19 -0
- package/dist/providers/index.d.cts +4 -4
- package/dist/providers/index.d.ts +4 -4
- package/dist/testing/conformance.d.cts +2 -2
- package/dist/testing/conformance.d.ts +2 -2
- package/dist/{traversal-BmCyenfC.d.ts → traversal-B_84kGaO.d.ts} +1 -1
- package/dist/{traversal-qKh6sE-g.d.cts → traversal-CBE5h5ob.d.cts} +1 -1
- package/dist/types/index.d.cts +3 -3
- package/dist/types/index.d.ts +3 -3
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as StorageRepositoryConfig, c as StoredRepository, d as RepositoryFilter, e as PaginatedResult, f as StoredRepositorySummary, g as RepositoryUpdate, h as DeleteProgressCallback, i as RepositoryStats, M as MemoryVocabulary, j as PaginationOptions, V as VocabularyChangeRecord, k as StoredEntity, l as StoredEntityUpdate, m as StorageFindQuery, n as StoredRelationship, o as RelationshipQueryOptions, p as StorageExploreOptions, q as StorageNeighborhood, r as StoragePathOptions, s as StoragePathResult, t as StorageTimelineOptions, u as StorageTimelineResult, v as ExportChunk, I as ImportChunk, B as BulkImportOptions, w as BulkImportResult } from './portability-
|
|
1
|
+
import { S as StorageRepositoryConfig, c as StoredRepository, d as RepositoryFilter, e as PaginatedResult, f as StoredRepositorySummary, g as RepositoryUpdate, h as DeleteProgressCallback, i as RepositoryStats, M as MemoryVocabulary, j as PaginationOptions, V as VocabularyChangeRecord, k as StoredEntity, l as StoredEntityUpdate, m as StorageFindQuery, n as StoredRelationship, o as RelationshipQueryOptions, p as StorageExploreOptions, q as StorageNeighborhood, r as StoragePathOptions, s as StoragePathResult, t as StorageTimelineOptions, u as StorageTimelineResult, v as ExportChunk, I as ImportChunk, B as BulkImportOptions, w as BulkImportResult } from './portability-P1hL-bOa.cjs';
|
|
2
2
|
|
|
3
3
|
/** Result returned by ensureSchema describing what actions were taken. */
|
|
4
4
|
interface EnsureSchemaResult {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as StorageRepositoryConfig, c as StoredRepository, d as RepositoryFilter, e as PaginatedResult, f as StoredRepositorySummary, g as RepositoryUpdate, h as DeleteProgressCallback, i as RepositoryStats, M as MemoryVocabulary, j as PaginationOptions, V as VocabularyChangeRecord, k as StoredEntity, l as StoredEntityUpdate, m as StorageFindQuery, n as StoredRelationship, o as RelationshipQueryOptions, p as StorageExploreOptions, q as StorageNeighborhood, r as StoragePathOptions, s as StoragePathResult, t as StorageTimelineOptions, u as StorageTimelineResult, v as ExportChunk, I as ImportChunk, B as BulkImportOptions, w as BulkImportResult } from './portability-
|
|
1
|
+
import { S as StorageRepositoryConfig, c as StoredRepository, d as RepositoryFilter, e as PaginatedResult, f as StoredRepositorySummary, g as RepositoryUpdate, h as DeleteProgressCallback, i as RepositoryStats, M as MemoryVocabulary, j as PaginationOptions, V as VocabularyChangeRecord, k as StoredEntity, l as StoredEntityUpdate, m as StorageFindQuery, n as StoredRelationship, o as RelationshipQueryOptions, p as StorageExploreOptions, q as StorageNeighborhood, r as StoragePathOptions, s as StoragePathResult, t as StorageTimelineOptions, u as StorageTimelineResult, v as ExportChunk, I as ImportChunk, B as BulkImportOptions, w as BulkImportResult } from './portability-P1hL-bOa.js';
|
|
2
2
|
|
|
3
3
|
/** Result returned by ensureSchema describing what actions were taken. */
|
|
4
4
|
interface EnsureSchemaResult {
|
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
InvalidInputError: () => InvalidInputError,
|
|
40
40
|
MemoryRepository: () => MemoryRepository,
|
|
41
41
|
NoOpEmbeddingProvider: () => NoOpEmbeddingProvider,
|
|
42
|
+
OperationAbortedError: () => OperationAbortedError,
|
|
42
43
|
OperationCancelledError: () => OperationCancelledError,
|
|
43
44
|
ProviderError: () => ProviderError,
|
|
44
45
|
RelationshipConstraintError: () => RelationshipConstraintError,
|
|
@@ -225,6 +226,18 @@ var OperationCancelledError = class extends DeepMemoryError {
|
|
|
225
226
|
this.reason = reason;
|
|
226
227
|
}
|
|
227
228
|
};
|
|
229
|
+
var OperationAbortedError = class extends DeepMemoryError {
|
|
230
|
+
operation;
|
|
231
|
+
constructor(operation) {
|
|
232
|
+
super(
|
|
233
|
+
"OPERATION_ABORTED",
|
|
234
|
+
`${operation} aborted by caller`,
|
|
235
|
+
`The caller's AbortSignal was triggered. Partial state from completed batches has been retained.`
|
|
236
|
+
);
|
|
237
|
+
this.name = "OperationAbortedError";
|
|
238
|
+
this.operation = operation;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
228
241
|
var EmbeddingProviderRequiredError = class extends DeepMemoryError {
|
|
229
242
|
constructor() {
|
|
230
243
|
super(
|
|
@@ -932,6 +945,7 @@ var EntityManager = class {
|
|
|
932
945
|
}
|
|
933
946
|
const batchSize = options?.batchSize ?? 50;
|
|
934
947
|
const errorThreshold = options?.errorThresholdToAbort;
|
|
948
|
+
const signal = options?.signal;
|
|
935
949
|
const firstPage = await this.storage.findEntities(this.repositoryId, { limit: 1, offset: 0 });
|
|
936
950
|
const total = firstPage.total;
|
|
937
951
|
let totalProcessed = 0;
|
|
@@ -939,6 +953,9 @@ var EntityManager = class {
|
|
|
939
953
|
const allErrors = [];
|
|
940
954
|
let offset = 0;
|
|
941
955
|
while (offset < total) {
|
|
956
|
+
if (signal?.aborted) {
|
|
957
|
+
throw new OperationAbortedError("reembedAll");
|
|
958
|
+
}
|
|
942
959
|
const page = await this.storage.findEntities(this.repositoryId, {
|
|
943
960
|
limit: batchSize,
|
|
944
961
|
offset
|
|
@@ -951,12 +968,15 @@ var EntityManager = class {
|
|
|
951
968
|
totalProcessed += result.processed;
|
|
952
969
|
totalFailed += result.failed;
|
|
953
970
|
allErrors.push(...result.errors);
|
|
954
|
-
options?.onProgress?.(totalProcessed, total, totalFailed);
|
|
971
|
+
await options?.onProgress?.(totalProcessed, total, totalFailed);
|
|
955
972
|
if (errorThreshold !== void 0 && totalFailed >= errorThreshold) {
|
|
956
973
|
allErrors.push({ entityId: "", error: `Aborted: error threshold of ${errorThreshold} reached (${totalFailed} failures)` });
|
|
957
974
|
break;
|
|
958
975
|
}
|
|
959
976
|
offset += page.items.length;
|
|
977
|
+
if (signal?.aborted) {
|
|
978
|
+
throw new OperationAbortedError("reembedAll");
|
|
979
|
+
}
|
|
960
980
|
const delayMs = options?.delayBetweenBatchesMs ?? 0;
|
|
961
981
|
if (delayMs > 0 && offset < total) {
|
|
962
982
|
await new Promise((resolve) => {
|
|
@@ -2323,7 +2343,13 @@ var MemoryRepository = class {
|
|
|
2323
2343
|
* the repository's embedding configuration is updated to the new values before
|
|
2324
2344
|
* re-embedding, so all subsequent entity writes use the new model/dimensionality.
|
|
2325
2345
|
*
|
|
2326
|
-
* Processes in batches with optional rate limiting.
|
|
2346
|
+
* Processes in batches with optional rate limiting.
|
|
2347
|
+
*
|
|
2348
|
+
* Progress is delivered via the optional `onProgress` callback. Most callers
|
|
2349
|
+
* should use {@link DeepMemory.reembedAll} instead, which wires this callback
|
|
2350
|
+
* to the global event bus so `reembed:*` events are reachable via
|
|
2351
|
+
* `DeepMemory.on()`.
|
|
2352
|
+
*
|
|
2327
2353
|
* Updates repository metadata with the new model ID and dimensions on completion.
|
|
2328
2354
|
*/
|
|
2329
2355
|
async reembedAll(options) {
|
|
@@ -2358,46 +2384,23 @@ var MemoryRepository = class {
|
|
|
2358
2384
|
}
|
|
2359
2385
|
});
|
|
2360
2386
|
}
|
|
2361
|
-
const
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2387
|
+
const result = await this.entityManager.reembedAll({
|
|
2388
|
+
batchSize: options?.batchSize,
|
|
2389
|
+
maxRetries: options?.maxRetries,
|
|
2390
|
+
errorThresholdToAbort: options?.errorThresholdToAbort,
|
|
2391
|
+
delayBetweenBatchesMs: options?.delayBetweenBatchesMs,
|
|
2392
|
+
signal: options?.signal,
|
|
2393
|
+
onProgress: async (processed, total, failed) => {
|
|
2394
|
+
await options?.onProgress?.({ processed, totalEntities: total, failed });
|
|
2395
|
+
}
|
|
2365
2396
|
});
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
await this.eventBus.emit("reembed:progress", {
|
|
2374
|
-
repositoryId: this.repositoryId,
|
|
2375
|
-
processed,
|
|
2376
|
-
totalEntities: total,
|
|
2377
|
-
failed
|
|
2378
|
-
});
|
|
2379
|
-
}
|
|
2380
|
-
});
|
|
2381
|
-
await this.storage.updateRepository(this.repositoryId, {
|
|
2382
|
-
metadata: {
|
|
2383
|
-
embeddingModelId: result.modelId,
|
|
2384
|
-
embeddingDimensions: result.dimensions
|
|
2385
|
-
}
|
|
2386
|
-
});
|
|
2387
|
-
await this.eventBus.emit("reembed:completed", {
|
|
2388
|
-
repositoryId: this.repositoryId,
|
|
2389
|
-
processed: result.processed,
|
|
2390
|
-
failed: result.failed,
|
|
2391
|
-
modelId: result.modelId
|
|
2392
|
-
});
|
|
2393
|
-
return result;
|
|
2394
|
-
} catch (err) {
|
|
2395
|
-
await this.eventBus.emit("reembed:failed", {
|
|
2396
|
-
repositoryId: this.repositoryId,
|
|
2397
|
-
error: err instanceof Error ? err.message : String(err)
|
|
2398
|
-
});
|
|
2399
|
-
throw err;
|
|
2400
|
-
}
|
|
2397
|
+
await this.storage.updateRepository(this.repositoryId, {
|
|
2398
|
+
metadata: {
|
|
2399
|
+
embeddingModelId: result.modelId,
|
|
2400
|
+
embeddingDimensions: result.dimensions
|
|
2401
|
+
}
|
|
2402
|
+
});
|
|
2403
|
+
return result;
|
|
2401
2404
|
}
|
|
2402
2405
|
// ─── Relationships ─────────────────────────────────────────────────
|
|
2403
2406
|
async createRelationships(inputs) {
|
|
@@ -3511,7 +3514,7 @@ var EventBus = class {
|
|
|
3511
3514
|
};
|
|
3512
3515
|
|
|
3513
3516
|
// src/portability/RepositoryExporter.ts
|
|
3514
|
-
var LIBRARY_VERSION = true ? "0.
|
|
3517
|
+
var LIBRARY_VERSION = true ? "0.15.0" : "0.1.0";
|
|
3515
3518
|
var RepositoryExporter = class {
|
|
3516
3519
|
storage;
|
|
3517
3520
|
provenance;
|
|
@@ -3865,11 +3868,18 @@ var RepositoryImporter = class {
|
|
|
3865
3868
|
storage;
|
|
3866
3869
|
actorId;
|
|
3867
3870
|
onProgress;
|
|
3871
|
+
signal;
|
|
3868
3872
|
migrationEngine = new MigrationEngine();
|
|
3869
3873
|
constructor(config) {
|
|
3870
3874
|
this.storage = config.storage;
|
|
3871
3875
|
this.actorId = config.actorId;
|
|
3872
3876
|
this.onProgress = config.onProgress;
|
|
3877
|
+
this.signal = config.signal;
|
|
3878
|
+
}
|
|
3879
|
+
throwIfAborted() {
|
|
3880
|
+
if (this.signal?.aborted) {
|
|
3881
|
+
throw new OperationAbortedError("import");
|
|
3882
|
+
}
|
|
3873
3883
|
}
|
|
3874
3884
|
/**
|
|
3875
3885
|
* Import an export archive according to the provided options.
|
|
@@ -3945,6 +3955,7 @@ var RepositoryImporter = class {
|
|
|
3945
3955
|
let chunksCompleted = 0;
|
|
3946
3956
|
const adaptiveConcurrencyHandle = options.bulk?.adaptiveConcurrencyHandle ?? {};
|
|
3947
3957
|
for await (const chunk of chunks) {
|
|
3958
|
+
this.throwIfAborted();
|
|
3948
3959
|
const bulkResult = await this.storage.importBulk(target.repositoryId, [chunk], {
|
|
3949
3960
|
...options.bulk,
|
|
3950
3961
|
skipExistenceCheck: true,
|
|
@@ -4026,6 +4037,7 @@ var RepositoryImporter = class {
|
|
|
4026
4037
|
let relationshipsSkipped = 0;
|
|
4027
4038
|
let chunksCompleted = 0;
|
|
4028
4039
|
for await (const chunk of chunks) {
|
|
4040
|
+
this.throwIfAborted();
|
|
4029
4041
|
if (chunk.entities) {
|
|
4030
4042
|
for (const entity of chunk.entities) {
|
|
4031
4043
|
let existing = await this.storage.getEntity(repositoryId, entity.id);
|
|
@@ -4444,22 +4456,31 @@ var DeepMemory = class {
|
|
|
4444
4456
|
const importer = new RepositoryImporter({
|
|
4445
4457
|
storage: this.storage,
|
|
4446
4458
|
actorId: this.provenance.getContext().actorId,
|
|
4447
|
-
onProgress: (progress) => this.globalEventBus.emit("import:progress", progress)
|
|
4459
|
+
onProgress: (progress) => this.globalEventBus.emit("import:progress", progress),
|
|
4460
|
+
signal: options.signal
|
|
4448
4461
|
});
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4462
|
+
try {
|
|
4463
|
+
const result = await importer.import(archive, options);
|
|
4464
|
+
if (result.success) {
|
|
4465
|
+
await this.globalEventBus.emit("import:completed", {
|
|
4466
|
+
repositoryId: result.repositoryId,
|
|
4467
|
+
entitiesImported: result.statistics.entitiesImported,
|
|
4468
|
+
relationshipsImported: result.statistics.relationshipsImported
|
|
4469
|
+
});
|
|
4470
|
+
} else {
|
|
4471
|
+
await this.globalEventBus.emit("import:failed", {
|
|
4472
|
+
repositoryId: result.repositoryId,
|
|
4473
|
+
error: result.warnings.map((w) => w.message).join("; ")
|
|
4474
|
+
});
|
|
4475
|
+
}
|
|
4476
|
+
return result;
|
|
4477
|
+
} catch (err) {
|
|
4457
4478
|
await this.globalEventBus.emit("import:failed", {
|
|
4458
|
-
repositoryId:
|
|
4459
|
-
error:
|
|
4479
|
+
repositoryId: options.target.repositoryId,
|
|
4480
|
+
error: err instanceof Error ? err.message : String(err)
|
|
4460
4481
|
});
|
|
4482
|
+
throw err;
|
|
4461
4483
|
}
|
|
4462
|
-
return result;
|
|
4463
4484
|
}
|
|
4464
4485
|
/**
|
|
4465
4486
|
* Stream a repository export as an async generator.
|
|
@@ -4528,23 +4549,77 @@ var DeepMemory = class {
|
|
|
4528
4549
|
const importer = new RepositoryImporter({
|
|
4529
4550
|
storage: this.storage,
|
|
4530
4551
|
actorId: this.provenance.getContext().actorId,
|
|
4531
|
-
onProgress: (progress) => this.globalEventBus.emit("import:progress", progress)
|
|
4552
|
+
onProgress: (progress) => this.globalEventBus.emit("import:progress", progress),
|
|
4553
|
+
signal: options.signal
|
|
4532
4554
|
});
|
|
4533
4555
|
await this.globalEventBus.emit("import:started", { repositoryId: options.target.repositoryId });
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4556
|
+
try {
|
|
4557
|
+
const result = await importer.importStream(header, chunks, options);
|
|
4558
|
+
if (result.success) {
|
|
4559
|
+
await this.globalEventBus.emit("import:completed", {
|
|
4560
|
+
repositoryId: result.repositoryId,
|
|
4561
|
+
entitiesImported: result.statistics.entitiesImported,
|
|
4562
|
+
relationshipsImported: result.statistics.relationshipsImported
|
|
4563
|
+
});
|
|
4564
|
+
} else {
|
|
4565
|
+
await this.globalEventBus.emit("import:failed", {
|
|
4566
|
+
repositoryId: result.repositoryId,
|
|
4567
|
+
error: result.warnings.map((w) => w.message).join("; ")
|
|
4568
|
+
});
|
|
4569
|
+
}
|
|
4570
|
+
return result;
|
|
4571
|
+
} catch (err) {
|
|
4542
4572
|
await this.globalEventBus.emit("import:failed", {
|
|
4543
|
-
repositoryId:
|
|
4544
|
-
error:
|
|
4573
|
+
repositoryId: options.target.repositoryId,
|
|
4574
|
+
error: err instanceof Error ? err.message : String(err)
|
|
4545
4575
|
});
|
|
4576
|
+
throw err;
|
|
4577
|
+
}
|
|
4578
|
+
}
|
|
4579
|
+
/**
|
|
4580
|
+
* Re-embed all entities in a repository, emitting `reembed:*` events on the
|
|
4581
|
+
* global event bus (reachable via {@link DeepMemory.on}).
|
|
4582
|
+
*
|
|
4583
|
+
* Mirrors the lifecycle of {@link importRepositoryStream}: emits
|
|
4584
|
+
* `reembed:started` up front, `reembed:progress` after every batch,
|
|
4585
|
+
* and either `reembed:completed` or `reembed:failed` at the end.
|
|
4586
|
+
*
|
|
4587
|
+
* `options.signal` is honoured at batch boundaries — any vectors already
|
|
4588
|
+
* written by completed batches are retained, and `reembed:failed` is emitted
|
|
4589
|
+
* with the abort error message.
|
|
4590
|
+
*/
|
|
4591
|
+
async reembedAll(repositoryId, options) {
|
|
4592
|
+
await this.ensureInitialized();
|
|
4593
|
+
const repo = await this.openRepository(repositoryId);
|
|
4594
|
+
const stats = await repo.getStats();
|
|
4595
|
+
await this.globalEventBus.emit("reembed:started", {
|
|
4596
|
+
repositoryId,
|
|
4597
|
+
totalEntities: stats.entityCount
|
|
4598
|
+
});
|
|
4599
|
+
try {
|
|
4600
|
+
const result = await repo.reembedAll({
|
|
4601
|
+
...options,
|
|
4602
|
+
onProgress: (progress) => this.globalEventBus.emit("reembed:progress", {
|
|
4603
|
+
repositoryId,
|
|
4604
|
+
processed: progress.processed,
|
|
4605
|
+
totalEntities: progress.totalEntities,
|
|
4606
|
+
failed: progress.failed
|
|
4607
|
+
})
|
|
4608
|
+
});
|
|
4609
|
+
await this.globalEventBus.emit("reembed:completed", {
|
|
4610
|
+
repositoryId,
|
|
4611
|
+
processed: result.processed,
|
|
4612
|
+
failed: result.failed,
|
|
4613
|
+
modelId: result.modelId
|
|
4614
|
+
});
|
|
4615
|
+
return result;
|
|
4616
|
+
} catch (err) {
|
|
4617
|
+
await this.globalEventBus.emit("reembed:failed", {
|
|
4618
|
+
repositoryId,
|
|
4619
|
+
error: err instanceof Error ? err.message : String(err)
|
|
4620
|
+
});
|
|
4621
|
+
throw err;
|
|
4546
4622
|
}
|
|
4547
|
-
return result;
|
|
4548
4623
|
}
|
|
4549
4624
|
/** Subscribe to global events */
|
|
4550
4625
|
on(event, handler) {
|
|
@@ -5646,6 +5721,7 @@ var NoOpEmbeddingProvider = class {
|
|
|
5646
5721
|
InvalidInputError,
|
|
5647
5722
|
MemoryRepository,
|
|
5648
5723
|
NoOpEmbeddingProvider,
|
|
5724
|
+
OperationAbortedError,
|
|
5649
5725
|
OperationCancelledError,
|
|
5650
5726
|
ProviderError,
|
|
5651
5727
|
RelationshipConstraintError,
|