fix(memory): honor empty extraction results
Memind CI / Test, build, and release guards (push) Successful in 2m55s
Memind CI / Test, build, and release guards (push) Successful in 2m55s
This commit is contained in:
@@ -208,6 +208,35 @@ test('saveAndAnalyze marks messages analyzed when llm extraction fails and no me
|
||||
else process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED = previous;
|
||||
});
|
||||
|
||||
test('saveAndAnalyze still uses fallback when llm extraction is unavailable', async () => {
|
||||
const previous = process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED;
|
||||
process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED = '1';
|
||||
const pool = createPool();
|
||||
const service = createConversationMemoryService(pool, {
|
||||
now: () => 2250,
|
||||
llmProviderService: {
|
||||
async createChatCompletion() {
|
||||
throw new Error('upstream unavailable');
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await service.saveAndAnalyze('session-fallback', 'user-fallback', [
|
||||
{
|
||||
id: 'm-fallback',
|
||||
role: 'user',
|
||||
content: [{ type: 'text', text: '我喜欢简洁的回答。' }],
|
||||
metadata: { userVisible: true },
|
||||
},
|
||||
]);
|
||||
|
||||
assert.equal(result.memories, 1);
|
||||
assert.match(pool.state.memories[0].memory_text, /简洁/);
|
||||
|
||||
if (previous == null) delete process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED;
|
||||
else process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED = previous;
|
||||
});
|
||||
|
||||
test('saveAndAnalyze uses admin effective env for memory extraction model', async () => {
|
||||
const previous = process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED;
|
||||
process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED = '1';
|
||||
@@ -284,6 +313,40 @@ test('saveAndAnalyze extracts memories through llmProviderService', async () =>
|
||||
else process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED = previous;
|
||||
});
|
||||
|
||||
test('saveAndAnalyze respects an empty llm result instead of storing a question through fallback', async () => {
|
||||
const previous = process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED;
|
||||
process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED = '1';
|
||||
const pool = createPool();
|
||||
const service = createConversationMemoryService(pool, {
|
||||
now: () => 2750,
|
||||
llmProviderService: {
|
||||
async createChatCompletion({ messages }) {
|
||||
assert.match(String(messages?.[0]?.content ?? ''), /问句没有提供答案时不要记录/);
|
||||
return {
|
||||
ok: true,
|
||||
reply: JSON.stringify({ memories: [] }),
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await service.saveAndAnalyze('session-question', 'user-question', [
|
||||
{
|
||||
id: 'm-question',
|
||||
role: 'user',
|
||||
content: [{ type: 'text', text: '用户记住的记忆召回灰度测试代号是什么?' }],
|
||||
metadata: { userVisible: true },
|
||||
},
|
||||
]);
|
||||
|
||||
assert.equal(result.analyzed, 1);
|
||||
assert.equal(result.memories, 0);
|
||||
assert.equal(pool.state.memories.length, 0);
|
||||
|
||||
if (previous == null) delete process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED;
|
||||
else process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED = previous;
|
||||
});
|
||||
|
||||
test('saveAndAnalyze throttles repeated llm extraction warnings', async () => {
|
||||
const previous = process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED;
|
||||
process.env.USER_CONVERSATION_MEMORY_LLM_ENABLED = '1';
|
||||
|
||||
Reference in New Issue
Block a user