fix(memory): sync new memories into pgvector
Memind CI / Test, build, and release guards (push) Successful in 2m31s
Memind CI / Test, build, and release guards (push) Successful in 2m31s
This commit is contained in:
@@ -3,6 +3,8 @@ import test from 'node:test';
|
||||
import {
|
||||
backfillLegacyMemoriesToPgvector,
|
||||
loadLegacyMemoryBackfillBatch,
|
||||
loadLegacyUserMemorySyncBatch,
|
||||
syncLegacyUserMemoriesToPgvector,
|
||||
} from './memory-v2-pgvector-backfill.mjs';
|
||||
|
||||
function createMysqlPool(rows) {
|
||||
@@ -162,3 +164,55 @@ test('backfillLegacyMemoriesToPgvector apply requires pg pool and embedding func
|
||||
/embedMemory/,
|
||||
);
|
||||
});
|
||||
|
||||
test('loadLegacyUserMemorySyncBatch scopes recent memories to one user and session', async () => {
|
||||
const calls = [];
|
||||
const mysqlPool = {
|
||||
async query(sql, params) {
|
||||
calls.push({ sql, params });
|
||||
return [[legacyRows[1]]];
|
||||
},
|
||||
};
|
||||
|
||||
const memories = await loadLegacyUserMemorySyncBatch(mysqlPool, {
|
||||
userId: 'user-1',
|
||||
sessionId: 'session-2',
|
||||
limit: 25,
|
||||
});
|
||||
|
||||
assert.equal(memories.length, 1);
|
||||
assert.equal(memories[0].id, 'mem-2');
|
||||
assert.match(calls[0].sql, /user_id = \?/);
|
||||
assert.match(calls[0].sql, /source_session_id = \?/);
|
||||
assert.match(calls[0].sql, /ORDER BY updated_at DESC/);
|
||||
assert.deepEqual(calls[0].params, ['user-1', 'session-2', 25]);
|
||||
});
|
||||
|
||||
test('syncLegacyUserMemoriesToPgvector immediately upserts the scoped memory', async () => {
|
||||
const pgCalls = [];
|
||||
const mysqlPool = {
|
||||
async query() {
|
||||
return [[legacyRows[0]]];
|
||||
},
|
||||
};
|
||||
|
||||
const result = await syncLegacyUserMemoriesToPgvector({
|
||||
mysqlPool,
|
||||
pgPool: {
|
||||
async query(sql, params) {
|
||||
pgCalls.push({ sql, params });
|
||||
return { rows: [] };
|
||||
},
|
||||
},
|
||||
embedMemory: async () => [0.2, 0.4],
|
||||
userId: 'user-1',
|
||||
sessionId: 'session-1',
|
||||
limit: 10,
|
||||
});
|
||||
|
||||
assert.equal(result.mode, 'user-sync');
|
||||
assert.equal(result.scanned, 1);
|
||||
assert.equal(result.inserted, 1);
|
||||
assert.match(pgCalls[0].sql, /INSERT INTO "memory_embeddings"/);
|
||||
assert.equal(pgCalls[0].params[4], 'mem-1');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user