fix: enable FTS fallback when no embedding provider available (#17725)#17822
fix: enable FTS fallback when no embedding provider available (#17725)#17822irchelper wants to merge 2 commits into
Conversation
…aw#17725) When no embedding provider is available (e.g., OAuth mode without API keys), memory_search now falls back to FTS-only mode instead of returning disabled: true. Changes: - embeddings.ts: return null provider with reason instead of throwing - manager.ts: handle null provider, use FTS-only search mode - manager-search.ts: allow searching all models when provider is undefined - memory-tool.ts: expose search mode in results The search results now include a 'mode' field indicating 'hybrid' or 'fts-only'.
Additional Comments (8)
the sync operation can be triggered even in FTS-only mode (when Prompt To Fix With AIThis is a comment left during a code review.
Path: src/memory/manager-sync-ops.ts
Line: 762:763
Comment:
accessing `this.provider.model` and `this.provider.id` will throw when `provider` is null (FTS-only mode)
the sync operation can be triggered even in FTS-only mode (when `this.provider` is null) via `search()` -> line 213 in `manager.ts`. this causes a runtime error.
```suggestion
meta.model !== (this.provider?.model ?? "none") ||
meta.provider !== (this.provider?.id ?? "none") ||
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/memory/manager-embedding-ops.ts
Line: 98:98
Comment:
accessing `this.provider.id` and `this.provider.model` will throw when `provider` is null (FTS-only mode)
`loadEmbeddingCache()` can be called indirectly through sync operations even when `provider` is null. need null checks here.
```suggestion
const baseParams = [this.provider?.id ?? "none", this.provider?.model ?? "none", this.providerKey];
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/memory/manager-embedding-ops.ts
Line: 135:136
Comment:
accessing `this.provider.id` and `this.provider.model` will throw when `provider` is null
`upsertEmbeddingCache()` can be called during sync even in FTS-only mode. need null checks.
```suggestion
this.provider?.id ?? "none",
this.provider?.model ?? "none",
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/memory/manager-embedding-ops.ts
Line: 690:690
Comment:
calling `enforceEmbeddingMaxInputTokens()` with null provider will throw
`indexFile()` is called during sync operations, which can happen even when `provider` is null. the function needs a guard:
```suggestion
const chunks = this.provider
? enforceEmbeddingMaxInputTokens(
this.provider,
chunkMarkdown(content, this.settings.chunking).filter(
(chunk) => chunk.text.trim().length > 0,
),
)
: chunkMarkdown(content, this.settings.chunking).filter(
(chunk) => chunk.text.trim().length > 0,
);
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/memory/manager-embedding-ops.ts
Line: 717:717
Comment:
accessing `this.provider.model` will throw when provider is null
```suggestion
.run(entry.path, options.source, this.provider?.model ?? "none");
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/memory/manager-embedding-ops.ts
Line: 727:728
Comment:
accessing `this.provider.model` will throw when provider is null
```suggestion
`${options.source}:${entry.path}:${chunk.startLine}:${chunk.endLine}:${chunk.hash}:${this.provider?.model ?? "none"}`,
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/memory/manager-embedding-ops.ts
Line: 747:747
Comment:
accessing `this.provider.model` will throw when provider is null
```suggestion
this.provider?.model ?? "none",
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/memory/manager-embedding-ops.ts
Line: 771:771
Comment:
accessing `this.provider.model` will throw when provider is null
```suggestion
this.provider?.model ?? "none",
```
How can I resolve this? If you propose a fix, please make it concise. |
When searching in FTS-only mode (no embedding provider), extract meaningful keywords from conversational queries to improve search results. Examples: - "that thing we discussed about the API" → ["discussed", "API"] - "之前讨论的那个方案" → ["讨论", "方案"] Implementation: - New query-expansion.ts module with local keyword extraction - Supports English and Chinese stop word filtering - Searches each keyword separately and merges results - Falls back to original query if no keywords extracted This helps users find relevant memory entries even with vague queries, without requiring an external LLM call (which may not be available in FTS-only mode due to missing API keys).
|
Included in #17800 |
Summary
Fixes #17725 - memory_search always returns disabled when using OAuth
When no embedding provider is available (e.g., OAuth mode without API keys), memory_search now falls back to FTS-only mode instead of returning
disabled: true.Changes
1.
src/memory/embeddings.tscreateEmbeddingProvider()to return{ provider: null, providerUnavailableReason: ... }instead of throwing when all providers fail due to missing API keys2.
src/memory/manager.tsproviderfield nullableprovideris nullstatus()to reportsearchMode: 'fts-only'or'hybrid'probeEmbeddingAvailability()andprobeVectorAvailability()to handle null provider3.
src/memory/manager-search.tsproviderModelparameter optional insearchKeyword()4.
src/memory/manager-embedding-ops.tscomputeProviderKey()to handle null provider5.
src/agents/tools/memory-tool.tsmodefield to search results ('hybrid'or'fts-only')Testing
pnpm checkpassesVerification
With this change:
memory_searchno longer returnsdisabled: truewhen no embedding providermode: 'fts-only'ormode: 'hybrid'Greptile Summary
Enables FTS-only fallback when no embedding provider is available, fixing the OAuth mode issue where
memory_searchreturneddisabled: true.Major changes:
createEmbeddingProvider()to returnnullprovider with reason instead of throwing when API keys are missingMemoryIndexManagerto handle null provider and use FTS-only search pathsearchModefield to indicate'fts-only'or'hybrid'modeproviderModelparameter optional insearchKeyword()to search all models in FTS-only modeCritical issues found:
manager-embedding-ops.tsandmanager-sync-ops.tsaccessthis.provider.idandthis.provider.modelwithout null checks, causing runtime errors when sync operations run in FTS-only modeTest coverage:
embeddings.test.tsConfidence Score: 1/5
manager-embedding-ops.tsandmanager-sync-ops.ts. When sync operations run with a null provider (which can happen in FTS-only mode), the code will crash attempting to accessthis.provider.idandthis.provider.modelin at least 8 locations. These are not edge cases - sync is triggered during normal search operations whenthis.settings.sync.onSearchis enabled.src/memory/manager-embedding-ops.tsandsrc/memory/manager-sync-ops.ts- both have multiple null pointer access bugs that need fixing before mergeLast reviewed commit: 9dbb6b3