fix: parallelize memory embedding indexing

This commit is contained in:
Peter Steinberger
2026-01-17 21:56:17 +00:00
parent 3200b51160
commit f6d359932a
3 changed files with 113 additions and 10 deletions

View File

@@ -150,4 +150,45 @@ describe("memory embedding batches", () => {
expect(last?.total).toBeGreaterThan(0);
expect(last?.completed).toBe(last?.total);
});
it("retries embeddings on rate limit errors", async () => {
const line = "d".repeat(120);
const content = Array.from({ length: 12 }, () => line).join("\n");
await fs.writeFile(path.join(workspaceDir, "memory", "2026-01-06.md"), content);
let calls = 0;
embedBatch.mockImplementation(async (texts: string[]) => {
calls += 1;
if (calls < 3) {
throw new Error("openai embeddings failed: 429 rate limit");
}
return texts.map(() => [0, 1, 0]);
});
const cfg = {
agents: {
defaults: {
workspace: workspaceDir,
memorySearch: {
provider: "openai",
model: "mock-embed",
store: { path: indexPath },
chunking: { tokens: 200, overlap: 0 },
sync: { watch: false, onSessionStart: false, onSearch: false },
query: { minScore: 0 },
},
},
list: [{ id: "main", default: true }],
},
};
const result = await getMemorySearchManager({ cfg, agentId: "main" });
expect(result.manager).not.toBeNull();
if (!result.manager) throw new Error("manager missing");
manager = result.manager;
await manager.sync({ force: true });
expect(calls).toBe(3);
}, 10000);
});