memories-lite 0.99.1 → 0.99.3
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/dist/config/defaults.js +5 -19
- package/dist/config/manager.js +1 -6
- package/dist/memory/index.d.ts +2 -4
- package/dist/memory/index.js +16 -47
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/index.js +2 -2
- package/dist/types/index.d.ts +12 -97
- package/dist/types/index.js +2 -19
- package/dist/vectorstores/lite.d.ts +1 -0
- package/dist/vectorstores/lite.js +11 -6
- package/memories-lite-a42ac5108869b599bcbac21069f63fb47f07452fcc4b87e89b3c06a945612d0b.db +0 -0
- package/memories-lite-a9137698d8d3fdbf27efcdc8cd372084b52d484e8db866c5455bbb3f85299b54.db +0 -0
- package/package.json +1 -1
- package/src/config/defaults.ts +5 -19
- package/src/config/manager.ts +1 -6
- package/src/memory/index.ts +25 -57
- package/src/prompts/index.ts +2 -2
- package/src/types/index.ts +4 -35
- package/src/vectorstores/lite.ts +13 -7
- package/tests/init.mem.ts +7 -4
- package/tests/lite.spec.ts +16 -16
- package/tests/memory.discussion.search.test.ts +377 -0
package/dist/config/defaults.js
CHANGED
|
@@ -7,18 +7,17 @@ const DEFAULT_SCORING_CONFIG = {
|
|
|
7
7
|
assistant_preference: { alpha: 0.60, beta: 0.05, gamma: 0.35, halfLifeDays: Infinity },
|
|
8
8
|
//
|
|
9
9
|
// discussion: mémoires de discussions (synthèses opérationnelles)
|
|
10
|
-
// - alpha=
|
|
11
|
-
// - beta=
|
|
10
|
+
// - alpha=1: score basé uniquement sur la similarité cosinus
|
|
11
|
+
// - beta=0: pas de recency
|
|
12
12
|
// - gamma=0: pas d'importance base
|
|
13
|
-
discussion: { alpha:
|
|
13
|
+
discussion: { alpha: 1, beta: 0, gamma: 0, halfLifeDays: Infinity },
|
|
14
14
|
//
|
|
15
15
|
// default: fallback si type manquant ou inconnu
|
|
16
16
|
default: { alpha: 0.5, beta: 0.3, gamma: 0.1, halfLifeDays: 30 }
|
|
17
17
|
};
|
|
18
18
|
exports.DEFAULT_MEMORY_CONFIG = {
|
|
19
19
|
disableHistory: true,
|
|
20
|
-
|
|
21
|
-
version: "v1.1",
|
|
20
|
+
version: "v2.0",
|
|
22
21
|
embedder: {
|
|
23
22
|
provider: "openai",
|
|
24
23
|
config: {
|
|
@@ -33,6 +32,7 @@ exports.DEFAULT_MEMORY_CONFIG = {
|
|
|
33
32
|
collectionName: "memories",
|
|
34
33
|
dimension: 768,
|
|
35
34
|
scoring: DEFAULT_SCORING_CONFIG,
|
|
35
|
+
searchThreshold: 0.50, // Seuil minimum de score pour retourner un résultat
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
38
|
llm: {
|
|
@@ -43,20 +43,6 @@ exports.DEFAULT_MEMORY_CONFIG = {
|
|
|
43
43
|
modelProperties: undefined,
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
|
-
graphStore: {
|
|
47
|
-
provider: "neo4j",
|
|
48
|
-
config: {
|
|
49
|
-
url: process.env.NEO4J_URL || "neo4j://localhost:7687",
|
|
50
|
-
username: process.env.NEO4J_USERNAME || "neo4j",
|
|
51
|
-
password: process.env.NEO4J_PASSWORD || "password",
|
|
52
|
-
},
|
|
53
|
-
llm: {
|
|
54
|
-
provider: "openai",
|
|
55
|
-
config: {
|
|
56
|
-
model: "gpt-5-mini",
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
46
|
historyStore: {
|
|
61
47
|
provider: "dummy",
|
|
62
48
|
config: {
|
package/dist/config/manager.js
CHANGED
|
@@ -96,17 +96,12 @@ class ConfigManager {
|
|
|
96
96
|
})(),
|
|
97
97
|
},
|
|
98
98
|
historyDbPath: userConfig.historyDbPath || defaults_1.DEFAULT_MEMORY_CONFIG.historyDbPath,
|
|
99
|
-
|
|
100
|
-
graphStore: {
|
|
101
|
-
...defaults_1.DEFAULT_MEMORY_CONFIG.graphStore,
|
|
102
|
-
...userConfig.graphStore,
|
|
103
|
-
},
|
|
99
|
+
capturePrompt: userConfig.capturePrompt,
|
|
104
100
|
historyStore: {
|
|
105
101
|
...defaults_1.DEFAULT_MEMORY_CONFIG.historyStore,
|
|
106
102
|
...userConfig.historyStore,
|
|
107
103
|
},
|
|
108
104
|
disableHistory: userConfig.disableHistory || defaults_1.DEFAULT_MEMORY_CONFIG.disableHistory,
|
|
109
|
-
enableGraph: userConfig.enableGraph || defaults_1.DEFAULT_MEMORY_CONFIG.enableGraph,
|
|
110
105
|
};
|
|
111
106
|
// Validate the merged config
|
|
112
107
|
return types_1.MemoryConfigSchema.parse(mergedConfig);
|
package/dist/memory/index.d.ts
CHANGED
|
@@ -3,15 +3,13 @@ import { VectorStore } from "../vectorstores/base";
|
|
|
3
3
|
import { AddMemoryOptions, SearchMemoryOptions, DeleteAllMemoryOptions, GetAllMemoryOptions } from "./memory.types";
|
|
4
4
|
export declare class MemoriesLite {
|
|
5
5
|
private config;
|
|
6
|
-
private
|
|
6
|
+
private capturePrompt;
|
|
7
7
|
private embedder;
|
|
8
8
|
private vectorStoreConfig;
|
|
9
9
|
private llm;
|
|
10
10
|
private db;
|
|
11
11
|
private collectionName;
|
|
12
12
|
private apiVersion;
|
|
13
|
-
private graphMemory?;
|
|
14
|
-
private enableGraph;
|
|
15
13
|
telemetryId: string;
|
|
16
14
|
constructor(config?: Partial<MemoryConfig>);
|
|
17
15
|
private _initializeTelemetry;
|
|
@@ -35,7 +33,7 @@ export declare class MemoriesLite {
|
|
|
35
33
|
capture(messages: string | Message[], userId: string, config: AddMemoryOptions): Promise<SearchResult>;
|
|
36
34
|
get(memoryId: string, userId: string): Promise<MemoryItem | null>;
|
|
37
35
|
retrieve(query: string, userId: string, config: SearchMemoryOptions): Promise<SearchResult>;
|
|
38
|
-
update(memoryId: string, data: string, userId: string): Promise<{
|
|
36
|
+
update(memoryId: string, data: string, userId: string, metadata?: Record<string, any>): Promise<{
|
|
39
37
|
message: string;
|
|
40
38
|
}>;
|
|
41
39
|
delete(memoryId: string, userId: string): Promise<{
|
package/dist/memory/index.js
CHANGED
|
@@ -16,7 +16,7 @@ class MemoriesLite {
|
|
|
16
16
|
constructor(config = {}) {
|
|
17
17
|
// Merge and validate config
|
|
18
18
|
this.config = manager_1.ConfigManager.mergeConfig(config);
|
|
19
|
-
this.
|
|
19
|
+
this.capturePrompt = this.config.capturePrompt;
|
|
20
20
|
this.embedder = factory_1.EmbedderFactory.create(this.config.embedder.provider, this.config.embedder.config);
|
|
21
21
|
//
|
|
22
22
|
// vectorStore.provider is "lite"
|
|
@@ -39,12 +39,7 @@ class MemoriesLite {
|
|
|
39
39
|
}
|
|
40
40
|
this.collectionName = this.config.vectorStore.config.collectionName;
|
|
41
41
|
this.apiVersion = this.config.version || "v1.0";
|
|
42
|
-
this.enableGraph = this.config.enableGraph || false;
|
|
43
42
|
this.telemetryId = "anonymous";
|
|
44
|
-
// Initialize graph memory if configured
|
|
45
|
-
if (this.enableGraph && this.config.graphStore) {
|
|
46
|
-
// this.graphMemory = new MemoryGraph(this.config);
|
|
47
|
-
}
|
|
48
43
|
// Initialize telemetry if vector store is initialized
|
|
49
44
|
// this._initializeTelemetry();
|
|
50
45
|
}
|
|
@@ -56,7 +51,6 @@ class MemoriesLite {
|
|
|
56
51
|
api_version: this.apiVersion,
|
|
57
52
|
client_type: "Memory",
|
|
58
53
|
collection_name: this.collectionName,
|
|
59
|
-
enable_graph: this.enableGraph,
|
|
60
54
|
});
|
|
61
55
|
}
|
|
62
56
|
catch (error) { }
|
|
@@ -108,7 +102,7 @@ class MemoriesLite {
|
|
|
108
102
|
.join("\n\n");
|
|
109
103
|
//
|
|
110
104
|
// Générer la synthèse via LLM
|
|
111
|
-
const [systemPrompt, userPrompt] = (0, prompts_1.getDiscussionSynthesisMessages)(parsedMessages, capturePrompt || this.
|
|
105
|
+
const [systemPrompt, userPrompt] = (0, prompts_1.getDiscussionSynthesisMessages)(parsedMessages, capturePrompt || this.capturePrompt);
|
|
112
106
|
const response = await this.llm.generateResponse([
|
|
113
107
|
{ role: "system", content: systemPrompt },
|
|
114
108
|
{ role: "user", content: userPrompt },
|
|
@@ -134,8 +128,8 @@ class MemoriesLite {
|
|
|
134
128
|
return [];
|
|
135
129
|
}
|
|
136
130
|
//
|
|
137
|
-
// Créer l'embedding sur le
|
|
138
|
-
const embedding = await this.embedder.embed(
|
|
131
|
+
// Créer l'embedding sur le title seul (TEST COMPARATIF)
|
|
132
|
+
const embedding = await this.embedder.embed(title);
|
|
139
133
|
//
|
|
140
134
|
// Préparer les métadonnées
|
|
141
135
|
const memoryType = metadata.type || 'discussion';
|
|
@@ -192,20 +186,8 @@ class MemoriesLite {
|
|
|
192
186
|
//
|
|
193
187
|
// Générer synthèse et stocker
|
|
194
188
|
const vectorStoreResult = await this.addToVectorStore(final_parsedMessages, metadata, userId, filters, capturePrompt);
|
|
195
|
-
//
|
|
196
|
-
// Graph store (si configuré)
|
|
197
|
-
let graphResult;
|
|
198
|
-
if (this.graphMemory) {
|
|
199
|
-
try {
|
|
200
|
-
graphResult = await this.graphMemory.add(final_parsedMessages.map((m) => m.content).join("\n"), filters);
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
console.error("Error adding to graph memory:", error);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
189
|
return {
|
|
207
190
|
results: vectorStoreResult,
|
|
208
|
-
relations: graphResult?.relations,
|
|
209
191
|
};
|
|
210
192
|
}
|
|
211
193
|
async get(memoryId, userId) {
|
|
@@ -262,16 +244,6 @@ class MemoriesLite {
|
|
|
262
244
|
// Search vector store
|
|
263
245
|
const queryEmbedding = await this.embedder.embed(query);
|
|
264
246
|
const memories = await vectorStore.search(queryEmbedding, limit, filters);
|
|
265
|
-
// Search graph store if available
|
|
266
|
-
let graphResults = [];
|
|
267
|
-
if (this.graphMemory) {
|
|
268
|
-
try {
|
|
269
|
-
graphResults = await this.graphMemory.search(query, filters);
|
|
270
|
-
}
|
|
271
|
-
catch (error) {
|
|
272
|
-
console.error("Error searching graph memory:", error);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
247
|
const excludedKeys = new Set([
|
|
276
248
|
"userId",
|
|
277
249
|
"agentId",
|
|
@@ -297,13 +269,12 @@ class MemoriesLite {
|
|
|
297
269
|
}));
|
|
298
270
|
return {
|
|
299
271
|
results,
|
|
300
|
-
relations: graphResults,
|
|
301
272
|
};
|
|
302
273
|
}
|
|
303
|
-
async update(memoryId, data, userId) {
|
|
274
|
+
async update(memoryId, data, userId, metadata = {}) {
|
|
304
275
|
// await this._captureEvent("update", { memory_id: memoryId });
|
|
305
276
|
const embedding = await this.embedder.embed(data);
|
|
306
|
-
await this.updateMemory(memoryId, data, { [data]: embedding },
|
|
277
|
+
await this.updateMemory(memoryId, data, { [data]: embedding }, metadata, userId);
|
|
307
278
|
return { message: "Memory updated successfully!" };
|
|
308
279
|
}
|
|
309
280
|
async delete(memoryId, userId) {
|
|
@@ -346,9 +317,6 @@ class MemoriesLite {
|
|
|
346
317
|
await this.db.reset();
|
|
347
318
|
// Check provider before attempting deleteCol
|
|
348
319
|
await vectorStore.deleteCol();
|
|
349
|
-
if (this.graphMemory) {
|
|
350
|
-
await this.graphMemory.deleteAll({ userId: "default" }); // Assuming this is okay, or needs similar check?
|
|
351
|
-
}
|
|
352
320
|
// Re-initialize factories/clients based on the original config
|
|
353
321
|
this.embedder = factory_1.EmbedderFactory.create(this.config.embedder.provider, this.config.embedder.config);
|
|
354
322
|
this.llm = factory_1.LLMFactory.create(this.config.llm.provider, this.config.llm.config);
|
|
@@ -420,20 +388,21 @@ class MemoriesLite {
|
|
|
420
388
|
throw new Error(`Memory with ID ${memoryId} not found`);
|
|
421
389
|
}
|
|
422
390
|
const prevValue = existingMemory.payload.data;
|
|
391
|
+
const originalPayload = (existingMemory.payload ?? {});
|
|
423
392
|
const embedding = existingEmbeddings[data] || (await this.embedder.embed(data));
|
|
393
|
+
//
|
|
394
|
+
// Preserve origin fields to avoid corrupting ownership/linkage (discussionId/userId/agentId).
|
|
395
|
+
// - title: keep original unless explicitly changed
|
|
396
|
+
// - discussionId, userId, agentId/runId: always keep original
|
|
397
|
+
const title = (typeof metadata.title === "string" && metadata.title.trim())
|
|
398
|
+
? metadata.title.trim()
|
|
399
|
+
: originalPayload.title;
|
|
424
400
|
const newMetadata = {
|
|
425
|
-
...
|
|
401
|
+
...originalPayload,
|
|
426
402
|
data,
|
|
427
403
|
hash: (0, crypto_1.createHash)("md5").update(data).digest("hex"),
|
|
428
|
-
type: existingMemory.payload.type,
|
|
429
|
-
createdAt: existingMemory.payload.createdAt,
|
|
430
404
|
updatedAt: new Date().toISOString(),
|
|
431
|
-
|
|
432
|
-
agentId: existingMemory.payload.agentId,
|
|
433
|
-
}),
|
|
434
|
-
...(existingMemory.payload.runId && {
|
|
435
|
-
runId: existingMemory.payload.runId,
|
|
436
|
-
}),
|
|
405
|
+
title: title,
|
|
437
406
|
};
|
|
438
407
|
await vectorStore.update(memoryId, embedding, newMetadata);
|
|
439
408
|
await this.db.addHistory(memoryId, prevValue, data, "UPDATE", newMetadata.createdAt, newMetadata.updatedAt);
|
package/dist/prompts/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const DiscussionSynthesisSchema: z.ZodObject<{
|
|
|
18
18
|
* Prompt par défaut pour la synthèse de discussion
|
|
19
19
|
* Peut être remplacé via capturePrompt dans AddMemoryOptions
|
|
20
20
|
*/
|
|
21
|
-
export declare const DEFAULT_DISCUSSION_PROMPT = "Tu es un expert en synth\u00E8se op\u00E9rationnelle.\n\n\u00C0 partir de cette discussion, g\u00E9n\u00E8re :\n1. TITRE: Un titre court et descriptif (
|
|
21
|
+
export declare const DEFAULT_DISCUSSION_PROMPT = "Tu es un expert en synth\u00E8se op\u00E9rationnelle.\n\n\u00C0 partir de cette discussion, g\u00E9n\u00E8re :\n1. TITRE: Un titre court et descriptif (10-20 mots) qui capture l'essence de la demande\n2. SUMMARY: Les points cl\u00E9s du chemin de r\u00E9solution en markdown (max 150 mots)\n\nCette synth\u00E8se servira \u00E0 retrouver et r\u00E9appliquer ce pattern de r\u00E9solution similaire.\nUtilise la m\u00EAme langue que la discussion.\n\nDiscussion \u00E0 synth\u00E9tiser:\n";
|
|
22
22
|
/**
|
|
23
23
|
* Génère les messages pour la synthèse de discussion
|
|
24
24
|
* @param discussion - Contenu de la discussion formatée
|
package/dist/prompts/index.js
CHANGED
|
@@ -25,8 +25,8 @@ exports.DiscussionSynthesisSchema = zod_1.z.object({
|
|
|
25
25
|
exports.DEFAULT_DISCUSSION_PROMPT = `Tu es un expert en synthèse opérationnelle.
|
|
26
26
|
|
|
27
27
|
À partir de cette discussion, génère :
|
|
28
|
-
1. TITRE: Un titre court et descriptif (
|
|
29
|
-
2. SUMMARY: Les points clés du chemin de résolution (
|
|
28
|
+
1. TITRE: Un titre court et descriptif (10-20 mots) qui capture l'essence de la demande
|
|
29
|
+
2. SUMMARY: Les points clés du chemin de résolution en markdown (max 150 mots)
|
|
30
30
|
|
|
31
31
|
Cette synthèse servira à retrouver et réappliquer ce pattern de résolution similaire.
|
|
32
32
|
Utilise la même langue que la discussion.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export interface VectorStoreConfig {
|
|
|
26
26
|
cacheTtl?: number;
|
|
27
27
|
scoring?: MemoryScoringConfig;
|
|
28
28
|
recencyCleanupThreshold?: number;
|
|
29
|
+
searchThreshold?: number;
|
|
29
30
|
[key: string]: any;
|
|
30
31
|
}
|
|
31
32
|
export interface HistoryStoreConfig {
|
|
@@ -44,17 +45,6 @@ export interface LLMConfig {
|
|
|
44
45
|
model?: string | any;
|
|
45
46
|
modelProperties?: Record<string, any>;
|
|
46
47
|
}
|
|
47
|
-
export interface Neo4jConfig {
|
|
48
|
-
url: string;
|
|
49
|
-
username: string;
|
|
50
|
-
password: string;
|
|
51
|
-
}
|
|
52
|
-
export interface GraphStoreConfig {
|
|
53
|
-
provider: string;
|
|
54
|
-
config: Neo4jConfig;
|
|
55
|
-
llm?: LLMConfig;
|
|
56
|
-
customPrompt?: string;
|
|
57
|
-
}
|
|
58
48
|
export interface MemoryTypeConfig {
|
|
59
49
|
alpha: number;
|
|
60
50
|
beta: number;
|
|
@@ -84,9 +74,7 @@ export interface MemoryConfig {
|
|
|
84
74
|
historyStore?: HistoryStoreConfig;
|
|
85
75
|
disableHistory?: boolean;
|
|
86
76
|
historyDbPath?: string;
|
|
87
|
-
|
|
88
|
-
graphStore?: GraphStoreConfig;
|
|
89
|
-
enableGraph?: boolean;
|
|
77
|
+
capturePrompt?: string;
|
|
90
78
|
}
|
|
91
79
|
export type MemoryType = 'assistant_preference' | 'discussion';
|
|
92
80
|
export interface MemoryItem {
|
|
@@ -256,6 +244,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
256
244
|
};
|
|
257
245
|
}>>;
|
|
258
246
|
recencyCleanupThreshold: z.ZodOptional<z.ZodNumber>;
|
|
247
|
+
searchThreshold: z.ZodOptional<z.ZodNumber>;
|
|
259
248
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
260
249
|
collectionName: z.ZodOptional<z.ZodString>;
|
|
261
250
|
dimension: z.ZodOptional<z.ZodNumber>;
|
|
@@ -349,6 +338,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
349
338
|
};
|
|
350
339
|
}>>;
|
|
351
340
|
recencyCleanupThreshold: z.ZodOptional<z.ZodNumber>;
|
|
341
|
+
searchThreshold: z.ZodOptional<z.ZodNumber>;
|
|
352
342
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
353
343
|
collectionName: z.ZodOptional<z.ZodString>;
|
|
354
344
|
dimension: z.ZodOptional<z.ZodNumber>;
|
|
@@ -442,6 +432,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
442
432
|
};
|
|
443
433
|
}>>;
|
|
444
434
|
recencyCleanupThreshold: z.ZodOptional<z.ZodNumber>;
|
|
435
|
+
searchThreshold: z.ZodOptional<z.ZodNumber>;
|
|
445
436
|
}, z.ZodTypeAny, "passthrough">>;
|
|
446
437
|
}, "strip", z.ZodTypeAny, {
|
|
447
438
|
provider: string;
|
|
@@ -470,6 +461,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
470
461
|
};
|
|
471
462
|
} | undefined;
|
|
472
463
|
recencyCleanupThreshold?: number | undefined;
|
|
464
|
+
searchThreshold?: number | undefined;
|
|
473
465
|
} & {
|
|
474
466
|
[k: string]: unknown;
|
|
475
467
|
};
|
|
@@ -500,6 +492,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
500
492
|
};
|
|
501
493
|
} | undefined;
|
|
502
494
|
recencyCleanupThreshold?: number | undefined;
|
|
495
|
+
searchThreshold?: number | undefined;
|
|
503
496
|
} & {
|
|
504
497
|
[k: string]: unknown;
|
|
505
498
|
};
|
|
@@ -535,59 +528,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
535
528
|
};
|
|
536
529
|
}>;
|
|
537
530
|
historyDbPath: z.ZodOptional<z.ZodString>;
|
|
538
|
-
|
|
539
|
-
enableGraph: z.ZodOptional<z.ZodBoolean>;
|
|
540
|
-
graphStore: z.ZodOptional<z.ZodObject<{
|
|
541
|
-
provider: z.ZodString;
|
|
542
|
-
config: z.ZodObject<{
|
|
543
|
-
url: z.ZodString;
|
|
544
|
-
username: z.ZodString;
|
|
545
|
-
password: z.ZodString;
|
|
546
|
-
}, "strip", z.ZodTypeAny, {
|
|
547
|
-
url: string;
|
|
548
|
-
username: string;
|
|
549
|
-
password: string;
|
|
550
|
-
}, {
|
|
551
|
-
url: string;
|
|
552
|
-
username: string;
|
|
553
|
-
password: string;
|
|
554
|
-
}>;
|
|
555
|
-
llm: z.ZodOptional<z.ZodObject<{
|
|
556
|
-
provider: z.ZodString;
|
|
557
|
-
config: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
558
|
-
}, "strip", z.ZodTypeAny, {
|
|
559
|
-
provider: string;
|
|
560
|
-
config: Record<string, any>;
|
|
561
|
-
}, {
|
|
562
|
-
provider: string;
|
|
563
|
-
config: Record<string, any>;
|
|
564
|
-
}>>;
|
|
565
|
-
customPrompt: z.ZodOptional<z.ZodString>;
|
|
566
|
-
}, "strip", z.ZodTypeAny, {
|
|
567
|
-
provider: string;
|
|
568
|
-
config: {
|
|
569
|
-
url: string;
|
|
570
|
-
username: string;
|
|
571
|
-
password: string;
|
|
572
|
-
};
|
|
573
|
-
llm?: {
|
|
574
|
-
provider: string;
|
|
575
|
-
config: Record<string, any>;
|
|
576
|
-
} | undefined;
|
|
577
|
-
customPrompt?: string | undefined;
|
|
578
|
-
}, {
|
|
579
|
-
provider: string;
|
|
580
|
-
config: {
|
|
581
|
-
url: string;
|
|
582
|
-
username: string;
|
|
583
|
-
password: string;
|
|
584
|
-
};
|
|
585
|
-
llm?: {
|
|
586
|
-
provider: string;
|
|
587
|
-
config: Record<string, any>;
|
|
588
|
-
} | undefined;
|
|
589
|
-
customPrompt?: string | undefined;
|
|
590
|
-
}>>;
|
|
531
|
+
capturePrompt: z.ZodOptional<z.ZodString>;
|
|
591
532
|
historyStore: z.ZodOptional<z.ZodObject<{
|
|
592
533
|
provider: z.ZodString;
|
|
593
534
|
config: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
@@ -636,6 +577,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
636
577
|
};
|
|
637
578
|
} | undefined;
|
|
638
579
|
recencyCleanupThreshold?: number | undefined;
|
|
580
|
+
searchThreshold?: number | undefined;
|
|
639
581
|
} & {
|
|
640
582
|
[k: string]: unknown;
|
|
641
583
|
};
|
|
@@ -650,21 +592,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
650
592
|
};
|
|
651
593
|
version?: string | undefined;
|
|
652
594
|
historyDbPath?: string | undefined;
|
|
653
|
-
|
|
654
|
-
enableGraph?: boolean | undefined;
|
|
655
|
-
graphStore?: {
|
|
656
|
-
provider: string;
|
|
657
|
-
config: {
|
|
658
|
-
url: string;
|
|
659
|
-
username: string;
|
|
660
|
-
password: string;
|
|
661
|
-
};
|
|
662
|
-
llm?: {
|
|
663
|
-
provider: string;
|
|
664
|
-
config: Record<string, any>;
|
|
665
|
-
} | undefined;
|
|
666
|
-
customPrompt?: string | undefined;
|
|
667
|
-
} | undefined;
|
|
595
|
+
capturePrompt?: string | undefined;
|
|
668
596
|
historyStore?: {
|
|
669
597
|
provider: string;
|
|
670
598
|
config: Record<string, any>;
|
|
@@ -707,6 +635,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
707
635
|
};
|
|
708
636
|
} | undefined;
|
|
709
637
|
recencyCleanupThreshold?: number | undefined;
|
|
638
|
+
searchThreshold?: number | undefined;
|
|
710
639
|
} & {
|
|
711
640
|
[k: string]: unknown;
|
|
712
641
|
};
|
|
@@ -721,21 +650,7 @@ export declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
721
650
|
};
|
|
722
651
|
version?: string | undefined;
|
|
723
652
|
historyDbPath?: string | undefined;
|
|
724
|
-
|
|
725
|
-
enableGraph?: boolean | undefined;
|
|
726
|
-
graphStore?: {
|
|
727
|
-
provider: string;
|
|
728
|
-
config: {
|
|
729
|
-
url: string;
|
|
730
|
-
username: string;
|
|
731
|
-
password: string;
|
|
732
|
-
};
|
|
733
|
-
llm?: {
|
|
734
|
-
provider: string;
|
|
735
|
-
config: Record<string, any>;
|
|
736
|
-
} | undefined;
|
|
737
|
-
customPrompt?: string | undefined;
|
|
738
|
-
} | undefined;
|
|
653
|
+
capturePrompt?: string | undefined;
|
|
739
654
|
historyStore?: {
|
|
740
655
|
provider: string;
|
|
741
656
|
config: Record<string, any>;
|
package/dist/types/index.js
CHANGED
|
@@ -41,6 +41,7 @@ exports.MemoryConfigSchema = zod_1.z.object({
|
|
|
41
41
|
}),
|
|
42
42
|
}).optional(),
|
|
43
43
|
recencyCleanupThreshold: zod_1.z.number().min(0).max(1).optional(),
|
|
44
|
+
searchThreshold: zod_1.z.number().min(0).max(1).optional(),
|
|
44
45
|
})
|
|
45
46
|
.passthrough(),
|
|
46
47
|
}),
|
|
@@ -53,25 +54,7 @@ exports.MemoryConfigSchema = zod_1.z.object({
|
|
|
53
54
|
}),
|
|
54
55
|
}),
|
|
55
56
|
historyDbPath: zod_1.z.string().optional(),
|
|
56
|
-
|
|
57
|
-
enableGraph: zod_1.z.boolean().optional(),
|
|
58
|
-
graphStore: zod_1.z
|
|
59
|
-
.object({
|
|
60
|
-
provider: zod_1.z.string(),
|
|
61
|
-
config: zod_1.z.object({
|
|
62
|
-
url: zod_1.z.string(),
|
|
63
|
-
username: zod_1.z.string(),
|
|
64
|
-
password: zod_1.z.string(),
|
|
65
|
-
}),
|
|
66
|
-
llm: zod_1.z
|
|
67
|
-
.object({
|
|
68
|
-
provider: zod_1.z.string(),
|
|
69
|
-
config: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
70
|
-
})
|
|
71
|
-
.optional(),
|
|
72
|
-
customPrompt: zod_1.z.string().optional(),
|
|
73
|
-
})
|
|
74
|
-
.optional(),
|
|
57
|
+
capturePrompt: zod_1.z.string().optional(),
|
|
75
58
|
historyStore: zod_1.z
|
|
76
59
|
.object({
|
|
77
60
|
provider: zod_1.z.string(),
|
|
@@ -18,6 +18,7 @@ export declare class LiteVectorStore implements VectorStore {
|
|
|
18
18
|
private currentUserId;
|
|
19
19
|
private scoringConfig;
|
|
20
20
|
private cleanupThreshold?;
|
|
21
|
+
private searchThreshold;
|
|
21
22
|
private static cache;
|
|
22
23
|
constructor(config: VectorStoreConfig, currentUserId: string);
|
|
23
24
|
private init;
|
|
@@ -28,7 +28,8 @@ class LiteVectorStore {
|
|
|
28
28
|
this.currentUserId = currentUserId;
|
|
29
29
|
this.isSecure = config.secure || false;
|
|
30
30
|
this.scoringConfig = config.scoring;
|
|
31
|
-
this.cleanupThreshold = config.recencyCleanupThreshold || 0.25; // (default 0.25 means 2 times the half-life
|
|
31
|
+
this.cleanupThreshold = config.recencyCleanupThreshold || 0.25; // (default 0.25 means 2 times the half-life)
|
|
32
|
+
this.searchThreshold = config.searchThreshold ?? 0; // Seuil de score (default 0 = pas de filtrage)
|
|
32
33
|
config.rootPath = config.rootPath || process.cwd();
|
|
33
34
|
const filename = this.isSecure ? `memories-lite-${currentUserId}.db` : `memories-lite-global.db`;
|
|
34
35
|
this.dbPath = (config.rootPath == ':memory:') ? ':memory:' : path_1.default.join(config.rootPath, filename);
|
|
@@ -195,11 +196,15 @@ class LiteVectorStore {
|
|
|
195
196
|
if (this.filterVector(memoryVector, filters)) {
|
|
196
197
|
const cosineScore = this.cosineSimilarity(query, vector);
|
|
197
198
|
const hybridScore = this.calculateHybridScore(cosineScore, payload);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
//
|
|
200
|
+
// Filtrer par searchThreshold - ne retourner que les résultats au-dessus du seuil
|
|
201
|
+
if (hybridScore >= this.searchThreshold) {
|
|
202
|
+
results.push({
|
|
203
|
+
id: memoryVector.id,
|
|
204
|
+
payload: memoryVector.payload,
|
|
205
|
+
score: hybridScore,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
203
208
|
}
|
|
204
209
|
}
|
|
205
210
|
results.sort((a, b) => (b.score ?? 0) - (a.score ?? 0));
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/config/defaults.ts
CHANGED
|
@@ -6,10 +6,10 @@ const DEFAULT_SCORING_CONFIG: MemoryScoringConfig = {
|
|
|
6
6
|
assistant_preference: { alpha: 0.60, beta: 0.05, gamma: 0.35, halfLifeDays: Infinity },
|
|
7
7
|
//
|
|
8
8
|
// discussion: mémoires de discussions (synthèses opérationnelles)
|
|
9
|
-
// - alpha=
|
|
10
|
-
// - beta=
|
|
9
|
+
// - alpha=1: score basé uniquement sur la similarité cosinus
|
|
10
|
+
// - beta=0: pas de recency
|
|
11
11
|
// - gamma=0: pas d'importance base
|
|
12
|
-
discussion: { alpha:
|
|
12
|
+
discussion: { alpha: 1, beta: 0, gamma: 0, halfLifeDays: Infinity },
|
|
13
13
|
//
|
|
14
14
|
// default: fallback si type manquant ou inconnu
|
|
15
15
|
default: { alpha: 0.5, beta: 0.3, gamma: 0.1, halfLifeDays: 30 }
|
|
@@ -17,8 +17,7 @@ const DEFAULT_SCORING_CONFIG: MemoryScoringConfig = {
|
|
|
17
17
|
|
|
18
18
|
export const DEFAULT_MEMORY_CONFIG: MemoryConfig = {
|
|
19
19
|
disableHistory: true,
|
|
20
|
-
|
|
21
|
-
version: "v1.1",
|
|
20
|
+
version: "v2.0",
|
|
22
21
|
embedder: {
|
|
23
22
|
provider: "openai",
|
|
24
23
|
config: {
|
|
@@ -33,6 +32,7 @@ export const DEFAULT_MEMORY_CONFIG: MemoryConfig = {
|
|
|
33
32
|
collectionName: "memories",
|
|
34
33
|
dimension: 768,
|
|
35
34
|
scoring: DEFAULT_SCORING_CONFIG,
|
|
35
|
+
searchThreshold: 0.50, // Seuil minimum de score pour retourner un résultat
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
38
|
llm: {
|
|
@@ -43,20 +43,6 @@ export const DEFAULT_MEMORY_CONFIG: MemoryConfig = {
|
|
|
43
43
|
modelProperties: undefined,
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
|
-
graphStore: {
|
|
47
|
-
provider: "neo4j",
|
|
48
|
-
config: {
|
|
49
|
-
url: process.env.NEO4J_URL || "neo4j://localhost:7687",
|
|
50
|
-
username: process.env.NEO4J_USERNAME || "neo4j",
|
|
51
|
-
password: process.env.NEO4J_PASSWORD || "password",
|
|
52
|
-
},
|
|
53
|
-
llm: {
|
|
54
|
-
provider: "openai",
|
|
55
|
-
config: {
|
|
56
|
-
model: "gpt-5-mini",
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
46
|
historyStore: {
|
|
61
47
|
provider: "dummy",
|
|
62
48
|
config: {
|
package/src/config/manager.ts
CHANGED
|
@@ -106,18 +106,13 @@ export class ConfigManager {
|
|
|
106
106
|
},
|
|
107
107
|
historyDbPath:
|
|
108
108
|
userConfig.historyDbPath || DEFAULT_MEMORY_CONFIG.historyDbPath,
|
|
109
|
-
|
|
110
|
-
graphStore: {
|
|
111
|
-
...DEFAULT_MEMORY_CONFIG.graphStore,
|
|
112
|
-
...userConfig.graphStore,
|
|
113
|
-
},
|
|
109
|
+
capturePrompt: userConfig.capturePrompt,
|
|
114
110
|
historyStore: {
|
|
115
111
|
...DEFAULT_MEMORY_CONFIG.historyStore,
|
|
116
112
|
...userConfig.historyStore,
|
|
117
113
|
},
|
|
118
114
|
disableHistory:
|
|
119
115
|
userConfig.disableHistory || DEFAULT_MEMORY_CONFIG.disableHistory,
|
|
120
|
-
enableGraph: userConfig.enableGraph || DEFAULT_MEMORY_CONFIG.enableGraph,
|
|
121
116
|
};
|
|
122
117
|
|
|
123
118
|
// Validate the merged config
|