From 83aca8a59c7c936390db70735ab4e6190f7d2d12 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 30 Jul 2026 02:48:50 +0800 Subject: [PATCH] fix(memory): return early for blank searches (#116034) --- extensions/memory-core/src/memory/manager.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/memory-core/src/memory/manager.ts b/extensions/memory-core/src/memory/manager.ts index e1cb38cc14cd..3865f6885e7d 100644 --- a/extensions/memory-core/src/memory/manager.ts +++ b/extensions/memory-core/src/memory/manager.ts @@ -1112,6 +1112,10 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem } async search(query: string, opts?: MemoryIndexSearchOptions): Promise { + const normalizedQuery = query.trim(); + if (!normalizedQuery) { + return []; + } const maxResults = opts?.maxResults ?? this.settings.query.maxResults; const minScore = opts?.minScore ?? this.settings.query.minScore; const hasActiveProject = (opts?.activeProjectKeys?.length ?? 0) > 0; @@ -1119,7 +1123,7 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem ? Math.min(200, Math.max(maxResults, maxResults * 4)) : maxResults; const candidateMinScore = hasActiveProject ? minScore / 1.15 : minScore; - const results = await this.searchUnranked(query, { + const results = await this.searchUnranked(normalizedQuery, { ...opts, maxResults: candidateMaxResults, minScore: candidateMinScore, @@ -1131,15 +1135,11 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem } private async searchUnranked( - query: string, + normalizedQuery: string, opts?: MemoryIndexSearchOptions, ): Promise { return await this.withManagerOperation(async () => { opts?.onDebug?.({ backend: "builtin" }); - const normalizedQuery = query.trim(); - if (!normalizedQuery) { - return []; - } if (this.providerRequirement.mode === "required") { await this.ensureProviderInitialized(); this.assertRequiredProviderAvailable("search");