memory-lancedb-pro 1.0.26 → 1.0.28

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 CHANGED
@@ -416,6 +416,13 @@ const memoryLanceDBProPlugin = {
416
416
 
417
417
  const pluginVersion = getPluginVersion();
418
418
 
419
+ // Session-based recall history to prevent redundant injections
420
+ // Map<sessionId, Map<memoryId, turnIndex>>
421
+ const recallHistory = new Map<string, Map<string, number>>();
422
+
423
+ // Map<sessionId, turnCounter> - manual turn tracking per session
424
+ const turnCounter = new Map<string, number>();
425
+
419
426
  api.logger.info(
420
427
  `memory-lancedb-pro@${pluginVersion}: plugin registered (db: ${resolvedDbPath}, model: ${config.embedding.model || "text-embedding-3-small"})`,
421
428
  );
@@ -468,6 +475,11 @@ const memoryLanceDBProPlugin = {
468
475
  return;
469
476
  }
470
477
 
478
+ // Manually increment turn counter for this session
479
+ const sessionId = ctx?.sessionId || "default";
480
+ const currentTurn = (turnCounter.get(sessionId) || 0) + 1;
481
+ turnCounter.set(sessionId, currentTurn);
482
+
471
483
  try {
472
484
  // Determine agent ID and accessible scopes
473
485
  const agentId = ctx?.agentId || "main";
@@ -484,7 +496,46 @@ const memoryLanceDBProPlugin = {
484
496
  return;
485
497
  }
486
498
 
487
- const memoryContext = results
499
+ // Filter out redundant memories based on session history
500
+ const minRepeated = config.autoRecallMinRepeated ?? 0;
501
+
502
+ // Only enable dedup logic when minRepeated > 0
503
+ let finalResults = results;
504
+
505
+ if (minRepeated > 0) {
506
+ const sessionHistory = recallHistory.get(sessionId) || new Map<string, number>();
507
+ const filteredResults = results.filter((r) => {
508
+ const lastTurn = sessionHistory.get(r.entry.id) ?? -999;
509
+ const diff = currentTurn - lastTurn;
510
+ const isRedundant = diff < minRepeated;
511
+
512
+ if (isRedundant) {
513
+ api.logger.debug?.(
514
+ `memory-lancedb-pro: skipping redundant memory ${r.entry.id.slice(0, 8)} (last seen at turn ${lastTurn}, current turn ${currentTurn}, min ${minRepeated})`,
515
+ );
516
+ }
517
+ return !isRedundant;
518
+ });
519
+
520
+ if (filteredResults.length === 0) {
521
+ if (results.length > 0) {
522
+ api.logger.info?.(
523
+ `memory-lancedb-pro: all ${results.length} memories were filtered out due to redundancy policy`,
524
+ );
525
+ }
526
+ return;
527
+ }
528
+
529
+ // Update history with successfully injected memories
530
+ for (const r of filteredResults) {
531
+ sessionHistory.set(r.entry.id, currentTurn);
532
+ }
533
+ recallHistory.set(sessionId, sessionHistory);
534
+
535
+ finalResults = filteredResults;
536
+ }
537
+
538
+ const memoryContext = finalResults
488
539
  .map(
489
540
  (r) =>
490
541
  `- [${r.entry.category}:${r.entry.scope}] ${sanitizeForContext(r.entry.text)} (${(r.score * 100).toFixed(0)}%${r.sources?.bm25 ? ", vector+BM25" : ""}${r.sources?.reranked ? "+reranked" : ""})`,
@@ -492,7 +543,7 @@ const memoryLanceDBProPlugin = {
492
543
  .join("\n");
493
544
 
494
545
  api.logger.info?.(
495
- `memory-lancedb-pro: injecting ${results.length} memories into context for agent ${agentId}`,
546
+ `memory-lancedb-pro: injecting ${finalResults.length} memories into context for agent ${agentId}`,
496
547
  );
497
548
 
498
549
  return {
@@ -894,7 +945,6 @@ function parsePluginConfig(value: unknown): PluginConfig {
894
945
  if (!apiKey || (Array.isArray(apiKey) && apiKey.length === 0)) {
895
946
  throw new Error("embedding.apiKey is required (set directly or via OPENAI_API_KEY env var)");
896
947
  }
897
- }
898
948
 
899
949
  return {
900
950
  embedding: {
@@ -87,6 +87,13 @@
87
87
  "default": 15,
88
88
  "description": "Minimum prompt length (in characters) to trigger auto-recall. Prompts shorter than this are skipped. Default: 15 for English, 6 for CJK."
89
89
  },
90
+ "autoRecallMinRepeated": {
91
+ "type": "integer",
92
+ "minimum": 0,
93
+ "maximum": 100,
94
+ "default": 0,
95
+ "description": "Minimum number of turns before the same memory can be recalled again in the same session. Set to 0 to disable deduplication (default behavior: inject all memories)."
96
+ },
90
97
  "captureAssistant": {
91
98
  "type": "boolean"
92
99
  },
@@ -334,6 +341,11 @@
334
341
  "help": "Minimum prompt length to trigger auto-recall (shorter prompts are skipped). Default: 15 chars for English, 6 for CJK.",
335
342
  "advanced": true
336
343
  },
344
+ "autoRecallMinRepeated": {
345
+ "label": "Auto-Recall Min Repeated",
346
+ "help": "Minimum number of conversation turns before a specific memory can be re-injected in the same session.",
347
+ "advanced": true
348
+ },
337
349
  "captureAssistant": {
338
350
  "label": "Capture Assistant Messages",
339
351
  "help": "Also auto-capture assistant messages (default false to reduce memory pollution)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memory-lancedb-pro",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "OpenClaw enhanced LanceDB memory plugin with hybrid retrieval (Vector + BM25), cross-encoder rerank, multi-scope isolation, long-context chunking, and management CLI",
5
5
  "type": "module",
6
6
  "main": "index.ts",