@yamo/memory-mesh 3.0.0 → 3.0.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.
Files changed (107) hide show
  1. package/README.md +8 -2
  2. package/lib/llm/client.d.ts +23 -48
  3. package/lib/llm/client.js +1 -0
  4. package/lib/llm/client.ts +298 -377
  5. package/lib/llm/index.js +1 -0
  6. package/lib/llm/index.ts +1 -2
  7. package/lib/memory/adapters/client.d.ts +22 -85
  8. package/lib/memory/adapters/client.js +1 -0
  9. package/lib/memory/adapters/client.ts +474 -633
  10. package/lib/memory/adapters/config.d.ts +82 -89
  11. package/lib/memory/adapters/config.js +1 -0
  12. package/lib/memory/adapters/config.ts +156 -225
  13. package/lib/memory/adapters/errors.d.ts +28 -20
  14. package/lib/memory/adapters/errors.js +1 -0
  15. package/lib/memory/adapters/errors.ts +83 -120
  16. package/lib/memory/context-manager.d.ts +15 -18
  17. package/lib/memory/context-manager.js +1 -0
  18. package/lib/memory/context-manager.ts +314 -401
  19. package/lib/memory/embeddings/factory.d.ts +18 -20
  20. package/lib/memory/embeddings/factory.js +1 -0
  21. package/lib/memory/embeddings/factory.ts +130 -173
  22. package/lib/memory/embeddings/index.js +1 -0
  23. package/lib/memory/embeddings/index.ts +1 -0
  24. package/lib/memory/embeddings/service.d.ts +36 -66
  25. package/lib/memory/embeddings/service.js +1 -0
  26. package/lib/memory/embeddings/service.ts +479 -616
  27. package/lib/memory/index.d.ts +2 -2
  28. package/lib/memory/index.js +1 -0
  29. package/lib/memory/index.ts +3 -13
  30. package/lib/memory/memory-mesh.d.ts +151 -93
  31. package/lib/memory/memory-mesh.js +1 -0
  32. package/lib/memory/memory-mesh.ts +1406 -1692
  33. package/lib/memory/memory-translator.d.ts +1 -6
  34. package/lib/memory/memory-translator.js +1 -0
  35. package/lib/memory/memory-translator.ts +96 -128
  36. package/lib/memory/schema.d.ts +29 -10
  37. package/lib/memory/schema.js +1 -0
  38. package/lib/memory/schema.ts +102 -185
  39. package/lib/memory/scorer.d.ts +3 -4
  40. package/lib/memory/scorer.js +1 -0
  41. package/lib/memory/scorer.ts +69 -86
  42. package/lib/memory/search/index.js +1 -0
  43. package/lib/memory/search/index.ts +1 -0
  44. package/lib/memory/search/keyword-search.d.ts +10 -26
  45. package/lib/memory/search/keyword-search.js +1 -0
  46. package/lib/memory/search/keyword-search.ts +123 -161
  47. package/lib/scrubber/config/defaults.d.ts +39 -46
  48. package/lib/scrubber/config/defaults.js +1 -0
  49. package/lib/scrubber/config/defaults.ts +50 -112
  50. package/lib/scrubber/errors/scrubber-error.d.ts +22 -0
  51. package/lib/scrubber/errors/scrubber-error.js +39 -0
  52. package/lib/scrubber/errors/scrubber-error.ts +44 -0
  53. package/lib/scrubber/index.d.ts +0 -1
  54. package/lib/scrubber/index.js +1 -0
  55. package/lib/scrubber/index.ts +1 -2
  56. package/lib/scrubber/scrubber.d.ts +14 -31
  57. package/lib/scrubber/scrubber.js +1 -0
  58. package/lib/scrubber/scrubber.ts +93 -152
  59. package/lib/scrubber/stages/chunker.d.ts +22 -10
  60. package/lib/scrubber/stages/chunker.js +86 -0
  61. package/lib/scrubber/stages/chunker.ts +104 -0
  62. package/lib/scrubber/stages/metadata-annotator.d.ts +14 -15
  63. package/lib/scrubber/stages/metadata-annotator.js +64 -0
  64. package/lib/scrubber/stages/metadata-annotator.ts +75 -0
  65. package/lib/scrubber/stages/normalizer.d.ts +13 -10
  66. package/lib/scrubber/stages/normalizer.js +51 -0
  67. package/lib/scrubber/stages/normalizer.ts +60 -0
  68. package/lib/scrubber/stages/semantic-filter.d.ts +13 -10
  69. package/lib/scrubber/stages/semantic-filter.js +51 -0
  70. package/lib/scrubber/stages/semantic-filter.ts +62 -0
  71. package/lib/scrubber/stages/structural-cleaner.d.ts +15 -10
  72. package/lib/scrubber/stages/structural-cleaner.js +73 -0
  73. package/lib/scrubber/stages/structural-cleaner.ts +83 -0
  74. package/lib/scrubber/stages/validator.d.ts +14 -15
  75. package/lib/scrubber/stages/validator.js +56 -0
  76. package/lib/scrubber/stages/validator.ts +67 -0
  77. package/lib/scrubber/telemetry.d.ts +20 -27
  78. package/lib/scrubber/telemetry.js +1 -0
  79. package/lib/scrubber/telemetry.ts +53 -90
  80. package/lib/scrubber/utils/hash.d.ts +14 -0
  81. package/lib/scrubber/utils/hash.js +37 -0
  82. package/lib/scrubber/utils/hash.ts +40 -0
  83. package/lib/scrubber/utils/html-parser.d.ts +14 -0
  84. package/lib/scrubber/utils/html-parser.js +38 -0
  85. package/lib/scrubber/utils/html-parser.ts +46 -0
  86. package/lib/scrubber/utils/pattern-matcher.d.ts +12 -0
  87. package/lib/scrubber/utils/pattern-matcher.js +54 -0
  88. package/lib/scrubber/utils/pattern-matcher.ts +64 -0
  89. package/lib/scrubber/utils/token-counter.d.ts +18 -0
  90. package/lib/scrubber/utils/token-counter.js +30 -0
  91. package/lib/scrubber/utils/token-counter.ts +32 -0
  92. package/lib/utils/logger.d.ts +1 -11
  93. package/lib/utils/logger.js +1 -0
  94. package/lib/utils/logger.ts +43 -63
  95. package/lib/utils/skill-metadata.d.ts +6 -14
  96. package/lib/utils/skill-metadata.js +1 -0
  97. package/lib/utils/skill-metadata.ts +89 -103
  98. package/lib/yamo/emitter.d.ts +8 -35
  99. package/lib/yamo/emitter.js +1 -0
  100. package/lib/yamo/emitter.ts +77 -155
  101. package/lib/yamo/index.d.ts +14 -0
  102. package/lib/yamo/index.js +14 -0
  103. package/lib/yamo/index.ts +16 -0
  104. package/lib/yamo/schema.d.ts +8 -10
  105. package/lib/yamo/schema.js +1 -0
  106. package/lib/yamo/schema.ts +82 -114
  107. package/package.json +4 -2
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * LanceDB Schema Definitions for MemoryManager
3
4
  * Uses Apache Arrow Schema format for LanceDB JavaScript SDK
@@ -7,197 +8,130 @@
7
8
  * - all-mpnet-base-v2: 768 dimensions
8
9
  * - text-embedding-3-small: 1536 dimensions
9
10
  */
10
-
11
11
  import * as arrow from "apache-arrow";
12
- import * as lancedb from "@lancedb/lancedb";
13
-
14
12
  /**
15
13
  * Default vector dimension (all-MiniLM-L6-v2)
16
14
  */
17
15
  export const DEFAULT_VECTOR_DIMENSION = 384;
18
-
19
16
  /**
20
17
  * Common embedding model dimensions
21
18
  */
22
- export const EMBEDDING_DIMENSIONS: Record<string, number> = {
23
- "Xenova/all-MiniLM-L6-v2": 384,
24
- "Xenova/all-mpnet-base-v2": 768,
25
- "Xenova/distiluse-base-multilingual-cased-v1": 512,
26
- "sentence-transformers/all-MiniLM-L6-v2": 384,
27
- "sentence-transformers/all-mpnet-base-v2": 768,
28
- "openai/text-embedding-3-small": 1536,
29
- "openai/text-embedding-3-large": 3072,
30
- "cohere/embed-english-light-v3.0": 1024,
31
- "cohere/embed-english-v3.0": 1024,
19
+ export const EMBEDDING_DIMENSIONS = {
20
+ "Xenova/all-MiniLM-L6-v2": 384,
21
+ "Xenova/all-mpnet-base-v2": 768,
22
+ "Xenova/distiluse-base-multilingual-cased-v1": 512,
23
+ "sentence-transformers/all-MiniLM-L6-v2": 384,
24
+ "sentence-transformers/all-mpnet-base-v2": 768,
25
+ "openai/text-embedding-3-small": 1536,
26
+ "openai/text-embedding-3-large": 3072,
27
+ "cohere/embed-english-light-v3.0": 1024,
28
+ "cohere/embed-english-v3.0": 1024,
32
29
  };
33
-
34
30
  /**
35
31
  * Get dimension for a given embedding model
36
32
  * @param {string} modelName - Embedding model name or path
37
33
  * @returns {number} Vector dimension
38
34
  */
39
- export function getEmbeddingDimension(modelName?: string): number {
40
- if (!modelName) {
41
- return DEFAULT_VECTOR_DIMENSION;
42
- }
43
-
44
- // Check exact match
45
- if (EMBEDDING_DIMENSIONS[modelName]) {
46
- return EMBEDDING_DIMENSIONS[modelName];
47
- }
48
-
49
- // Check for partial matches
50
- for (const [key, dimension] of Object.entries(EMBEDDING_DIMENSIONS)) {
51
- if (modelName.toLowerCase().includes(key.toLowerCase())) {
52
- return dimension;
35
+ export function getEmbeddingDimension(modelName) {
36
+ if (!modelName) {
37
+ return DEFAULT_VECTOR_DIMENSION;
38
+ }
39
+ // Check exact match
40
+ if (EMBEDDING_DIMENSIONS[modelName]) {
41
+ return EMBEDDING_DIMENSIONS[modelName];
53
42
  }
54
- }
55
-
56
- // Fallback to default
57
- return DEFAULT_VECTOR_DIMENSION;
43
+ // Check for partial matches
44
+ for (const [key, dimension] of Object.entries(EMBEDDING_DIMENSIONS)) {
45
+ if (modelName.toLowerCase().includes(key.toLowerCase())) {
46
+ return dimension;
47
+ }
48
+ }
49
+ // Fallback to default
50
+ return DEFAULT_VECTOR_DIMENSION;
58
51
  }
59
-
60
52
  /**
61
53
  * Create a memory schema with a specific vector dimension
62
54
  * @param {number} vectorDim - Vector dimension (e.g., 384, 768, 1536)
63
55
  * @returns {arrow.Schema} Arrow schema with specified dimension
64
56
  */
65
- export function createMemorySchema(
66
- vectorDim: number = DEFAULT_VECTOR_DIMENSION,
67
- ): arrow.Schema {
68
- return new arrow.Schema([
69
- new arrow.Field("id", new arrow.Utf8(), false),
70
- new arrow.Field(
71
- "vector",
72
- new arrow.FixedSizeList(
73
- vectorDim,
74
- new arrow.Field("item", new arrow.Float32(), true),
75
- ),
76
- false,
77
- ),
78
- new arrow.Field("content", new arrow.Utf8(), false),
79
- new arrow.Field("metadata", new arrow.Utf8(), true), // Stored as JSON string
80
- new arrow.Field(
81
- "created_at",
82
- new arrow.Timestamp(arrow.TimeUnit.MILLISECOND),
83
- false,
84
- ),
85
- new arrow.Field(
86
- "updated_at",
87
- new arrow.Timestamp(arrow.TimeUnit.MILLISECOND),
88
- true,
89
- ),
90
- ]);
57
+ export function createMemorySchema(vectorDim = DEFAULT_VECTOR_DIMENSION) {
58
+ return new arrow.Schema([
59
+ new arrow.Field("id", new arrow.Utf8(), false),
60
+ new arrow.Field("vector", new arrow.FixedSizeList(vectorDim, new arrow.Field("item", new arrow.Float32(), true)), false),
61
+ new arrow.Field("content", new arrow.Utf8(), false),
62
+ new arrow.Field("metadata", new arrow.Utf8(), true), // Stored as JSON string
63
+ new arrow.Field("created_at", new arrow.Timestamp(arrow.TimeUnit.MILLISECOND), false),
64
+ new arrow.Field("updated_at", new arrow.Timestamp(arrow.TimeUnit.MILLISECOND), true),
65
+ ]);
91
66
  }
92
-
93
67
  /**
94
68
  * Create V2 memory schema with automatic recall fields
95
69
  * All new fields are nullable for backward compatibility
96
70
  * @param {number} vectorDim - Vector dimension (e.g., 384, 768, 1536)
97
71
  * @returns {arrow.Schema} Arrow schema with V2 fields
98
72
  */
99
- export function createMemorySchemaV2(
100
- vectorDim: number = DEFAULT_VECTOR_DIMENSION,
101
- ): arrow.Schema {
102
- return new arrow.Schema([
103
- // ========== V1 Fields (Backward Compatible) ==========
104
- new arrow.Field("id", new arrow.Utf8(), false),
105
- new arrow.Field(
106
- "vector",
107
- new arrow.FixedSizeList(
108
- vectorDim,
109
- new arrow.Field("item", new arrow.Float32(), true),
110
- ),
111
- false,
112
- ),
113
- new arrow.Field("content", new arrow.Utf8(), false),
114
- new arrow.Field("metadata", new arrow.Utf8(), true),
115
- new arrow.Field(
116
- "created_at",
117
- new arrow.Timestamp(arrow.TimeUnit.MILLISECOND),
118
- false,
119
- ),
120
- new arrow.Field(
121
- "updated_at",
122
- new arrow.Timestamp(arrow.TimeUnit.MILLISECOND),
123
- true,
124
- ),
125
-
126
- // ========== V2 Fields (All Nullable) ==========
127
- new arrow.Field("session_id", new arrow.Utf8(), true), // Session association
128
- new arrow.Field("agent_id", new arrow.Utf8(), true), // Agent/skill that created memory
129
- new arrow.Field("memory_type", new arrow.Utf8(), true), // 'global', 'session', 'agent'
130
- new arrow.Field("importance_score", new arrow.Float32(), true), // 0.0-1.0 importance
131
- new arrow.Field("access_count", new arrow.Int32(), true), // Popularity tracking
132
- new arrow.Field(
133
- "last_accessed",
134
- new arrow.Timestamp(arrow.TimeUnit.MILLISECOND),
135
- true,
136
- ),
137
- ]);
73
+ export function createMemorySchemaV2(vectorDim = DEFAULT_VECTOR_DIMENSION) {
74
+ return new arrow.Schema([
75
+ // ========== V1 Fields (Backward Compatible) ==========
76
+ new arrow.Field("id", new arrow.Utf8(), false),
77
+ new arrow.Field("vector", new arrow.FixedSizeList(vectorDim, new arrow.Field("item", new arrow.Float32(), true)), false),
78
+ new arrow.Field("content", new arrow.Utf8(), false),
79
+ new arrow.Field("metadata", new arrow.Utf8(), true),
80
+ new arrow.Field("created_at", new arrow.Timestamp(arrow.TimeUnit.MILLISECOND), false),
81
+ new arrow.Field("updated_at", new arrow.Timestamp(arrow.TimeUnit.MILLISECOND), true),
82
+ // ========== V2 Fields (All Nullable) ==========
83
+ new arrow.Field("session_id", new arrow.Utf8(), true), // Session association
84
+ new arrow.Field("agent_id", new arrow.Utf8(), true), // Agent/skill that created memory
85
+ new arrow.Field("memory_type", new arrow.Utf8(), true), // 'global', 'session', 'agent'
86
+ new arrow.Field("importance_score", new arrow.Float32(), true), // 0.0-1.0 importance
87
+ new arrow.Field("access_count", new arrow.Int32(), true), // Popularity tracking
88
+ new arrow.Field("last_accessed", new arrow.Timestamp(arrow.TimeUnit.MILLISECOND), true),
89
+ ]);
138
90
  }
139
-
140
91
  /**
141
92
  * Create schema for synthesized skills (Recursive Skill Synthesis)
142
93
  * @param {number} vectorDim - Vector dimension for intent embedding
143
94
  * @returns {arrow.Schema} Arrow schema
144
95
  */
145
- export function createSynthesizedSkillSchema(
146
- vectorDim: number = DEFAULT_VECTOR_DIMENSION,
147
- ): arrow.Schema {
148
- return new arrow.Schema([
149
- new arrow.Field("id", new arrow.Utf8(), false),
150
- new arrow.Field("name", new arrow.Utf8(), false),
151
- new arrow.Field("intent", new arrow.Utf8(), false),
152
- new arrow.Field("yamo_text", new arrow.Utf8(), false),
153
- new arrow.Field(
154
- "vector",
155
- new arrow.FixedSizeList(
156
- vectorDim,
157
- new arrow.Field("item", new arrow.Float32(), true),
158
- ),
159
- false,
160
- ),
161
- new arrow.Field("metadata", new arrow.Utf8(), true), // Stored as JSON: {reliability, use_count, created_at}
162
- new arrow.Field(
163
- "created_at",
164
- new arrow.Timestamp(arrow.TimeUnit.MILLISECOND),
165
- false,
166
- ),
167
- ]);
96
+ export function createSynthesizedSkillSchema(vectorDim = DEFAULT_VECTOR_DIMENSION) {
97
+ return new arrow.Schema([
98
+ new arrow.Field("id", new arrow.Utf8(), false),
99
+ new arrow.Field("name", new arrow.Utf8(), false),
100
+ new arrow.Field("intent", new arrow.Utf8(), false),
101
+ new arrow.Field("yamo_text", new arrow.Utf8(), false),
102
+ new arrow.Field("vector", new arrow.FixedSizeList(vectorDim, new arrow.Field("item", new arrow.Float32(), true)), false),
103
+ new arrow.Field("metadata", new arrow.Utf8(), true), // Stored as JSON: {reliability, use_count, created_at}
104
+ new arrow.Field("created_at", new arrow.Timestamp(arrow.TimeUnit.MILLISECOND), false),
105
+ ]);
168
106
  }
169
-
170
107
  /**
171
108
  * Check if a table is using V2 schema
172
109
  * @param {arrow.Schema} schema - Table schema to check
173
110
  * @returns {boolean} True if V2 schema detected
174
111
  */
175
- export function isSchemaV2(schema: arrow.Schema): boolean {
176
- return schema.fields.some((f) => f.name === "session_id");
112
+ export function isSchemaV2(schema) {
113
+ return schema.fields.some((f) => f.name === "session_id");
177
114
  }
178
-
179
115
  /**
180
116
  * Memory table schema using Apache Arrow format (default 384 dimensions)
181
117
  * @deprecated Use createMemorySchema(vectorDim) for dynamic dimensions
182
118
  */
183
119
  export const MEMORY_SCHEMA = createMemorySchema(DEFAULT_VECTOR_DIMENSION);
184
-
185
120
  /**
186
121
  * Index configuration for memory table
187
122
  * Indices should be created after data is inserted
188
123
  */
189
124
  export const INDEX_CONFIG = {
190
- vector: {
191
- index_type: "ivf_pq",
192
- metric: "cosine",
193
- num_partitions: 256,
194
- num_sub_vectors: 8,
195
- },
196
- full_text: {
197
- fields: ["content"],
198
- },
125
+ vector: {
126
+ index_type: "ivf_pq",
127
+ metric: "cosine",
128
+ num_partitions: 256,
129
+ num_sub_vectors: 8,
130
+ },
131
+ full_text: {
132
+ fields: ["content"],
133
+ },
199
134
  };
200
-
201
135
  /**
202
136
  * Creates a memory table in LanceDB with the predefined schema (384 dimensions)
203
137
  * @param {lancedb.Connection} db - LanceDB connection
@@ -206,17 +140,9 @@ export const INDEX_CONFIG = {
206
140
  * @throws {Error} If table creation fails
207
141
  * @deprecated Use createMemoryTableWithDimension() for dynamic dimensions
208
142
  */
209
- export async function createMemoryTable(
210
- db: lancedb.Connection,
211
- tableName: string = "memory_entries",
212
- ): Promise<lancedb.Table> {
213
- return createMemoryTableWithDimension(
214
- db,
215
- tableName,
216
- DEFAULT_VECTOR_DIMENSION,
217
- );
143
+ export async function createMemoryTable(db, tableName = "memory_entries") {
144
+ return createMemoryTableWithDimension(db, tableName, DEFAULT_VECTOR_DIMENSION);
218
145
  }
219
-
220
146
  /**
221
147
  * Creates a memory table in LanceDB with a specific vector dimension
222
148
  * @param {lancedb.Connection} db - LanceDB connection
@@ -225,43 +151,34 @@ export async function createMemoryTable(
225
151
  * @returns {Promise<lancedb.Table>} The created or opened table
226
152
  * @throws {Error} If table creation fails
227
153
  */
228
- export async function createMemoryTableWithDimension(
229
- db: lancedb.Connection,
230
- tableName: string,
231
- vectorDim: number,
232
- ): Promise<lancedb.Table> {
233
- try {
234
- // Check if table already exists
235
- const existingTables = await db.tableNames();
236
-
237
- if (existingTables.includes(tableName)) {
238
- return await db.openTable(tableName);
154
+ export async function createMemoryTableWithDimension(db, tableName, vectorDim) {
155
+ try {
156
+ // Check if table already exists
157
+ const existingTables = await db.tableNames();
158
+ if (existingTables.includes(tableName)) {
159
+ return await db.openTable(tableName);
160
+ }
161
+ // Create schema with specified dimension
162
+ const schema = createMemorySchema(vectorDim);
163
+ // Create table with schema
164
+ // LanceDB v0.23.0+ accepts empty array as initial data with schema option
165
+ const table = await db.createTable(tableName, [], { schema }); // Cast to any because lancedb types might be strict about options
166
+ return table;
167
+ }
168
+ catch (error) {
169
+ const message = error instanceof Error ? error.message : String(error);
170
+ throw new Error(`Failed to create memory table with dimension ${vectorDim}: ${message}`);
239
171
  }
240
-
241
- // Create schema with specified dimension
242
- const schema = createMemorySchema(vectorDim);
243
-
244
- // Create table with schema
245
- // LanceDB v0.23.0+ accepts empty array as initial data with schema option
246
- const table = await db.createTable(tableName, [], { schema } as any); // Cast to any because lancedb types might be strict about options
247
- return table;
248
- } catch (error) {
249
- const message = error instanceof Error ? error.message : String(error);
250
- throw new Error(
251
- `Failed to create memory table with dimension ${vectorDim}: ${message}`,
252
- );
253
- }
254
172
  }
255
-
256
173
  export default {
257
- MEMORY_SCHEMA,
258
- INDEX_CONFIG,
259
- createMemoryTable,
260
- createMemoryTableWithDimension,
261
- createMemorySchema,
262
- createMemorySchemaV2,
263
- isSchemaV2,
264
- getEmbeddingDimension,
265
- DEFAULT_VECTOR_DIMENSION,
266
- EMBEDDING_DIMENSIONS,
174
+ MEMORY_SCHEMA,
175
+ INDEX_CONFIG,
176
+ createMemoryTable,
177
+ createMemoryTableWithDimension,
178
+ createMemorySchema,
179
+ createMemorySchemaV2,
180
+ isSchemaV2,
181
+ getEmbeddingDimension,
182
+ DEFAULT_VECTOR_DIMENSION,
183
+ EMBEDDING_DIMENSIONS,
267
184
  };
@@ -1,26 +1,25 @@
1
1
  /**
2
2
  * MemoryScorer - Calculate memory importance and detect duplicates
3
3
  */
4
- import { MemoryMesh } from "./memory-mesh.js";
5
4
  export declare class MemoryScorer {
6
5
  #private;
7
6
  /**
8
7
  * @param {MemoryMesh} mesh - MemoryMesh instance for duplicate checking
9
8
  */
10
- constructor(mesh: MemoryMesh);
9
+ constructor(mesh: any);
11
10
  /**
12
11
  * Calculate importance score for content
13
12
  * @param {string} content - Content to score
14
13
  * @param {Object} metadata - Associated metadata
15
14
  * @returns {Promise<number>} Importance score (0-1)
16
15
  */
17
- calculateImportance(content: string, metadata?: any): number;
16
+ calculateImportance(content: any, metadata?: {}): number;
18
17
  /**
19
18
  * Check if content is duplicate of existing memory
20
19
  * @param {string} content - Content to check
21
20
  * @param {number} threshold - Similarity threshold (default 0.9)
22
21
  * @returns {Promise<boolean>} True if duplicate exists
23
22
  */
24
- isDuplicate(content: string, threshold?: number): Promise<boolean>;
23
+ isDuplicate(content: any, threshold?: number): Promise<boolean>;
25
24
  }
26
25
  export default MemoryScorer;
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * MemoryScorer - Calculate memory importance and detect duplicates
3
4
  */
@@ -1,95 +1,78 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * MemoryScorer - Calculate memory importance and detect duplicates
3
4
  */
4
-
5
- import { MemoryMesh } from "./memory-mesh.js";
6
-
7
5
  export class MemoryScorer {
8
- #mesh: MemoryMesh;
9
-
10
- /**
11
- * @param {MemoryMesh} mesh - MemoryMesh instance for duplicate checking
12
- */
13
- constructor(mesh: MemoryMesh) {
14
- this.#mesh = mesh;
15
- }
16
-
17
- /**
18
- * Calculate importance score for content
19
- * @param {string} content - Content to score
20
- * @param {Object} metadata - Associated metadata
21
- * @returns {Promise<number>} Importance score (0-1)
22
- */
23
- calculateImportance(content: string, metadata: any = {}): number {
24
- let score = 0;
25
-
26
- // Content length (longer = more important, up to a point)
27
- const length = content.length;
28
- score += Math.min(length / 1000, 0.2);
29
-
30
- // Has structured data (JSON, code blocks)
31
- if (content.includes("```") || content.includes("{")) {
32
- score += 0.1;
6
+ #mesh;
7
+ /**
8
+ * @param {MemoryMesh} mesh - MemoryMesh instance for duplicate checking
9
+ */
10
+ constructor(mesh) {
11
+ this.#mesh = mesh;
33
12
  }
34
-
35
- // Interaction type bonuses
36
- if (metadata.interaction_type === "tool_execution") {
37
- score += 0.15;
13
+ /**
14
+ * Calculate importance score for content
15
+ * @param {string} content - Content to score
16
+ * @param {Object} metadata - Associated metadata
17
+ * @returns {Promise<number>} Importance score (0-1)
18
+ */
19
+ calculateImportance(content, metadata = {}) {
20
+ let score = 0;
21
+ // Content length (longer = more important, up to a point)
22
+ const length = content.length;
23
+ score += Math.min(length / 1000, 0.2);
24
+ // Has structured data (JSON, code blocks)
25
+ if (content.includes("```") || content.includes("{")) {
26
+ score += 0.1;
27
+ }
28
+ // Interaction type bonuses
29
+ if (metadata.interaction_type === "tool_execution") {
30
+ score += 0.15;
31
+ }
32
+ if (metadata.interaction_type === "file_operation") {
33
+ score += 0.1;
34
+ }
35
+ // Tool usage indicates importance
36
+ if (metadata.tools_used?.length > 0) {
37
+ score += Math.min(metadata.tools_used.length * 0.05, 0.15);
38
+ }
39
+ // File involvement
40
+ if (metadata.files_involved?.length > 0) {
41
+ score += Math.min(metadata.files_involved.length * 0.05, 0.15);
42
+ }
43
+ // Keywords that indicate importance
44
+ const importantKeywords = [
45
+ "error",
46
+ "bug",
47
+ "fix",
48
+ "important",
49
+ "critical",
50
+ "note",
51
+ "remember",
52
+ ];
53
+ const lowerContent = content.toLowerCase();
54
+ const keywordMatches = importantKeywords.filter((k) => lowerContent.includes(k)).length;
55
+ score += Math.min(keywordMatches * 0.05, 0.15);
56
+ return Math.min(score, 1.0);
38
57
  }
39
- if (metadata.interaction_type === "file_operation") {
40
- score += 0.1;
58
+ /**
59
+ * Check if content is duplicate of existing memory
60
+ * @param {string} content - Content to check
61
+ * @param {number} threshold - Similarity threshold (default 0.9)
62
+ * @returns {Promise<boolean>} True if duplicate exists
63
+ */
64
+ async isDuplicate(content, threshold = 0.9) {
65
+ try {
66
+ const results = await this.#mesh.search(content, {
67
+ limit: 1,
68
+ useCache: false,
69
+ });
70
+ return results.length > 0 && results[0].score >= threshold;
71
+ }
72
+ catch (_error) {
73
+ // On error, assume not duplicate to allow storage
74
+ return false;
75
+ }
41
76
  }
42
-
43
- // Tool usage indicates importance
44
- if (metadata.tools_used?.length > 0) {
45
- score += Math.min(metadata.tools_used.length * 0.05, 0.15);
46
- }
47
-
48
- // File involvement
49
- if (metadata.files_involved?.length > 0) {
50
- score += Math.min(metadata.files_involved.length * 0.05, 0.15);
51
- }
52
-
53
- // Keywords that indicate importance
54
- const importantKeywords = [
55
- "error",
56
- "bug",
57
- "fix",
58
- "important",
59
- "critical",
60
- "note",
61
- "remember",
62
- ];
63
- const lowerContent = content.toLowerCase();
64
- const keywordMatches = importantKeywords.filter((k) =>
65
- lowerContent.includes(k),
66
- ).length;
67
- score += Math.min(keywordMatches * 0.05, 0.15);
68
-
69
- return Math.min(score, 1.0);
70
- }
71
-
72
- /**
73
- * Check if content is duplicate of existing memory
74
- * @param {string} content - Content to check
75
- * @param {number} threshold - Similarity threshold (default 0.9)
76
- * @returns {Promise<boolean>} True if duplicate exists
77
- */
78
- async isDuplicate(
79
- content: string,
80
- threshold: number = 0.9,
81
- ): Promise<boolean> {
82
- try {
83
- const results = await this.#mesh.search(content, {
84
- limit: 1,
85
- useCache: false,
86
- });
87
- return results.length > 0 && results[0].score >= threshold;
88
- } catch (_error) {
89
- // On error, assume not duplicate to allow storage
90
- return false;
91
- }
92
- }
93
77
  }
94
-
95
78
  export default MemoryScorer;
@@ -1 +1,2 @@
1
+ // @ts-nocheck
1
2
  export { KeywordSearch } from "./keyword-search.js";
@@ -1 +1,2 @@
1
+ // @ts-nocheck
1
2
  export { KeywordSearch } from "./keyword-search.js";
@@ -2,43 +2,31 @@
2
2
  * Simple Keyword Search Engine (In-Memory)
3
3
  * Provides basic TF-IDF style retrieval to complement vector search
4
4
  */
5
- export interface KeywordDoc {
6
- content: string;
7
- metadata?: any;
8
- }
9
- export interface KeywordSearchResult extends KeywordDoc {
10
- id: string;
11
- score: number;
12
- matches: string[];
13
- }
14
- export interface SearchOptions {
15
- limit?: number;
16
- }
17
5
  export declare class KeywordSearch {
18
- index: Map<string, Map<string, number>>;
19
- docLengths: Map<string, number>;
20
- idf: Map<string, number>;
21
- docs: Map<string, KeywordDoc>;
22
- isDirty: boolean;
6
+ index: any;
7
+ docLengths: any;
8
+ idf: any;
9
+ docs: any;
10
+ isDirty: any;
23
11
  constructor();
24
12
  /**
25
13
  * Tokenize text into normalized terms
26
14
  * @param {string} text
27
15
  * @returns {string[]} tokens
28
16
  */
29
- tokenize(text: string): string[];
17
+ tokenize(text: any): any;
30
18
  /**
31
19
  * Add a document to the index
32
20
  * @param {string} id
33
21
  * @param {string} content
34
22
  * @param {Object} [metadata]
35
23
  */
36
- add(id: string, content: string, metadata?: any): void;
24
+ add(id: any, content: any, metadata?: {}): void;
37
25
  /**
38
26
  * Remove a document
39
27
  * @param {string} id
40
28
  */
41
- remove(id: string): void;
29
+ remove(id: any): void;
42
30
  /**
43
31
  * Recalculate IDF scores
44
32
  */
@@ -49,14 +37,10 @@ export declare class KeywordSearch {
49
37
  * @param {Object} options
50
38
  * @returns {Array<{id: string, score: number, matches: string[], content: string, metadata: Object}>}
51
39
  */
52
- search(query: string, options?: SearchOptions): KeywordSearchResult[];
40
+ search(query: any, options?: {}): any[];
53
41
  /**
54
42
  * Bulk load records
55
43
  * @param {Array} records
56
44
  */
57
- load(records: {
58
- id: string;
59
- content: string;
60
- metadata?: any;
61
- }[]): void;
45
+ load(records: any): void;
62
46
  }
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Simple Keyword Search Engine (In-Memory)
3
4
  * Provides basic TF-IDF style retrieval to complement vector search