openclaw-memory-alibaba-local 1.0.7 → 1.0.9
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 +32 -13
- 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`);
|
|
@@ -1328,7 +1343,7 @@ async function captureUserMemoryFromInboundTexts(
|
|
|
1328
1343
|
if (action.action === "delete") {
|
|
1329
1344
|
const hit = existingCandidates.find((c) => c.entry.id === action.memoryId);
|
|
1330
1345
|
if (hit) {
|
|
1331
|
-
await deleteSimilarLogicalMemory(db, agentId,
|
|
1346
|
+
await deleteSimilarLogicalMemory(db, agentId, hit.entry.sessionId, hit);
|
|
1332
1347
|
}
|
|
1333
1348
|
continue;
|
|
1334
1349
|
}
|
|
@@ -1336,7 +1351,7 @@ async function captureUserMemoryFromInboundTexts(
|
|
|
1336
1351
|
if (action.action === "update") {
|
|
1337
1352
|
const hit = existingCandidates.find((c) => c.entry.id === action.memoryId);
|
|
1338
1353
|
if (hit) {
|
|
1339
|
-
await deleteSimilarLogicalMemory(db, agentId,
|
|
1354
|
+
await deleteSimilarLogicalMemory(db, agentId, hit.entry.sessionId, hit);
|
|
1340
1355
|
}
|
|
1341
1356
|
const { vectors } = await backend.encodeForStorage(action.text);
|
|
1342
1357
|
const rows = buildChunkRows(
|
|
@@ -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`);
|
|
@@ -1428,7 +1447,7 @@ async function captureUserMemoryFromInboundTexts(
|
|
|
1428
1447
|
if (action.action === "delete") {
|
|
1429
1448
|
const hit = existingCandidates.find((c) => c.entry.id === action.memoryId);
|
|
1430
1449
|
if (hit) {
|
|
1431
|
-
await deleteSimilarLogicalMemory(db, agentId,
|
|
1450
|
+
await deleteSimilarLogicalMemory(db, agentId, hit.entry.sessionId, hit);
|
|
1432
1451
|
}
|
|
1433
1452
|
continue;
|
|
1434
1453
|
}
|
|
@@ -1436,7 +1455,7 @@ async function captureUserMemoryFromInboundTexts(
|
|
|
1436
1455
|
if (action.action === "update") {
|
|
1437
1456
|
const hit = existingCandidates.find((c) => c.entry.id === action.memoryId);
|
|
1438
1457
|
if (hit) {
|
|
1439
|
-
await deleteSimilarLogicalMemory(db, agentId,
|
|
1458
|
+
await deleteSimilarLogicalMemory(db, agentId, hit.entry.sessionId, hit);
|
|
1440
1459
|
}
|
|
1441
1460
|
const { vectors } = await backend.encodeForStorage(action.text);
|
|
1442
1461
|
const rows = buildChunkRows(
|
|
@@ -1581,10 +1600,10 @@ async function deleteSimilarLogicalMemory(
|
|
|
1581
1600
|
sessionId: string | null | undefined,
|
|
1582
1601
|
hit: MemorySearchResult,
|
|
1583
1602
|
): Promise<void> {
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
}
|
|
1603
|
+
// Try text-match delete first (covers all chunks), then ID-based fallback.
|
|
1604
|
+
// deleteByAgentSessionCategoryText returns optimistic 1, so always also try by ID.
|
|
1605
|
+
await db.deleteByAgentSessionCategoryText(agentId, sessionId, hit.entry.category, hit.entry.text);
|
|
1606
|
+
await db.delete(agentId, hit.entry.id).catch(() => {});
|
|
1588
1607
|
}
|
|
1589
1608
|
|
|
1590
1609
|
async function storeOneCaptureItem(
|