memory-lancedb-pro 1.0.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.
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Noise Filter
3
+ * Filters out low-quality memories (meta-questions, agent denials, session boilerplate)
4
+ * Inspired by openclaw-plugin-continuity's noise filtering approach.
5
+ */
6
+
7
+ // Agent-side denial patterns
8
+ const DENIAL_PATTERNS = [
9
+ /i don'?t have (any )?(information|data|memory|record)/i,
10
+ /i'?m not sure about/i,
11
+ /i don'?t recall/i,
12
+ /i don'?t remember/i,
13
+ /it looks like i don'?t/i,
14
+ /i wasn'?t able to find/i,
15
+ /no (relevant )?memories found/i,
16
+ /i don'?t have access to/i,
17
+ ];
18
+
19
+ // User-side meta-question patterns (about memory itself, not content)
20
+ const META_QUESTION_PATTERNS = [
21
+ /\bdo you (remember|recall|know about)\b/i,
22
+ /\bcan you (remember|recall)\b/i,
23
+ /\bdid i (tell|mention|say|share)\b/i,
24
+ /\bhave i (told|mentioned|said)\b/i,
25
+ /\bwhat did i (tell|say|mention)\b/i,
26
+ ];
27
+
28
+ // Session boilerplate
29
+ const BOILERPLATE_PATTERNS = [
30
+ /^(hi|hello|hey|good morning|good evening|greetings)/i,
31
+ /^fresh session/i,
32
+ /^new session/i,
33
+ /^HEARTBEAT/i,
34
+ ];
35
+
36
+ export interface NoiseFilterOptions {
37
+ /** Filter agent denial responses (default: true) */
38
+ filterDenials?: boolean;
39
+ /** Filter meta-questions about memory (default: true) */
40
+ filterMetaQuestions?: boolean;
41
+ /** Filter session boilerplate (default: true) */
42
+ filterBoilerplate?: boolean;
43
+ }
44
+
45
+ const DEFAULT_OPTIONS: Required<NoiseFilterOptions> = {
46
+ filterDenials: true,
47
+ filterMetaQuestions: true,
48
+ filterBoilerplate: true,
49
+ };
50
+
51
+ /**
52
+ * Check if a memory text is noise that should be filtered out.
53
+ * Returns true if the text is noise.
54
+ */
55
+ export function isNoise(text: string, options: NoiseFilterOptions = {}): boolean {
56
+ const opts = { ...DEFAULT_OPTIONS, ...options };
57
+ const trimmed = text.trim();
58
+
59
+ if (trimmed.length < 5) return true;
60
+
61
+ if (opts.filterDenials && DENIAL_PATTERNS.some(p => p.test(trimmed))) return true;
62
+ if (opts.filterMetaQuestions && META_QUESTION_PATTERNS.some(p => p.test(trimmed))) return true;
63
+ if (opts.filterBoilerplate && BOILERPLATE_PATTERNS.some(p => p.test(trimmed))) return true;
64
+
65
+ return false;
66
+ }
67
+
68
+ /**
69
+ * Filter an array of items, removing noise entries.
70
+ */
71
+ export function filterNoise<T>(
72
+ items: T[],
73
+ getText: (item: T) => string,
74
+ options?: NoiseFilterOptions
75
+ ): T[] {
76
+ const opts = { ...DEFAULT_OPTIONS, ...options };
77
+ return items.filter(item => !isNoise(getText(item), opts));
78
+ }