openclaw-memory-alibaba-local 1.0.6 → 1.0.8
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/index.ts +56 -5
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1298,12 +1298,27 @@ async function captureUserMemoryFromInboundTexts(
|
|
|
1298
1298
|
embeddingResults.push({ item: { ...item, text: truncated }, vectors });
|
|
1299
1299
|
}
|
|
1300
1300
|
|
|
1301
|
-
// 2.
|
|
1302
|
-
const allVectors = embeddingResults.flatMap((r) => r.vectors);
|
|
1301
|
+
// 2. Per-item recall: for each event item recall top-3 similar existing world_facts, then dedup
|
|
1303
1302
|
const recallMinScore = Math.max(0.5, cfg.similarityThresholdUserMemory - 0.35);
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1306
|
-
|
|
1303
|
+
const PER_ITEM_RECALL = 3;
|
|
1304
|
+
const candidateMap = new Map<string, MemorySearchResult>();
|
|
1305
|
+
for (const er of embeddingResults) {
|
|
1306
|
+
const perItemHits = er.vectors.length > 0
|
|
1307
|
+
? await db.searchMerged(agentId, er.vectors, PER_ITEM_RECALL, recallMinScore, [WORLD_FACT])
|
|
1308
|
+
: [];
|
|
1309
|
+
for (const h of perItemHits) {
|
|
1310
|
+
const key = `${String(h.entry.category)}\0${h.entry.text}`;
|
|
1311
|
+
const prev = candidateMap.get(key);
|
|
1312
|
+
if (!prev || h.score > prev.score) {
|
|
1313
|
+
candidateMap.set(key, h);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
const existingCandidates = [...candidateMap.values()].sort((a, b) => b.score - a.score);
|
|
1318
|
+
console.log(`[openclaw-memory-alibaba-local] worldImageExtraction recall: ${embeddingResults.length} items × ${PER_ITEM_RECALL} = raw ${embeddingResults.length * PER_ITEM_RECALL}, deduped ${existingCandidates.length}, minScore=${recallMinScore}`);
|
|
1319
|
+
if (existingCandidates.length > 0) {
|
|
1320
|
+
console.log(`[openclaw-memory-alibaba-local] worldImageExtraction recall found ${existingCandidates.length} candidates: ${existingCandidates.map((c) => `[${c.score.toFixed(3)}] ${c.entry.text.slice(0, 60)}`).join(" | ")}`);
|
|
1321
|
+
}
|
|
1307
1322
|
|
|
1308
1323
|
// 3. LLM CRUD decision
|
|
1309
1324
|
console.log(`[openclaw-memory-alibaba-local] worldImageExtraction input: ${eventItems.length} event items, ${existingCandidates.length} existing candidates`);
|
|
@@ -1400,9 +1415,13 @@ async function captureUserMemoryFromInboundTexts(
|
|
|
1400
1415
|
// 2. Recall top-10 similar existing memories for ALL new extractions (agentId global, USER_MEMORY scope)
|
|
1401
1416
|
const allVectors = embeddingResults.flatMap((r) => r.vectors);
|
|
1402
1417
|
const recallMinScore = Math.max(0.5, cfg.similarityThresholdUserMemory - 0.35);
|
|
1418
|
+
console.log(`[openclaw-memory-alibaba-local] userImageExtraction recall: ${allVectors.length} query vectors, minScore=${recallMinScore}`);
|
|
1403
1419
|
const existingCandidates = allVectors.length > 0
|
|
1404
1420
|
? await db.searchMerged(agentId, allVectors, 10, recallMinScore, [...USER_MEMORY_CATEGORIES])
|
|
1405
1421
|
: [];
|
|
1422
|
+
if (existingCandidates.length > 0) {
|
|
1423
|
+
console.log(`[openclaw-memory-alibaba-local] userImageExtraction recall found ${existingCandidates.length} candidates: ${existingCandidates.map((c) => `[${c.score.toFixed(3)}] ${c.entry.text.slice(0, 60)}`).join(" | ")}`);
|
|
1424
|
+
}
|
|
1406
1425
|
|
|
1407
1426
|
// 3. Call user image extraction LLM
|
|
1408
1427
|
console.log(`[openclaw-memory-alibaba-local] userImageExtraction input: ${userItems.length} user items (${eventItems.length} event items bypassed), ${existingCandidates.length} existing candidates`);
|
|
@@ -2052,6 +2071,19 @@ const memoryPlugin = {
|
|
|
2052
2071
|
if (!db || !backend) return;
|
|
2053
2072
|
if (!event.prompt || event.prompt.length < 5) return;
|
|
2054
2073
|
|
|
2074
|
+
// Skip recall for system/bootstrap prompts (/new, /reset, session startup).
|
|
2075
|
+
const promptLower = event.prompt.toLowerCase();
|
|
2076
|
+
if (
|
|
2077
|
+
promptLower.includes("a new session was started") ||
|
|
2078
|
+
promptLower.includes("session startup sequence") ||
|
|
2079
|
+
promptLower.includes("/new or /reset") ||
|
|
2080
|
+
promptLower.startsWith("system:") ||
|
|
2081
|
+
promptLower.startsWith("run your session")
|
|
2082
|
+
) {
|
|
2083
|
+
console.log("[openclaw-memory-alibaba-local] recall skip (system/bootstrap prompt)");
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2055
2087
|
try {
|
|
2056
2088
|
const extracted = extractUserQueryForRecall(event.prompt);
|
|
2057
2089
|
if (extracted.query.length < 5) {
|
|
@@ -2144,6 +2176,25 @@ const memoryPlugin = {
|
|
|
2144
2176
|
const trigger = (ctx as { trigger?: string }).trigger;
|
|
2145
2177
|
const isUserTrigger = trigger === "user";
|
|
2146
2178
|
|
|
2179
|
+
// Skip memory extraction for system/bootstrap sessions (/new, /reset).
|
|
2180
|
+
// Check the last user message for known bootstrap patterns.
|
|
2181
|
+
if (isUserTrigger) {
|
|
2182
|
+
const lastUserMsg = [...event.messages].reverse().find(
|
|
2183
|
+
(m: any) => m && typeof m === "object" && (m as Record<string, unknown>).role === "user",
|
|
2184
|
+
) as Record<string, unknown> | undefined;
|
|
2185
|
+
const lastUserText = typeof lastUserMsg?.content === "string" ? lastUserMsg.content.toLowerCase() : "";
|
|
2186
|
+
if (
|
|
2187
|
+
lastUserText.includes("a new session was started") ||
|
|
2188
|
+
lastUserText.includes("session startup sequence") ||
|
|
2189
|
+
lastUserText.includes("/new or /reset") ||
|
|
2190
|
+
lastUserText.startsWith("system:") ||
|
|
2191
|
+
lastUserText.startsWith("run your session")
|
|
2192
|
+
) {
|
|
2193
|
+
console.log("[openclaw-memory-alibaba-local] agent_end skip capture (system/bootstrap session)");
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2147
2198
|
try {
|
|
2148
2199
|
const tCap0 = Date.now();
|
|
2149
2200
|
const storageSessionKey = resolveStorageSessionKey(ctx);
|