feat: add sqlite-vec memory search acceleration
This commit is contained in:
95
src/cli/memory-cli.test.ts
Normal file
95
src/cli/memory-cli.test.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import { Command } from "commander";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const getMemorySearchManager = vi.fn();
|
||||
const loadConfig = vi.fn(() => ({}));
|
||||
const resolveDefaultAgentId = vi.fn(() => "main");
|
||||
|
||||
vi.mock("../memory/index.js", () => ({
|
||||
getMemorySearchManager,
|
||||
}));
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
loadConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../agents/agent-scope.js", () => ({
|
||||
resolveDefaultAgentId,
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
getMemorySearchManager.mockReset();
|
||||
});
|
||||
|
||||
describe("memory cli", () => {
|
||||
it("prints vector status when available", async () => {
|
||||
const { registerMemoryCli } = await import("./memory-cli.js");
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
getMemorySearchManager.mockResolvedValueOnce({
|
||||
manager: {
|
||||
status: () => ({
|
||||
files: 2,
|
||||
chunks: 5,
|
||||
dirty: false,
|
||||
workspaceDir: "/tmp/clawd",
|
||||
dbPath: "/tmp/memory.sqlite",
|
||||
provider: "openai",
|
||||
model: "text-embedding-3-small",
|
||||
requestedProvider: "openai",
|
||||
vector: {
|
||||
enabled: true,
|
||||
available: true,
|
||||
extensionPath: "/opt/sqlite-vec.dylib",
|
||||
dims: 1024,
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const log = vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
|
||||
const program = new Command();
|
||||
program.name("test");
|
||||
registerMemoryCli(program);
|
||||
await program.parseAsync(["memory", "status"], { from: "user" });
|
||||
|
||||
expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector: ready"));
|
||||
expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector dims: 1024"));
|
||||
expect(log).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Vector path: /opt/sqlite-vec.dylib"),
|
||||
);
|
||||
});
|
||||
|
||||
it("prints vector error when unavailable", async () => {
|
||||
const { registerMemoryCli } = await import("./memory-cli.js");
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
getMemorySearchManager.mockResolvedValueOnce({
|
||||
manager: {
|
||||
status: () => ({
|
||||
files: 0,
|
||||
chunks: 0,
|
||||
dirty: true,
|
||||
workspaceDir: "/tmp/clawd",
|
||||
dbPath: "/tmp/memory.sqlite",
|
||||
provider: "openai",
|
||||
model: "text-embedding-3-small",
|
||||
requestedProvider: "openai",
|
||||
vector: {
|
||||
enabled: true,
|
||||
available: false,
|
||||
loadError: "load failed",
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const log = vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
|
||||
const program = new Command();
|
||||
program.name("test");
|
||||
registerMemoryCli(program);
|
||||
await program.parseAsync(["memory", "status", "--agent", "main"], { from: "user" });
|
||||
|
||||
expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector: unavailable"));
|
||||
expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector error: load failed"));
|
||||
});
|
||||
});
|
||||
@@ -56,6 +56,23 @@ export function registerMemoryCli(program: Command) {
|
||||
`Dirty: ${status.dirty ? "yes" : "no"}`,
|
||||
`Index: ${status.dbPath}`,
|
||||
].filter(Boolean) as string[];
|
||||
if (status.vector) {
|
||||
const vectorState = status.vector.enabled
|
||||
? status.vector.available
|
||||
? "ready"
|
||||
: "unavailable"
|
||||
: "disabled";
|
||||
lines.push(`Vector: ${vectorState}`);
|
||||
if (status.vector.dims) {
|
||||
lines.push(`Vector dims: ${status.vector.dims}`);
|
||||
}
|
||||
if (status.vector.extensionPath) {
|
||||
lines.push(`Vector path: ${status.vector.extensionPath}`);
|
||||
}
|
||||
if (status.vector.loadError) {
|
||||
lines.push(chalk.yellow(`Vector error: ${status.vector.loadError}`));
|
||||
}
|
||||
}
|
||||
if (status.fallback?.reason) {
|
||||
lines.push(chalk.gray(status.fallback.reason));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user