@mastra/memory 1.35.0 → 1.36.0-alpha.1
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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-memory-observational-memory.md +25 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +35 -1
- package/dist/docs/references/docs-storage.md +1 -0
- package/dist/docs/references/reference-memory-observational-memory.md +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/activation-ttl.d.ts +4 -2
- package/dist/processors/observational-memory/activation-ttl.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +23 -4
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/dist/{src-CPCWMt3d.js → src-CFTlELNa.js} +151 -44
- package/dist/{src-CPCWMt3d.js.map → src-CFTlELNa.js.map} +1 -1
- package/dist/{src-BlhP1hpS.cjs → src-Ch_8ufgu.cjs} +151 -44
- package/dist/{src-BlhP1hpS.cjs.map → src-Ch_8ufgu.cjs.map} +1 -1
- package/package.json +3 -3
|
@@ -26024,8 +26024,23 @@ function getOpenAIPromptCacheRetention(providerOptions) {
|
|
|
26024
26024
|
const openaiOptions = providerOptions?.openai;
|
|
26025
26025
|
return typeof openaiOptions?.promptCacheRetention === "string" ? openaiOptions.promptCacheRetention.toLowerCase() : void 0;
|
|
26026
26026
|
}
|
|
26027
|
+
function isActivationTTLMap(activateAfterIdle) {
|
|
26028
|
+
return typeof activateAfterIdle === "object" && activateAfterIdle !== null;
|
|
26029
|
+
}
|
|
26030
|
+
/** The configured TTL for marker payloads. Per-provider maps are omitted; markers only carry scalar values. */
|
|
26031
|
+
function getMarkerActivationTTL(activateAfterIdle) {
|
|
26032
|
+
return isActivationTTLMap(activateAfterIdle) ? void 0 : activateAfterIdle;
|
|
26033
|
+
}
|
|
26034
|
+
/** A map entry applies when its key equals the model's provider before the first `.`, lowercased. */
|
|
26035
|
+
function resolveActivationTTLMapEntry(activateAfterIdle, modelContext) {
|
|
26036
|
+
const providerKey = normalize(modelContext?.provider).split(".")[0];
|
|
26037
|
+
if (providerKey && Object.hasOwn(activateAfterIdle.providers, providerKey)) return activateAfterIdle.providers[providerKey];
|
|
26038
|
+
return activateAfterIdle.default;
|
|
26039
|
+
}
|
|
26027
26040
|
function resolveActivationTTL(activateAfterIdle, modelContext) {
|
|
26028
|
-
|
|
26041
|
+
const ttl = isActivationTTLMap(activateAfterIdle) ? resolveActivationTTLMapEntry(activateAfterIdle, modelContext) : activateAfterIdle;
|
|
26042
|
+
if (ttl === void 0 || ttl === false) return;
|
|
26043
|
+
if (ttl !== "auto") return ttl;
|
|
26029
26044
|
return resolveAutoActivationTTL(modelContext);
|
|
26030
26045
|
}
|
|
26031
26046
|
function resolveAutoActivationTTL(modelContext) {
|
|
@@ -28835,7 +28850,7 @@ var ReflectorRunner = class {
|
|
|
28835
28850
|
messageTokens: getMaxThreshold(this.observationConfig.messageTokens),
|
|
28836
28851
|
observationTokens: getMaxThreshold(record ? this.getEffectiveReflectionTokens(record) : this.reflectionConfig.observationTokens),
|
|
28837
28852
|
scope: this.scope,
|
|
28838
|
-
activateAfterIdle: this.reflectionConfig.activateAfterIdle
|
|
28853
|
+
activateAfterIdle: getMarkerActivationTTL(this.reflectionConfig.activateAfterIdle)
|
|
28839
28854
|
};
|
|
28840
28855
|
}
|
|
28841
28856
|
/**
|
|
@@ -29266,7 +29281,7 @@ var ReflectorRunner = class {
|
|
|
29266
29281
|
currentModel: activationMetadata?.currentModel,
|
|
29267
29282
|
config: {
|
|
29268
29283
|
...this.getObservationMarkerConfig(freshRecord),
|
|
29269
|
-
activateAfterIdle: activationMetadata?.activateAfterIdle ?? this.reflectionConfig.activateAfterIdle
|
|
29284
|
+
activateAfterIdle: activationMetadata?.activateAfterIdle ?? getMarkerActivationTTL(this.reflectionConfig.activateAfterIdle)
|
|
29270
29285
|
}
|
|
29271
29286
|
});
|
|
29272
29287
|
writer.custom({
|
|
@@ -29955,6 +29970,32 @@ function parseActivationTTL(value, fieldPath) {
|
|
|
29955
29970
|
if (!Number.isFinite(amount) || amount < 0) throw new Error(`${fieldPath} must be a non-negative number of milliseconds or a duration string like "5m".`);
|
|
29956
29971
|
return amount * (unit === "ms" || unit === "msec" || unit === "msecs" || unit === "millisecond" || unit === "milliseconds" ? 1 : unit === "s" || unit === "sec" || unit === "secs" || unit === "second" || unit === "seconds" ? 1e3 : unit === "m" || unit === "min" || unit === "mins" || unit === "minute" || unit === "minutes" ? 6e4 : 36e5);
|
|
29957
29972
|
}
|
|
29973
|
+
/**
|
|
29974
|
+
* Parse an `activateAfterIdle` config value: a scalar TTL, or a per-provider map
|
|
29975
|
+
* like `{ default: 'auto', anthropic: '1h' }`.
|
|
29976
|
+
*/
|
|
29977
|
+
function parseActivationTTLConfig(value, fieldPath) {
|
|
29978
|
+
if (typeof value !== "object") return parseActivationTTL(value, fieldPath);
|
|
29979
|
+
if (value === null || Array.isArray(value)) throw new Error(`${fieldPath} must be a TTL value or an object of per-provider TTLs, e.g. { default: 'auto', anthropic: '1h' }.`);
|
|
29980
|
+
const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0);
|
|
29981
|
+
if (entries.length === 0) throw new Error(`${fieldPath} must set at least one provider or "default" when using per-provider TTLs, e.g. { default: 'auto', anthropic: '1h' }.`);
|
|
29982
|
+
const parsed = { providers: Object.create(null) };
|
|
29983
|
+
const seenKeys = /* @__PURE__ */ new Set();
|
|
29984
|
+
for (const [rawKey, entryValue] of entries) {
|
|
29985
|
+
const key = rawKey.trim().toLowerCase();
|
|
29986
|
+
const entryPath = `${fieldPath}.${rawKey}`;
|
|
29987
|
+
if (!key) throw new Error(`${fieldPath} contains an empty provider key.`);
|
|
29988
|
+
if (key.includes(".") || key.includes("/")) throw new Error(`${entryPath} is not a valid provider key. Use the provider name before the first ".", e.g. "anthropic" instead of "anthropic.messages".`);
|
|
29989
|
+
if (seenKeys.has(key)) throw new Error(`${entryPath} duplicates another key in ${fieldPath}. Provider keys are case-insensitive.`);
|
|
29990
|
+
seenKeys.add(key);
|
|
29991
|
+
if (entryValue !== false && typeof entryValue !== "number" && typeof entryValue !== "string") throw new Error(`${entryPath} must be a non-negative number of milliseconds, a duration string like "5m" or "1hr", "auto", or false.`);
|
|
29992
|
+
const ttl = entryValue === false ? false : parseActivationTTL(entryValue, entryPath);
|
|
29993
|
+
if (key === "default") {
|
|
29994
|
+
if (ttl !== false) parsed.default = ttl;
|
|
29995
|
+
} else parsed.providers[key] = ttl;
|
|
29996
|
+
}
|
|
29997
|
+
return parsed;
|
|
29998
|
+
}
|
|
29958
29999
|
let hasWarnedResourceScopeDeprecation = false;
|
|
29959
30000
|
/**
|
|
29960
30001
|
* ObservationalMemory - A three-agent memory system for long conversations.
|
|
@@ -30169,7 +30210,7 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
30169
30210
|
bufferTokens: asyncBufferingDisabled ? void 0 : resolveBufferTokens(config.observation?.bufferTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferTokens, config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens),
|
|
30170
30211
|
bufferOnIdle: config.observation?.bufferOnIdle ?? false,
|
|
30171
30212
|
bufferActivation: asyncBufferingDisabled ? void 0 : config.observation?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferActivation,
|
|
30172
|
-
activateAfterIdle:
|
|
30213
|
+
activateAfterIdle: parseActivationTTLConfig(observationActivateAfterIdle, observationActivateAfterIdlePath),
|
|
30173
30214
|
activateOnProviderChange: config.observation?.activateOnProviderChange ?? config.activateOnProviderChange ?? false,
|
|
30174
30215
|
blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(config.observation?.blockAfter ?? (config.observation?.bufferTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferTokens ? 1.2 : void 0), config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens),
|
|
30175
30216
|
previousObserverTokens: config.observation?.previousObserverTokens ?? 2e3,
|
|
@@ -30194,7 +30235,7 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
30194
30235
|
},
|
|
30195
30236
|
providerOptions: config.reflection?.providerOptions ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.providerOptions,
|
|
30196
30237
|
bufferActivation: asyncBufferingDisabled ? void 0 : config?.reflection?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation,
|
|
30197
|
-
activateAfterIdle:
|
|
30238
|
+
activateAfterIdle: parseActivationTTLConfig(config.reflection?.activateAfterIdle, "reflection.activateAfterIdle"),
|
|
30198
30239
|
activateOnProviderChange: config.reflection?.activateOnProviderChange ?? false,
|
|
30199
30240
|
blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(config.reflection?.blockAfter ?? (config.reflection?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation ? 1.2 : void 0), config.reflection?.observationTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens),
|
|
30200
30241
|
instruction: config.reflection?.instruction,
|
|
@@ -30520,7 +30561,7 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
30520
30561
|
messageTokens: getMaxThreshold(this.observationConfig.messageTokens),
|
|
30521
30562
|
observationTokens: getMaxThreshold(this.reflectionConfig.observationTokens),
|
|
30522
30563
|
scope: this.scope,
|
|
30523
|
-
activateAfterIdle: this.observationConfig.activateAfterIdle
|
|
30564
|
+
activateAfterIdle: getMarkerActivationTTL(this.observationConfig.activateAfterIdle)
|
|
30524
30565
|
};
|
|
30525
30566
|
}
|
|
30526
30567
|
/**
|
|
@@ -31921,7 +31962,7 @@ ${formattedMessages}
|
|
|
31921
31962
|
currentModel,
|
|
31922
31963
|
config: {
|
|
31923
31964
|
...this.getObservationMarkerConfig(),
|
|
31924
|
-
activateAfterIdle: activationActivateAfterIdle ?? this.observationConfig.activateAfterIdle
|
|
31965
|
+
activateAfterIdle: activationActivateAfterIdle ?? getMarkerActivationTTL(this.observationConfig.activateAfterIdle)
|
|
31925
31966
|
}
|
|
31926
31967
|
});
|
|
31927
31968
|
opts.writer.custom({
|
|
@@ -33232,22 +33273,32 @@ var Memory = class Memory extends MastraMemory {
|
|
|
33232
33273
|
if (resourceScope && !resourceId && config?.semanticRecall && vectorSearchString) throw new Error("Memory error: Resource-scoped semantic recall is enabled but no resourceId was provided. Either provide a resourceId or explicitly set semanticRecall.scope to 'thread'.");
|
|
33233
33274
|
let usage;
|
|
33234
33275
|
if (config?.semanticRecall && vectorSearchString && this.vector) {
|
|
33235
|
-
const
|
|
33236
|
-
|
|
33237
|
-
const {
|
|
33238
|
-
|
|
33239
|
-
|
|
33240
|
-
if (typeof this.vector === `undefined`) throw new Error(`Tried to query vector index ${indexName} but this Memory instance doesn't have an attached vector db.`);
|
|
33241
|
-
const scopeFilter = resourceScope ? { resource_id: resourceId } : { thread_id: threadId };
|
|
33242
|
-
const userFilter = typeof config.semanticRecall === "object" ? config.semanticRecall.filter : void 0;
|
|
33243
|
-
const combinedFilter = userFilter ? { $and: [scopeFilter, userFilter] } : scopeFilter;
|
|
33276
|
+
const scopeFilter = resourceScope ? { resource_id: resourceId } : { thread_id: threadId };
|
|
33277
|
+
const userFilter = typeof config.semanticRecall === "object" ? config.semanticRecall.filter : void 0;
|
|
33278
|
+
const combinedFilter = userFilter ? { $and: [scopeFilter, userFilter] } : scopeFilter;
|
|
33279
|
+
if (this.isSelfEmbedding) {
|
|
33280
|
+
const { indexName } = await this.createEmbeddingIndex(void 0, config);
|
|
33244
33281
|
vectorResults.push(...await this.vector.query({
|
|
33245
33282
|
indexName,
|
|
33246
|
-
|
|
33283
|
+
queryText: vectorSearchString,
|
|
33247
33284
|
topK: vectorConfig.topK,
|
|
33248
33285
|
filter: combinedFilter
|
|
33249
33286
|
}));
|
|
33250
|
-
}
|
|
33287
|
+
} else {
|
|
33288
|
+
const result = await this.embedMessageContent(vectorSearchString);
|
|
33289
|
+
usage = result.usage;
|
|
33290
|
+
const { embeddings, dimension } = result;
|
|
33291
|
+
const { indexName } = await this.createEmbeddingIndex(dimension, config);
|
|
33292
|
+
await Promise.all(embeddings.map(async (embedding) => {
|
|
33293
|
+
if (typeof this.vector === `undefined`) throw new Error(`Tried to query vector index ${indexName} but this Memory instance doesn't have an attached vector db.`);
|
|
33294
|
+
vectorResults.push(...await this.vector.query({
|
|
33295
|
+
indexName,
|
|
33296
|
+
queryVector: embedding,
|
|
33297
|
+
topK: vectorConfig.topK,
|
|
33298
|
+
filter: combinedFilter
|
|
33299
|
+
}));
|
|
33300
|
+
}));
|
|
33301
|
+
}
|
|
33251
33302
|
}
|
|
33252
33303
|
const threshold = (typeof config.semanticRecall === "object" ? config.semanticRecall : void 0)?.threshold;
|
|
33253
33304
|
const filteredVectorResults = threshold !== void 0 ? vectorResults.filter((r) => r.score >= threshold) : vectorResults;
|
|
@@ -33405,11 +33456,13 @@ var Memory = class Memory extends MastraMemory {
|
|
|
33405
33456
|
if (this.vector) this.trackVectorCleanup(this.deleteThreadVectors(threadId));
|
|
33406
33457
|
}
|
|
33407
33458
|
/**
|
|
33408
|
-
* Prefix shared by every message index. The index for the default embedding
|
|
33409
|
-
*
|
|
33459
|
+
* Prefix shared by every message index. The index for the default embedding dimension is named
|
|
33460
|
+
* with the bare prefix; other dimensions add a dimension suffix, and a store that embeds the
|
|
33461
|
+
* text itself adds its own. Built here rather than read from `getEmbeddingIndexName()`, which
|
|
33462
|
+
* answers for one configuration and so would not match indexes written under another.
|
|
33410
33463
|
*/
|
|
33411
33464
|
get messageIndexPrefix() {
|
|
33412
|
-
return this.
|
|
33465
|
+
return `memory${this.vector?.indexSeparator ?? "_"}messages`;
|
|
33413
33466
|
}
|
|
33414
33467
|
/**
|
|
33415
33468
|
* Prefix shared by every observation index. Each observation index adds a dimension suffix.
|
|
@@ -33694,13 +33747,24 @@ ${workingMemory}`;
|
|
|
33694
33747
|
if (joined) textForEmbedding = joined;
|
|
33695
33748
|
}
|
|
33696
33749
|
if (!textForEmbedding) return;
|
|
33697
|
-
|
|
33698
|
-
|
|
33699
|
-
|
|
33750
|
+
let embeddings = [];
|
|
33751
|
+
let documents;
|
|
33752
|
+
let chunks;
|
|
33753
|
+
if (this.isSelfEmbedding) {
|
|
33754
|
+
chunks = this.chunkText(textForEmbedding);
|
|
33755
|
+
documents = chunks;
|
|
33756
|
+
} else {
|
|
33757
|
+
const result = await this.embedMessageContent(textForEmbedding);
|
|
33758
|
+
dimension = result.dimension;
|
|
33759
|
+
if (result.usage?.tokens) totalTokens += result.usage.tokens;
|
|
33760
|
+
embeddings = result.embeddings;
|
|
33761
|
+
chunks = result.chunks;
|
|
33762
|
+
}
|
|
33700
33763
|
const threadMetadata = message.threadId ? threadMetadataMap.get(message.threadId) || {} : {};
|
|
33701
33764
|
embeddingData.push({
|
|
33702
|
-
embeddings
|
|
33703
|
-
|
|
33765
|
+
embeddings,
|
|
33766
|
+
documents,
|
|
33767
|
+
metadata: chunks.map(() => ({
|
|
33704
33768
|
...threadMetadata,
|
|
33705
33769
|
message_id: message.id,
|
|
33706
33770
|
thread_id: message.threadId,
|
|
@@ -33711,16 +33775,23 @@ ${workingMemory}`;
|
|
|
33711
33775
|
}))
|
|
33712
33776
|
});
|
|
33713
33777
|
}));
|
|
33714
|
-
if (embeddingData.length > 0 && dimension !== void 0) {
|
|
33778
|
+
if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
|
|
33715
33779
|
if (typeof this.vector === `undefined`) throw new Error(`Tried to upsert embeddings but this Memory instance doesn't have an attached vector db.`);
|
|
33716
33780
|
const { indexName } = await this.createEmbeddingIndex(dimension, config);
|
|
33717
33781
|
const allVectors = [];
|
|
33718
33782
|
const allMetadata = [];
|
|
33783
|
+
const allDocuments = [];
|
|
33719
33784
|
for (const data of embeddingData) {
|
|
33720
33785
|
allVectors.push(...data.embeddings);
|
|
33786
|
+
if (data.documents) allDocuments.push(...data.documents);
|
|
33721
33787
|
allMetadata.push(...data.metadata);
|
|
33722
33788
|
}
|
|
33723
|
-
await this.vector.upsert({
|
|
33789
|
+
if (this.isSelfEmbedding) await this.vector.upsert({
|
|
33790
|
+
indexName,
|
|
33791
|
+
documents: allDocuments,
|
|
33792
|
+
metadata: allMetadata
|
|
33793
|
+
});
|
|
33794
|
+
else await this.vector.upsert({
|
|
33724
33795
|
indexName,
|
|
33725
33796
|
vectors: allVectors,
|
|
33726
33797
|
metadata: allMetadata
|
|
@@ -34505,11 +34576,22 @@ Notes:
|
|
|
34505
34576
|
}
|
|
34506
34577
|
}
|
|
34507
34578
|
if (textForEmbedding) {
|
|
34508
|
-
|
|
34509
|
-
|
|
34579
|
+
let embeddings = [];
|
|
34580
|
+
let documents;
|
|
34581
|
+
let chunks;
|
|
34582
|
+
if (this.isSelfEmbedding) {
|
|
34583
|
+
chunks = this.chunkText(textForEmbedding);
|
|
34584
|
+
documents = chunks;
|
|
34585
|
+
} else {
|
|
34586
|
+
const result = await this.embedMessageContent(textForEmbedding);
|
|
34587
|
+
dimension = result.dimension;
|
|
34588
|
+
embeddings = result.embeddings;
|
|
34589
|
+
chunks = result.chunks;
|
|
34590
|
+
}
|
|
34510
34591
|
embeddingData.push({
|
|
34511
|
-
embeddings
|
|
34512
|
-
|
|
34592
|
+
embeddings,
|
|
34593
|
+
documents,
|
|
34594
|
+
metadata: chunks.map(() => ({
|
|
34513
34595
|
message_id: message.id,
|
|
34514
34596
|
thread_id: existingMessage.threadId,
|
|
34515
34597
|
resource_id: existingMessage.resourceId,
|
|
@@ -34544,15 +34626,22 @@ Notes:
|
|
|
34544
34626
|
} catch {
|
|
34545
34627
|
this.logger.debug("Failed to clean up old vectors during message update");
|
|
34546
34628
|
}
|
|
34547
|
-
if (embeddingData.length > 0 && dimension !== void 0) {
|
|
34629
|
+
if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
|
|
34548
34630
|
const { indexName } = await this.createEmbeddingIndex(dimension, config);
|
|
34549
34631
|
const allVectors = [];
|
|
34550
34632
|
const allMetadata = [];
|
|
34633
|
+
const allDocuments = [];
|
|
34551
34634
|
for (const data of embeddingData) {
|
|
34552
34635
|
allVectors.push(...data.embeddings);
|
|
34636
|
+
if (data.documents) allDocuments.push(...data.documents);
|
|
34553
34637
|
allMetadata.push(...data.metadata);
|
|
34554
34638
|
}
|
|
34555
|
-
await this.vector.upsert({
|
|
34639
|
+
if (this.isSelfEmbedding) await this.vector.upsert({
|
|
34640
|
+
indexName,
|
|
34641
|
+
documents: allDocuments,
|
|
34642
|
+
metadata: allMetadata
|
|
34643
|
+
});
|
|
34644
|
+
else await this.vector.upsert({
|
|
34556
34645
|
indexName,
|
|
34557
34646
|
vectors: allVectors,
|
|
34558
34647
|
metadata: allMetadata
|
|
@@ -34739,7 +34828,7 @@ Notes:
|
|
|
34739
34828
|
await this.rollbackCopiedThread(memoryStore, result.thread, "OM clone", false, priorDestinationResourceWm);
|
|
34740
34829
|
throw error;
|
|
34741
34830
|
}
|
|
34742
|
-
if (this.vector && this.embedder && config.semanticRecall) try {
|
|
34831
|
+
if (this.vector && (this.embedder || this.isSelfEmbedding) && config.semanticRecall) try {
|
|
34743
34832
|
await this.embedCopiedMessagesInBatches(memoryStore, result, config);
|
|
34744
34833
|
} catch (error) {
|
|
34745
34834
|
await this.rollbackCopiedThread(memoryStore, result.thread, "embedding", true, priorDestinationResourceWm);
|
|
@@ -34808,7 +34897,7 @@ Notes:
|
|
|
34808
34897
|
async updateThreadResourceId({ threadId, resourceId, memoryConfig }) {
|
|
34809
34898
|
const memoryStore = await this.getMemoryStore();
|
|
34810
34899
|
const config = this.getMergedThreadConfig(memoryConfig);
|
|
34811
|
-
const migratesVectors = Boolean(this.vector && this.embedder && config.semanticRecall);
|
|
34900
|
+
const migratesVectors = Boolean(this.vector && (this.embedder || this.isSelfEmbedding) && config.semanticRecall);
|
|
34812
34901
|
if (!migratesVectors) {
|
|
34813
34902
|
const existing = await memoryStore.getThreadById({ threadId });
|
|
34814
34903
|
if (existing && existing.resourceId === resourceId) return existing;
|
|
@@ -34914,7 +35003,7 @@ Notes:
|
|
|
34914
35003
|
* This is similar to the embedding logic in saveMessages but operates on already-saved messages.
|
|
34915
35004
|
*/
|
|
34916
35005
|
async embedClonedMessages(messages, config) {
|
|
34917
|
-
if (!this.vector || !this.embedder) return;
|
|
35006
|
+
if (!this.vector || !this.embedder && !this.isSelfEmbedding) return;
|
|
34918
35007
|
const embeddingData = [];
|
|
34919
35008
|
let dimension;
|
|
34920
35009
|
await Promise.all(messages.map(async (message) => {
|
|
@@ -34925,11 +35014,22 @@ Notes:
|
|
|
34925
35014
|
if (joined) textForEmbedding = joined;
|
|
34926
35015
|
}
|
|
34927
35016
|
if (!textForEmbedding) return;
|
|
34928
|
-
|
|
34929
|
-
|
|
35017
|
+
let embeddings = [];
|
|
35018
|
+
let documents;
|
|
35019
|
+
let chunks;
|
|
35020
|
+
if (this.isSelfEmbedding) {
|
|
35021
|
+
chunks = this.chunkText(textForEmbedding);
|
|
35022
|
+
documents = chunks;
|
|
35023
|
+
} else {
|
|
35024
|
+
const result = await this.embedMessageContent(textForEmbedding);
|
|
35025
|
+
dimension = result.dimension;
|
|
35026
|
+
embeddings = result.embeddings;
|
|
35027
|
+
chunks = result.chunks;
|
|
35028
|
+
}
|
|
34930
35029
|
embeddingData.push({
|
|
34931
|
-
embeddings
|
|
34932
|
-
|
|
35030
|
+
embeddings,
|
|
35031
|
+
documents,
|
|
35032
|
+
metadata: chunks.map(() => ({
|
|
34933
35033
|
message_id: message.id,
|
|
34934
35034
|
thread_id: message.threadId,
|
|
34935
35035
|
resource_id: message.resourceId,
|
|
@@ -34939,15 +35039,22 @@ Notes:
|
|
|
34939
35039
|
}))
|
|
34940
35040
|
});
|
|
34941
35041
|
}));
|
|
34942
|
-
if (embeddingData.length > 0 && dimension !== void 0) {
|
|
35042
|
+
if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
|
|
34943
35043
|
const { indexName } = await this.createEmbeddingIndex(dimension, config);
|
|
34944
35044
|
const allVectors = [];
|
|
34945
35045
|
const allMetadata = [];
|
|
35046
|
+
const allDocuments = [];
|
|
34946
35047
|
for (const data of embeddingData) {
|
|
34947
35048
|
allVectors.push(...data.embeddings);
|
|
35049
|
+
if (data.documents) allDocuments.push(...data.documents);
|
|
34948
35050
|
allMetadata.push(...data.metadata);
|
|
34949
35051
|
}
|
|
34950
|
-
await this.vector.upsert({
|
|
35052
|
+
if (this.isSelfEmbedding) await this.vector.upsert({
|
|
35053
|
+
indexName,
|
|
35054
|
+
documents: allDocuments,
|
|
35055
|
+
metadata: allMetadata
|
|
35056
|
+
});
|
|
35057
|
+
else await this.vector.upsert({
|
|
34951
35058
|
indexName,
|
|
34952
35059
|
vectors: allVectors,
|
|
34953
35060
|
metadata: allMetadata
|
|
@@ -35143,4 +35250,4 @@ Notes:
|
|
|
35143
35250
|
//#endregion
|
|
35144
35251
|
export { formatMessagesForObserver as A, OBSERVATION_CONTEXT_PROMPT_THREAD as B, SUMMARIZE_THREAD_DEFAULTS as C, buildObserverPrompt as D, OBSERVER_SYSTEM_PROMPT as E, parseAnchorId as F, StaleKnowledgeSemanticIndexError as G, getObservationContextPrompt as H, stripEphemeralAnchorIds as I, SUBCONSCIOUS_ACTIVITY_STATE_ID as J, SubconsciousRemindExtractor as K, OBSERVATIONAL_MEMORY_DEFAULTS as L, optimizeObservationsForContext as M, parseObserverOutput as N, buildObserverSystemPrompt as O, injectAnchorIds as P, Extractor as Q, OBSERVATION_CONTEXT_INSTRUCTIONS as R, deepMergeWorkingMemory as S, TokenCounter as T, Subconscious as U, OBSERVATION_CONTINUATION_HINT as V, KnowledgeSemanticIndexCoordinator as W, publishSubconsciousActivity as X, buildSubconsciousActivitySnapshot as Y, renderSubconsciousActivity as Z, reconcileObservationGroupsFromReflection as _, extractWorkingMemoryContent as a, wrapInObservationGroup as b, getObservationsAsOf as c, WORKING_MEMORY_STATE_ID as d, WORKING_MEMORY_STATE_PROCESSOR_ID as f, parseObservationGroups as g, deriveObservationGroupProvenance as h, WorkingMemory as i, hasCurrentTaskSection as j, extractCurrentTask as k, ObservationalMemoryProcessor as l, combineObservationGroupRanges as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, WorkingMemoryStateProcessor as p, ModelByInputTokens as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, renderObservationGroupsForReflection as v, summarizeConversation as w, WorkingMemoryExtractor as x, stripObservationGroups as y, OBSERVATION_CONTEXT_PROMPT as z };
|
|
35145
35252
|
|
|
35146
|
-
//# sourceMappingURL=src-
|
|
35253
|
+
//# sourceMappingURL=src-CFTlELNa.js.map
|