memories-lite 0.9.0 → 0.9.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.
- package/dist/memory/index.js +1 -1
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/index.js +11 -6
- package/package.json +1 -1
- package/src/memory/index.ts +1 -1
- package/src/prompts/index.ts +11 -6
- package/tests/memory.facts.test.ts +14 -11
package/dist/memory/index.js
CHANGED
|
@@ -96,7 +96,7 @@ class MemoriesLite {
|
|
|
96
96
|
async addToVectorStore(messages, metadata, userId, filters, customFacts) {
|
|
97
97
|
const $t = this.$t;
|
|
98
98
|
const vectorStore = await this.getVectorStore(userId);
|
|
99
|
-
const parsedMessages = messages.filter((m) => typeof m.content === 'string').map((m) => `${m.role == 'user' ? '**USER**: ' : '**ASSISTANT**: '}${$t(m.content)}\n`).join("\n");
|
|
99
|
+
const parsedMessages = messages.filter((m) => typeof m.content === 'string' && m.role == 'user').map((m) => `${m.role == 'user' ? '**USER**: ' : '**ASSISTANT**: '}${$t(m.content)}\n`).join("\n");
|
|
100
100
|
const [systemPrompt, userPrompt] = (0, prompts_1.getFactRetrievalMessages)(parsedMessages, customFacts || this.customPrompt);
|
|
101
101
|
const response = await this.llm.generateResponse([
|
|
102
102
|
{ role: "system", content: systemPrompt },
|
package/dist/prompts/index.d.ts
CHANGED
|
@@ -83,7 +83,7 @@ export declare const MemoryUpdateSchema: z.ZodObject<{
|
|
|
83
83
|
* If the task is temporal or event-based ("What was I doing yesterday?") → retrieve episodic memory.
|
|
84
84
|
* If the task is conceptual ("What does the user think about Marxism?") → retrieve semantic memory.
|
|
85
85
|
*/
|
|
86
|
-
export declare const MEMORY_STRING_SYSTEM = "# DIRECTIVES FOR MEMORIES\n- Information stored in memory is always enclosed within the <memories> tag.\n- Give 10x more weight to the user's current conversation and prioritize answering it first.\n- You must adapt your answer based on the contents found within the <memories> section.\n- If the memories are irrelevant to the user's query, you MUST ignore them.\n- By default, do not reference this section or the memories in your response.\n- Use
|
|
86
|
+
export declare const MEMORY_STRING_SYSTEM = "# DIRECTIVES FOR MEMORIES\n- Information stored in memory is always enclosed within the <memories> tag.\n- Give 10x more weight to the user's current conversation and prioritize answering it first.\n- You must adapt your answer based on the contents found within the <memories> section.\n- If the memories are irrelevant to the user's query, you MUST ignore them.\n- By default, do not reference this section or the memories in your response.\n- Use memories only to guide your reasoning. Do not respond to the memories themselves.";
|
|
87
87
|
export declare const MEMORY_STRING_PREFIX = "Use these contextual memories to guide your response. Prioritize the user's question. Ignore irrelevant memories.";
|
|
88
88
|
export declare const MEMORY_STRING_SYSTEM_OLD = "# USER AND MEMORIES PREFERENCES:\n- Utilize the provided memories to guide your responses.\n- Disregard any memories that are not relevant.\n- By default, do not reference this section or the memories in your response.\n";
|
|
89
89
|
export declare function getFactRetrievalMessages_O(parsedMessages: string, customRules?: string, defaultLanguage?: string): [string, string];
|
package/dist/prompts/index.js
CHANGED
|
@@ -23,7 +23,12 @@ exports.FactRetrievalSchema_extended = zod_1.z.object({
|
|
|
23
23
|
.array(zod_1.z.object({
|
|
24
24
|
fact: zod_1.z.string().describe("The fact extracted from the conversation."),
|
|
25
25
|
existing: zod_1.z.boolean().describe("Whether the fact is already present"),
|
|
26
|
-
type: zod_1.z.enum(["assistant_preference", "factual", "episodic", "procedural", "semantic"])
|
|
26
|
+
type: zod_1.z.enum(["assistant_preference", "factual", "episodic", "procedural", "semantic"])
|
|
27
|
+
.describe(`The type of the fact.
|
|
28
|
+
Use 'assistant_preference' for Assistant behavior preferences.
|
|
29
|
+
Use 'episodic' always for time-based events.
|
|
30
|
+
Use 'procedural' always when it concerns a business question.
|
|
31
|
+
Use 'semantic' for Understanding of concepts, relationships and general meanings.`),
|
|
27
32
|
}))
|
|
28
33
|
});
|
|
29
34
|
// Define Zod schema for memory update output
|
|
@@ -61,7 +66,7 @@ exports.MEMORY_STRING_SYSTEM = `# DIRECTIVES FOR MEMORIES
|
|
|
61
66
|
- You must adapt your answer based on the contents found within the <memories> section.
|
|
62
67
|
- If the memories are irrelevant to the user's query, you MUST ignore them.
|
|
63
68
|
- By default, do not reference this section or the memories in your response.
|
|
64
|
-
- Use
|
|
69
|
+
- Use memories only to guide your reasoning. Do not respond to the memories themselves.`;
|
|
65
70
|
exports.MEMORY_STRING_PREFIX = "Use these contextual memories to guide your response. Prioritize the user's question. Ignore irrelevant memories.";
|
|
66
71
|
exports.MEMORY_STRING_SYSTEM_OLD = `# USER AND MEMORIES PREFERENCES:
|
|
67
72
|
- Utilize the provided memories to guide your responses.
|
|
@@ -81,17 +86,17 @@ Your mission is to analyze a input content line by line and produce:
|
|
|
81
86
|
|
|
82
87
|
Filter content before extracting triplets:
|
|
83
88
|
- Ignore content with no direct relevance to user (e.g., "today is sunny", "I'm working").
|
|
84
|
-
-
|
|
85
|
-
- Eliminate introductions, sub-facts, detailed repetitive elements, stylistic fillers, or vague statements. A general fact always takes precedence over multiple sub-facts (signal vs noise).
|
|
89
|
+
- Eliminate introductions, vague statements and detailed repetitive elements.
|
|
86
90
|
|
|
87
91
|
You must extract {Subject, Predicate, Object} triplets by following these rules:
|
|
88
92
|
1. Identify named entities, preferences, and meaningful user-related concepts:
|
|
89
|
-
- All extracted triplets describe the user query intention as: the user’s preferences, beliefs, actions, experiences, learning, identity, work, or relationships (e.g., "I
|
|
93
|
+
- All extracted triplets describe the user query intention as: the user’s preferences, beliefs, actions, experiences, learning, identity, work, or relationships (e.g., "I love working with precise Agents").
|
|
94
|
+
- Merge triplets from sub-facts or detailed objects. A general fact always takes precedence over multiple sub-facts (signal vs noise).
|
|
90
95
|
- If the user asks about third-party business information classify it as "procedural" type.
|
|
91
96
|
- The query intention can include specific preferences about how the Assistant should respond (e.g., "answer concisely", "explain in detail").
|
|
92
97
|
- Use inference to compress each fact (max 10 words).
|
|
93
98
|
- DO NOT infer personal facts from third-party informations.
|
|
94
|
-
- Treat "Assistant
|
|
99
|
+
- Treat "Assistant:" messages as external and transient responses, there is no fact to extract from them. These responses MUST be used to enrich your reasoning process.
|
|
95
100
|
2. Compress the facts:
|
|
96
101
|
- Keep only the most shortest version of the Triplet.
|
|
97
102
|
3. Rewrite comparatives, conditionals, or temporals into explicit predicates (e.g., "prefers", "available during", "used because of").
|
package/package.json
CHANGED
package/src/memory/index.ts
CHANGED
|
@@ -162,7 +162,7 @@ export class MemoriesLite {
|
|
|
162
162
|
|
|
163
163
|
const $t = this.$t;
|
|
164
164
|
const vectorStore = await this.getVectorStore(userId);
|
|
165
|
-
const parsedMessages = messages.filter((m) => typeof m.content === 'string').map((m) => `${m.role=='user' ? '**USER**: ' : '**ASSISTANT**: '}${$t(m.content as string)}\n`).join("\n");
|
|
165
|
+
const parsedMessages = messages.filter((m) => typeof m.content === 'string' && m.role=='user').map((m) => `${m.role=='user' ? '**USER**: ' : '**ASSISTANT**: '}${$t(m.content as string)}\n`).join("\n");
|
|
166
166
|
|
|
167
167
|
const [systemPrompt, userPrompt] = getFactRetrievalMessages(parsedMessages, customFacts||this.customPrompt);
|
|
168
168
|
|
package/src/prompts/index.ts
CHANGED
|
@@ -20,7 +20,12 @@ export const FactRetrievalSchema_extended = z.object({
|
|
|
20
20
|
z.object({
|
|
21
21
|
fact: z.string().describe("The fact extracted from the conversation."),
|
|
22
22
|
existing: z.boolean().describe("Whether the fact is already present"),
|
|
23
|
-
type: z.enum(["assistant_preference","factual", "episodic", "procedural", "semantic"])
|
|
23
|
+
type: z.enum(["assistant_preference","factual", "episodic", "procedural", "semantic"])
|
|
24
|
+
.describe(`The type of the fact.
|
|
25
|
+
Use 'assistant_preference' for Assistant behavior preferences.
|
|
26
|
+
Use 'episodic' always for time-based events.
|
|
27
|
+
Use 'procedural' always when it concerns a business question.
|
|
28
|
+
Use 'semantic' for Understanding of concepts, relationships and general meanings.`),
|
|
24
29
|
})
|
|
25
30
|
)
|
|
26
31
|
});
|
|
@@ -71,7 +76,7 @@ export const MEMORY_STRING_SYSTEM = `# DIRECTIVES FOR MEMORIES
|
|
|
71
76
|
- You must adapt your answer based on the contents found within the <memories> section.
|
|
72
77
|
- If the memories are irrelevant to the user's query, you MUST ignore them.
|
|
73
78
|
- By default, do not reference this section or the memories in your response.
|
|
74
|
-
- Use
|
|
79
|
+
- Use memories only to guide your reasoning. Do not respond to the memories themselves.`;
|
|
75
80
|
|
|
76
81
|
export const MEMORY_STRING_PREFIX = "Use these contextual memories to guide your response. Prioritize the user's question. Ignore irrelevant memories."
|
|
77
82
|
|
|
@@ -97,17 +102,17 @@ Your mission is to analyze a input content line by line and produce:
|
|
|
97
102
|
|
|
98
103
|
Filter content before extracting triplets:
|
|
99
104
|
- Ignore content with no direct relevance to user (e.g., "today is sunny", "I'm working").
|
|
100
|
-
-
|
|
101
|
-
- Eliminate introductions, sub-facts, detailed repetitive elements, stylistic fillers, or vague statements. A general fact always takes precedence over multiple sub-facts (signal vs noise).
|
|
105
|
+
- Eliminate introductions, vague statements and detailed repetitive elements.
|
|
102
106
|
|
|
103
107
|
You must extract {Subject, Predicate, Object} triplets by following these rules:
|
|
104
108
|
1. Identify named entities, preferences, and meaningful user-related concepts:
|
|
105
|
-
- All extracted triplets describe the user query intention as: the user’s preferences, beliefs, actions, experiences, learning, identity, work, or relationships (e.g., "I
|
|
109
|
+
- All extracted triplets describe the user query intention as: the user’s preferences, beliefs, actions, experiences, learning, identity, work, or relationships (e.g., "I love working with precise Agents").
|
|
110
|
+
- Merge triplets from sub-facts or detailed objects. A general fact always takes precedence over multiple sub-facts (signal vs noise).
|
|
106
111
|
- If the user asks about third-party business information classify it as "procedural" type.
|
|
107
112
|
- The query intention can include specific preferences about how the Assistant should respond (e.g., "answer concisely", "explain in detail").
|
|
108
113
|
- Use inference to compress each fact (max 10 words).
|
|
109
114
|
- DO NOT infer personal facts from third-party informations.
|
|
110
|
-
- Treat "Assistant
|
|
115
|
+
- Treat "Assistant:" messages as external and transient responses, there is no fact to extract from them. These responses MUST be used to enrich your reasoning process.
|
|
111
116
|
2. Compress the facts:
|
|
112
117
|
- Keep only the most shortest version of the Triplet.
|
|
113
118
|
3. Rewrite comparatives, conditionals, or temporals into explicit predicates (e.g., "prefers", "available during", "used because of").
|
|
@@ -94,23 +94,24 @@ describe("Memory Class facts regression tests", () => {
|
|
|
94
94
|
});
|
|
95
95
|
|
|
96
96
|
it("should add a single procedural memory", async () => {
|
|
97
|
-
const customFacts = "Je suis Olivier Poulain\nIT chez Immeuble SA";
|
|
97
|
+
const customFacts = "Je suis Olivier Poulain\nIT et je travaille chez Immeuble SA";
|
|
98
98
|
const result = (await memory.capture([
|
|
99
99
|
{role:"user", content:"Qui suis-je ?"},
|
|
100
|
-
{role:"
|
|
100
|
+
{role:"assistant", content:"Vous êtes Olivier Poulain, Chef de Projets au département IT & Gestion de projet, dans l'équipe IT de Immeuble SA. Ces informations proviennent de votre profil collaborateur enregistré dans le système interne de Immeuble SA"}],
|
|
101
101
|
userId,
|
|
102
102
|
{customFacts},
|
|
103
103
|
)) as SearchResult;
|
|
104
104
|
expect(result).toBeDefined();
|
|
105
105
|
expect(result.results).toBeDefined();
|
|
106
|
-
expect(result.results.length).toBe(
|
|
107
|
-
expect(result.results[0]?.type).toBe("factual");
|
|
106
|
+
expect(result.results.length).toBe(0);
|
|
107
|
+
// expect(result.results[0]?.type).toBe("factual");
|
|
108
108
|
});
|
|
109
|
-
it("
|
|
109
|
+
it("episodic memory: Je veux manger des sushis pour ma pause de midi.", async () => {
|
|
110
|
+
const customFacts = "Je suis Olivier Poulain\nIT et je travaille chez Immeuble SA";
|
|
110
111
|
const result = (await memory.capture([
|
|
111
|
-
{role:"user", content:"
|
|
112
|
+
{role:"user", content:"Je veux manger des sushis pour ma pause de midi."}],
|
|
112
113
|
userId,
|
|
113
|
-
{},
|
|
114
|
+
{customFacts},
|
|
114
115
|
)) as SearchResult;
|
|
115
116
|
|
|
116
117
|
expect(result).toBeDefined();
|
|
@@ -119,6 +120,7 @@ describe("Memory Class facts regression tests", () => {
|
|
|
119
120
|
expect(result.results[0]?.type).toBe("episodic");
|
|
120
121
|
});
|
|
121
122
|
|
|
123
|
+
|
|
122
124
|
it("should add assistant_preference memory", async () => {
|
|
123
125
|
const result = (await memory.capture(
|
|
124
126
|
"tu dois répondre de manière concise et précise",
|
|
@@ -134,9 +136,10 @@ describe("Memory Class facts regression tests", () => {
|
|
|
134
136
|
expect(result.results[0]?.type).toBe("assistant_preference");
|
|
135
137
|
});
|
|
136
138
|
|
|
137
|
-
it("business
|
|
139
|
+
it("business:Le logement de Alphonse MAGLOIRE au 5ème étage est de combien pièces", async () => {
|
|
138
140
|
const result = (await memory.capture([
|
|
139
|
-
{role:"user", content:"
|
|
141
|
+
{role:"user", content:"Le logement de Alphonse MAGLOIRE au 5ème étage est de combien pièces.",},
|
|
142
|
+
{role:"assitant", content:"Alphonse MAGLOIRE a un logement de 4 pièces au 5ème étage",}],
|
|
140
143
|
userId,
|
|
141
144
|
{customFacts:"Je suis Olivier Poulain, Je m'occupe de la gérance locataire chez Immeuble SA"},
|
|
142
145
|
)) as SearchResult;
|
|
@@ -171,9 +174,9 @@ describe("Memory Class facts regression tests", () => {
|
|
|
171
174
|
}
|
|
172
175
|
});
|
|
173
176
|
|
|
174
|
-
it("
|
|
177
|
+
it("business:Est-ce que Claude RIBUR est à jour avec son loyer ?", async () => {
|
|
175
178
|
const result = (await memory.capture([
|
|
176
|
-
{role:"user", content:"Est-ce que
|
|
179
|
+
{role:"user", content:"Est-ce que Claude RIBUR est à jour avec son loyer ?"}],
|
|
177
180
|
userId,
|
|
178
181
|
{customFacts:"Je suis Olivier Poulain, Je m'occupe de la gérance locataire chez Immeuble SA"},
|
|
179
182
|
)) as SearchResult;
|