feat(memory-lancedb): make auto-capture max length configurable

This commit is contained in:
fan
2026-02-15 07:38:29 +08:00
committed by Vignesh
parent 82c1d9d3ef
commit 3e00460cdc
4 changed files with 57 additions and 4 deletions
+23 -1
View File
@@ -11,12 +11,14 @@ export type MemoryConfig = {
dbPath?: string;
autoCapture?: boolean;
autoRecall?: boolean;
captureMaxChars?: number;
};
export const MEMORY_CATEGORIES = ["preference", "fact", "decision", "entity", "other"] as const;
export type MemoryCategory = (typeof MEMORY_CATEGORIES)[number];
const DEFAULT_MODEL = "text-embedding-3-small";
const DEFAULT_CAPTURE_MAX_CHARS = 1500;
const LEGACY_STATE_DIRS: string[] = [];
function resolveDefaultDbPath(): string {
@@ -89,7 +91,11 @@ export const memoryConfigSchema = {
throw new Error("memory config required");
}
const cfg = value as Record<string, unknown>;
assertAllowedKeys(cfg, ["embedding", "dbPath", "autoCapture", "autoRecall"], "memory config");
assertAllowedKeys(
cfg,
["embedding", "dbPath", "autoCapture", "autoRecall", "captureMaxChars"],
"memory config",
);
const embedding = cfg.embedding as Record<string, unknown> | undefined;
if (!embedding || typeof embedding.apiKey !== "string") {
@@ -99,6 +105,15 @@ export const memoryConfigSchema = {
const model = resolveEmbeddingModel(embedding);
const captureMaxChars =
typeof cfg.captureMaxChars === "number" ? Math.floor(cfg.captureMaxChars) : undefined;
if (
typeof captureMaxChars === "number" &&
(captureMaxChars < 100 || captureMaxChars > 10_000)
) {
throw new Error("captureMaxChars must be between 100 and 10000");
}
return {
embedding: {
provider: "openai",
@@ -108,6 +123,7 @@ export const memoryConfigSchema = {
dbPath: typeof cfg.dbPath === "string" ? cfg.dbPath : DEFAULT_DB_PATH,
autoCapture: cfg.autoCapture !== false,
autoRecall: cfg.autoRecall !== false,
captureMaxChars: captureMaxChars ?? DEFAULT_CAPTURE_MAX_CHARS,
};
},
uiHints: {
@@ -135,5 +151,11 @@ export const memoryConfigSchema = {
label: "Auto-Recall",
help: "Automatically inject relevant memories into context",
},
captureMaxChars: {
label: "Capture Max Chars",
help: "Maximum message length eligible for auto-capture",
advanced: true,
placeholder: String(DEFAULT_CAPTURE_MAX_CHARS),
},
},
};