fix(memory): return early for blank searches (#116034)

This commit is contained in:
Vincent Koc
2026-07-30 02:48:50 +08:00
committed by GitHub
parent c709aa7787
commit 83aca8a59c
+6 -6
View File
@@ -1112,6 +1112,10 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem
}
async search(query: string, opts?: MemoryIndexSearchOptions): Promise<MemorySearchResult[]> {
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<MemorySearchResult[]> {
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");