From c0ab0ba0ca7b74ca0f7a96f4e0c4065664aca174 Mon Sep 17 00:00:00 2001 From: jlin53882 Date: Fri, 27 Mar 2026 15:26:21 +0800 Subject: [PATCH] feat(auto-recall): make query length limit configurable via autoRecallMaxQueryLength (default 2000) - Add FR-04 truncation before embedding to keep query focused - Make MAX_RECALL_QUERY_LENGTH configurable via config.autoRecallMaxQueryLength - Default to 2000 chars (previously hardcoded 1000 in some builds) - Add info log when truncation occurs for visibility - Mirrors existing config pattern (autoRecallMaxItems, autoRecallMaxChars, etc.) --- index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 32f5e778..6f88c3fc 100644 --- a/index.ts +++ b/index.ts @@ -2002,8 +2002,20 @@ const memoryLanceDBProPlugin = { const agentId = resolveHookAgentId(ctx?.agentId, (event as any).sessionKey); const accessibleScopes = scopeManager.getAccessibleScopes(agentId); + // FR-04: Truncate long prompts (e.g. file attachments) before embedding. + // Auto-recall only needs the user's intent, not full attachment text. + const MAX_RECALL_QUERY_LENGTH = config.autoRecallMaxQueryLength ?? 2_000; + let recallQuery = event.prompt; + if (recallQuery.length > MAX_RECALL_QUERY_LENGTH) { + const originalLength = recallQuery.length; + recallQuery = recallQuery.slice(0, MAX_RECALL_QUERY_LENGTH); + api.logger.info( + `memory-lancedb-pro: auto-recall query truncated from ${originalLength} to ${MAX_RECALL_QUERY_LENGTH} chars` + ); + } + const results = await retrieveWithRetry({ - query: event.prompt, + query: recallQuery, limit: 3, scopeFilter: accessibleScopes, source: "auto-recall",