entities extraction fix

This commit is contained in:
Storme-bit
2026-08-17 02:36:48 -07:00
parent 4defaaaf27
commit a4854cbfde
4 changed files with 177 additions and 2 deletions
+49
View File
@@ -0,0 +1,49 @@
// Entity extraction guards — tests the REAL mentionedIn and isIgnoredName filters
// that keep the extractor from storing (a) greetings and (b) "known entities" hint
// regurgitation. The mentionedIn cases are built from an actual observed failure:
// a "good morning" turn where qwen echoed the hint list back as fake extractions.
const { test } = require('node:test');
const assert = require('node:assert');
const { mentionedIn, isIgnoredName } = require('../packages/memory-service/src/entities/extraction');
test('mentionedIn accepts names that actually appear in the exchange', () => {
const text = 'User: I love how Sanderson writes magic systems. Assistant: Brandon Sanderson is known for hard magic.';
assert.ok(mentionedIn('Sanderson', text));
assert.ok(mentionedIn('Brandon Sanderson', text));
});
test('mentionedIn is case- and whitespace-insensitive', () => {
assert.ok(mentionedIn('digimon world next order', 'talking about Digimon World Next Order today'));
assert.ok(mentionedIn('Digimon World', 'the Digimon World game')); // collapsed whitespace
});
test('mentionedIn matches a name inside a possessive', () => {
assert.ok(mentionedIn('Sanderson', "Sanderson's latest book"));
});
test('regurgitated hint entities are rejected on a greeting turn (the bug)', () => {
// The exchange that triggered the bug — a bare greeting, no entities in it.
const exchange = 'good morning again Morning! Good timing — anything on your mind today?';
// The names qwen wrongly "extracted" from the hint block, verbatim from the logs.
const regurgitated = [
'Sanderson', 'Baldree', 'Riordan',
'Digimon World Next Order',
'Digimon Adventure: Last Evolution Kizuna',
'Digimon Adventure (2020 reboot)',
];
for (const name of regurgitated) {
assert.strictEqual(mentionedIn(name, exchange), false, `"${name}" should be rejected — not in the exchange`);
}
});
test('a real entity survives even when hint regurgitation is happening', () => {
const exchange = 'good morning — did you finish the Qdrant migration? Yes, the Qdrant collection is rebuilt.';
assert.ok(mentionedIn('Qdrant', exchange), 'genuinely-discussed entity is kept');
});
test('isIgnoredName catches greetings regardless of punctuation/case', () => {
assert.ok(isIgnoredName('Good morning'));
assert.ok(isIgnoredName('good morning!'));
assert.ok(isIgnoredName(' HELLO '));
assert.strictEqual(isIgnoredName('Qdrant'), false);
});