Skip to content

Commit 8cb0373

Browse files
committed
Memory-lancedb: configurable capture limit (#16624) (thanks @ciberponk)
1 parent 3e00460 commit 8cb0373

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

‎extensions/memory-lancedb/config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const MEMORY_CATEGORIES = ["preference", "fact", "decision", "entity", "o
1818
export type MemoryCategory = (typeof MEMORY_CATEGORIES)[number];
1919

2020
const DEFAULT_MODEL = "text-embedding-3-small";
21-
const DEFAULT_CAPTURE_MAX_CHARS = 1500;
21+
export const DEFAULT_CAPTURE_MAX_CHARS = 500;
2222
const LEGACY_STATE_DIRS: string[] = [];
2323

2424
function resolveDefaultDbPath(): string {

‎extensions/memory-lancedb/index.test.ts‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe("memory plugin e2e", () => {
6161
expect(config).toBeDefined();
6262
expect(config?.embedding?.apiKey).toBe(OPENAI_API_KEY);
6363
expect(config?.dbPath).toBe(dbPath);
64-
expect(config?.captureMaxChars).toBe(1500);
64+
expect(config?.captureMaxChars).toBe(500);
6565
});
6666

6767
test("config schema resolves env vars", async () => {
@@ -105,6 +105,21 @@ describe("memory plugin e2e", () => {
105105
}).toThrow("captureMaxChars must be between 100 and 10000");
106106
});
107107

108+
test("config schema accepts captureMaxChars override", async () => {
109+
const { default: memoryPlugin } = await import("./index.js");
110+
111+
const config = memoryPlugin.configSchema?.parse?.({
112+
embedding: {
113+
apiKey: OPENAI_API_KEY,
114+
model: "text-embedding-3-small",
115+
},
116+
dbPath,
117+
captureMaxChars: 1800,
118+
});
119+
120+
expect(config?.captureMaxChars).toBe(1800);
121+
});
122+
108123
test("shouldCapture applies real capture rules", async () => {
109124
const { shouldCapture } = await import("./index.js");
110125

@@ -117,10 +132,14 @@ describe("memory plugin e2e", () => {
117132
expect(shouldCapture("<relevant-memories>injected</relevant-memories>")).toBe(false);
118133
expect(shouldCapture("<system>status</system>")).toBe(false);
119134
expect(shouldCapture("Here is a short **summary**\n- bullet")).toBe(false);
120-
const longButAllowed = `I always prefer this style. ${"x".repeat(1200)}`;
121-
const tooLong = `I always prefer this style. ${"x".repeat(1600)}`;
122-
expect(shouldCapture(longButAllowed, { maxChars: 1500 })).toBe(true);
123-
expect(shouldCapture(tooLong, { maxChars: 1500 })).toBe(false);
135+
const defaultAllowed = `I always prefer this style. ${"x".repeat(400)}`;
136+
const defaultTooLong = `I always prefer this style. ${"x".repeat(600)}`;
137+
expect(shouldCapture(defaultAllowed)).toBe(true);
138+
expect(shouldCapture(defaultTooLong)).toBe(false);
139+
const customAllowed = `I always prefer this style. ${"x".repeat(1200)}`;
140+
const customTooLong = `I always prefer this style. ${"x".repeat(1600)}`;
141+
expect(shouldCapture(customAllowed, { maxChars: 1500 })).toBe(true);
142+
expect(shouldCapture(customTooLong, { maxChars: 1500 })).toBe(false);
124143
});
125144

126145
test("detectCategory classifies using production logic", async () => {

‎extensions/memory-lancedb/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Type } from "@sinclair/typebox";
1212
import { randomUUID } from "node:crypto";
1313
import OpenAI from "openai";
1414
import {
15+
DEFAULT_CAPTURE_MAX_CHARS,
1516
MEMORY_CATEGORIES,
1617
type MemoryCategory,
1718
memoryConfigSchema,
@@ -195,7 +196,7 @@ const MEMORY_TRIGGERS = [
195196
];
196197

197198
export function shouldCapture(text: string, options?: { maxChars?: number }): boolean {
198-
const maxChars = options?.maxChars ?? 1500;
199+
const maxChars = options?.maxChars ?? DEFAULT_CAPTURE_MAX_CHARS;
199200
if (text.length < 10 || text.length > maxChars) {
200201
return false;
201202
}

‎extensions/memory-lancedb/openclaw.plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"label": "Capture Max Chars",
3131
"help": "Maximum message length eligible for auto-capture",
3232
"advanced": true,
33-
"placeholder": "1500"
33+
"placeholder": "500"
3434
}
3535
},
3636
"configSchema": {

0 commit comments

Comments
 (0)