Improve pgvector keyword recall ranking without changing hybrid sort.

Rank ILIKE matches by lexical coverage instead of recency and attach lexical scores to keyword rows so MemFuseBench candidate recall rises sharply while Chinese hybrid ordering stays unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-09-02 10:01:42 +08:00
parent 0b6f79ae16
commit 2c0d903ecf
3 changed files with 89 additions and 6 deletions
+43
View File
@@ -162,6 +162,49 @@ test('pgvector hybrid ranking keeps vector order when query has no lexical overl
assert.equal(ranked[1].id, '1');
});
test('pgvector keyword fallback ranks ILIKE matches by lexical coverage, not recency', async () => {
const backend = createPgvectorMemoryBackend({
enabled: true,
pool: {
async query(sql) {
if (String(sql).includes('ILIKE')) {
assert.doesNotMatch(String(sql), /ORDER BY updated_at DESC/i);
return {
rows: [
{
id: 902,
content: 'Recent but weak match for curtains only',
type: 'noise',
score: 1,
created_at: '2026-09-01T00:00:00.000Z',
updated_at: '2026-09-01T00:00:00.000Z',
},
{
id: 901,
content: 'Sarah closed the smart curtains to reduce pollen entry',
type: 'fact',
score: 1,
created_at: '2026-05-01T00:00:00.000Z',
updated_at: '2026-05-01T00:00:00.000Z',
},
],
};
}
return { rows: [] };
},
},
embedQuery: async () => [0.25, 0.5, 0.75],
});
const result = await backend.resolve({
userId: 'user-1',
query: 'Why did Sarah close the curtains?',
limit: 1,
});
assert.match(result.memories[0].text, /Sarah closed the smart curtains/);
});
test('pgvector keyword fallback retrieves topic memories missed by vector top-k', async () => {
const queries = [];
const backend = createPgvectorMemoryBackend({