Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/memos-local-openclaw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ All optional — shown with defaults:
"rrfK": 60, // RRF fusion constant
"mmrLambda": 0.7, // MMR relevance vs diversity (0-1)
"recencyHalfLifeDays": 14, // Time decay half-life
"vectorSearchMaxChunks": 0 // 0 = search all (default). Set 200000–300000 only if search is slow on huge DBs
"vectorSearchMaxChunks": 0, // 0 = search all (default). Set 200000–300000 only if search is slow on huge DBs
"autoRecallMinQueryLength": 4 // Skip auto-recall when the normalised user prompt is shorter than this many chars (filters "好的"/"可以"/"?"). 0 disables the guard. Has no effect on explicit memory_search tool calls.
},
"dedup": {
"similarityThreshold": 0.75, // Cosine similarity for smart-dedup candidates (Top-5)
Expand Down
5 changes: 3 additions & 2 deletions apps/memos-local-openclaw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1882,8 +1882,9 @@ Groups: ${groupNames.length > 0 ? groupNames.join(", ") : "(none)"}`,
const query = normalizeAutoRecallQuery(rawPrompt);
recallQuery = query;

if (query.length < 2) {
ctx.log.debug("auto-recall: extracted query too short, skipping");
const minQueryLength = ctx.config.recall?.autoRecallMinQueryLength ?? DEFAULTS.autoRecallMinQueryLength;
if (query.length < minQueryLength) {
ctx.log.debug(`auto-recall: query too short (len=${query.length} < minQueryLength=${minQueryLength}), skipping`);
return;
}
ctx.log.debug(`auto-recall: query="${query.slice(0, 80)}"`);
Expand Down
1 change: 1 addition & 0 deletions apps/memos-local-openclaw/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function resolveConfig(raw: Partial<MemosLocalConfig> | undefined, stateD
mmrLambda: cfg.recall?.mmrLambda ?? DEFAULTS.mmrLambda,
recencyHalfLifeDays: cfg.recall?.recencyHalfLifeDays ?? DEFAULTS.recencyHalfLifeDays,
vectorSearchMaxChunks: cfg.recall?.vectorSearchMaxChunks ?? DEFAULTS.vectorSearchMaxChunks,
autoRecallMinQueryLength: cfg.recall?.autoRecallMinQueryLength ?? DEFAULTS.autoRecallMinQueryLength,
},
dedup: {
similarityThreshold: cfg.dedup?.similarityThreshold ?? DEFAULTS.dedupSimilarityThreshold,
Expand Down
22 changes: 22 additions & 0 deletions apps/memos-local-openclaw/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,20 @@ export interface MemosLocalConfig {
recencyHalfLifeDays?: number;
/** Cap vector search to this many most recent chunks. 0 = no cap (search all; may get slower with 200k+ chunks). If you set a cap for performance, use a large value (e.g. 200000–300000) so older memories are still in the window; FTS always searches all. */
vectorSearchMaxChunks?: number;
/**
* Minimum length (in UTF-16 code units, i.e. `string.length`) of the
* normalised auto-recall query. When the user prompt is shorter than
* this threshold (e.g. one-word confirmations like "好的", "可以",
* "运行", "继续", "?"), the `before_prompt_build` hook skips
* auto-recall to avoid injecting noise into the agent context.
*
* Only affects the *automatic* recall path. Explicit `memory_search`
* tool calls are unaffected — the agent / user opted in.
*
* Default: 4. Set to 0 to disable the guard (run auto-recall on
* every prompt regardless of length).
*/
autoRecallMinQueryLength?: number;
};
dedup?: {
similarityThreshold?: number;
Expand All @@ -337,6 +351,14 @@ export const DEFAULTS = {
mmrLambda: 0.7,
recencyHalfLifeDays: 14,
vectorSearchMaxChunks: 0,
/**
* Default minimum length of the normalised auto-recall query before
* the `before_prompt_build` hook will run a memory search. Filters
* out one-word language tokens (e.g. "好的", "可以", "运行", "继续",
* "?", "👍") that would otherwise inject unrelated history into the
* agent context. See `MemosLocalConfig.recall.autoRecallMinQueryLength`.
*/
autoRecallMinQueryLength: 4,
dedupSimilarityThreshold: 0.80,
evidenceWrapperTag: "STORED_MEMORY",
excerptMinChars: 200,
Expand Down
25 changes: 25 additions & 0 deletions apps/memos-local-openclaw/tests/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { describe, expect, it } from "vitest";
import { resolveConfig } from "../src/config";
import { DEFAULTS } from "../src/types";

describe("resolveConfig recall.autoRecallMinQueryLength", () => {
it("defaults to DEFAULTS.autoRecallMinQueryLength when not set", () => {
const resolved = resolveConfig({}, "/tmp/memos-config-min-query-default");
expect(resolved.recall?.autoRecallMinQueryLength).toBe(DEFAULTS.autoRecallMinQueryLength);
expect(resolved.recall?.autoRecallMinQueryLength).toBe(4);
});

it("preserves an explicit override", () => {
const resolved = resolveConfig(
{ recall: { autoRecallMinQueryLength: 10 } },
"/tmp/memos-config-min-query-override",
);
expect(resolved.recall?.autoRecallMinQueryLength).toBe(10);
});

it("preserves 0 explicitly (disables the short-query skip)", () => {
const resolved = resolveConfig(
{ recall: { autoRecallMinQueryLength: 0 } },
"/tmp/memos-config-min-query-zero",
);
expect(resolved.recall?.autoRecallMinQueryLength).toBe(0);
});
});

describe("resolveConfig", () => {
it("injects openclaw providers into existing blocks when host capabilities are enabled", () => {
Expand Down
Loading