






















@@ -294,6 +294,8 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem
294294sessionKey?: string;
295295qmdSearchModeOverride?: "query" | "search" | "vsearch";
296296onDebug?: (debug: MemorySearchRuntimeDebug) => void;
297+/** When set, only these chunk sources are considered (must be enabled for this manager). */
298+sources?: MemorySource[];
297299},
298300): Promise<MemorySearchResult[]> {
299301opts?.onDebug?.({ backend: "builtin" });
@@ -332,6 +334,14 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem
332334}
333335const minScore = opts?.minScore ?? this.settings.query.minScore;
334336const maxResults = opts?.maxResults ?? this.settings.query.maxResults;
337+const searchSources =
338+opts?.sources && opts.sources.length > 0
339+ ? [...new Set(opts.sources)].filter((s) => this.sources.has(s))
340+ : undefined;
341+if (opts?.sources && opts.sources.length > 0 && (!searchSources || searchSources.length === 0)) {
342+return [];
343+}
344+const sourceFilterList = searchSources ?? [...this.sources];
335345const hybrid = this.settings.query.hybrid;
336346const candidates = Math.min(
337347200,
@@ -345,9 +355,14 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem
345355return [];
346356}
347357348-const fullQueryResults = await this.searchKeyword(cleaned, candidates, {
349-boostFallbackRanking: true,
350-}).catch(() => []);
358+const fullQueryResults = await this.searchKeyword(
359+cleaned,
360+candidates,
361+{
362+boostFallbackRanking: true,
363+},
364+sourceFilterList,
365+).catch(() => []);
351366const resultSets =
352367fullQueryResults.length > 0
353368 ? [fullQueryResults]
@@ -360,7 +375,7 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem
360375});
361376const searchTerms = keywords.length > 0 ? keywords : [cleaned];
362377return searchTerms.map((term) =>
363-this.searchKeyword(term, candidates, { boostFallbackRanking: true }).catch(
378+this.searchKeyword(term, candidates, { boostFallbackRanking: true }, sourceFilterList).catch(
364379() => [],
365380),
366381);
@@ -391,13 +406,13 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem
391406// If FTS isn't available, hybrid mode cannot use keyword search; degrade to vector-only.
392407const keywordResults =
393408hybrid.enabled && this.fts.enabled && this.fts.available
394- ? await this.searchKeyword(cleaned, candidates).catch(() => [])
409+ ? await this.searchKeyword(cleaned, candidates, undefined, sourceFilterList).catch(() => [])
395410 : [];
396411397412const queryVec = await this.embedQueryWithTimeout(cleaned);
398413const hasVector = queryVec.some((v) => v !== 0);
399414const vectorResults = hasVector
400- ? await this.searchVector(queryVec, candidates).catch(() => [])
415+ ? await this.searchVector(queryVec, candidates, sourceFilterList).catch(() => [])
401416 : [];
402417403418if (!hybrid.enabled || !this.fts.enabled || !this.fts.available) {
@@ -473,6 +488,7 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem
473488private async searchVector(
474489queryVec: number[],
475490limit: number,
491+sourceFilterList: MemorySource[],
476492): Promise<Array<MemorySearchResult & { id: string }>> {
477493// This method should never be called without a provider
478494if (!this.provider) {
@@ -486,8 +502,8 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem
486502 limit,
487503snippetMaxChars: SNIPPET_MAX_CHARS,
488504ensureVectorReady: async (dimensions) => await this.ensureVectorReady(dimensions),
489-sourceFilterVec: this.buildSourceFilter("c"),
490-sourceFilterChunks: this.buildSourceFilter(),
505+sourceFilterVec: this.buildSourceFilter("c", sourceFilterList),
506+sourceFilterChunks: this.buildSourceFilter(undefined, sourceFilterList),
491507});
492508return results.map((entry) => entry as MemorySearchResult & { id: string });
493509}
@@ -500,11 +516,12 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem
500516query: string,
501517limit: number,
502518options?: { boostFallbackRanking?: boolean },
519+sourceFilterList?: MemorySource[],
503520): Promise<Array<MemorySearchResult & { id: string; textScore: number }>> {
504521if (!this.fts.enabled || !this.fts.available) {
505522return [];
506523}
507-const sourceFilter = this.buildSourceFilter();
524+const sourceFilter = this.buildSourceFilter(undefined, sourceFilterList);
508525// In FTS-only mode (no provider), search all models; otherwise filter by current provider's model
509526const providerModel = this.provider?.model;
510527const results = await searchKeyword({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。