refactor(memory): run agent recall, memory tools and the server on the memory contract (P1.5)
- Orchestrator, memory tools, context loader and pattern write-back use a MemoryStore and a workspace scope instead of MindDB layers; the knowledge graph tools, cognify, memory linker and feedback handler are gone (graph hidden in v1, ADR-0002). - The server opens one mem0 store in <dataDir>/memory/, embedded by the in-process model on first use, and extracts facts about the user in the background with the model the user chose (memoryExtraction setting). - Legacy .mind memories are copied into the store once, in the background; the legacy files are only read. - Weaver consolidation, harvest, wiki, memory import, memory lanes, vector backfill and index reconciliation are removed; agent runs, loops, sub-agent results, connector fetch and the failed-turn capture write through the contract. Workspace sessions no longer hold a mind handle. - FileIndexer and the install audit move to waggle.db; recall date helpers and the reranker are copied into core. - The CLI REPL opens the same memory store.
This commit is contained in:
@@ -5,7 +5,7 @@ import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { PERSONAL_SCOPE } from '@waggle/memory-contract';
|
||||
import { createMem0MemoryStore, type TextEmbedder } from '../src/index.js';
|
||||
import { createMem0MemoryStore, createWordEmbedder, type TextEmbedder } from '../src/index.js';
|
||||
import { describeMemoryStoreContract } from '../../memory-contract/tests/contract-suite.js';
|
||||
|
||||
/** Deterministic bag-of-words embedder: texts that share words get similar vectors. */
|
||||
@@ -125,4 +125,51 @@ describe('mem0 store — local behaviour', () => {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
});
|
||||
|
||||
it('reads a model function on every extraction', async () => {
|
||||
const models: string[] = [];
|
||||
const server = http.createServer((req, res) => {
|
||||
let body = '';
|
||||
req.on('data', (chunk) => { body += chunk; });
|
||||
req.on('end', () => {
|
||||
models.push((JSON.parse(body) as { model: string }).model);
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify({
|
||||
id: 'chatcmpl-test',
|
||||
object: 'chat.completion',
|
||||
created: 0,
|
||||
model: 'any',
|
||||
choices: [{ index: 0, finish_reason: 'stop', message: { role: 'assistant', content: '{"memory":[]}' } }],
|
||||
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
|
||||
}));
|
||||
});
|
||||
});
|
||||
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));
|
||||
const { port } = server.address() as AddressInfo;
|
||||
try {
|
||||
let current = 'first-model';
|
||||
const store = await createMem0MemoryStore({
|
||||
directory: tempDir(),
|
||||
embedder: wordEmbedder,
|
||||
extractionModel: { baseURL: `http://127.0.0.1:${port}/v1`, apiKey: 'test-key', model: () => current },
|
||||
});
|
||||
const conversation = [{ role: 'user' as const, content: 'I like tea.' }];
|
||||
await store.remember({ scope: PERSONAL_SCOPE, conversation });
|
||||
current = 'second-model';
|
||||
await store.remember({ scope: PERSONAL_SCOPE, conversation });
|
||||
expect(models).toEqual(['first-model', 'second-model']);
|
||||
await store.close();
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
});
|
||||
|
||||
it('ships a word embedder that ranks shared words higher', async () => {
|
||||
const embedder = createWordEmbedder();
|
||||
const [tea, coffee, teaAgain] = await embedder.embedBatch(['green tea', 'black coffee', 'tea']);
|
||||
const dot = (a: ArrayLike<number>, b: ArrayLike<number>) =>
|
||||
Array.from(a).reduce((sum, value, i) => sum + value * b[i]!, 0);
|
||||
expect(embedder.dimensions).toBe(256);
|
||||
expect(dot(tea!, teaAgain!)).toBeGreaterThan(dot(coffee!, teaAgain!));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user