feat: add remote LLM backend with averaged embedding optimization#325
Open
feat: add remote LLM backend with averaged embedding optimization#325
Conversation
Wire remote HTTP-based LLM (embed/rerank/generate via llama.cpp servers) as an alternative to local node-llama-cpp. Add `llm?: LLM` option to hybridQuery, vectorSearchQuery, and structuredSearch so callers can override the LLM backend. Average all expanded query embeddings into a single vector for one sqlite-vec scan instead of N separate scans, reducing query time from ~47s to ~12s on a 25GB index. Key changes: - llm-remote.ts: RemoteLLM class with HTTP embed/rerank/generate - store.ts: LLM passthrough for expandQuery, embedBatch, rerank; averaged embedding scan in hybridQuery and vectorSearchQuery; .qmd directory resolution for DB path - qmd.ts: withLLMSessionAuto, remote CLI commands, --local flag - collections.ts: config path resolution via .qmd directory - llm.ts: embedBatch added to LLM interface Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Updated the embed method in RemoteLLM to implement a retry mechanism, allowing up to three attempts for transient errors during remote server requests. Improved error handling and logging for both individual and batch embedding processes, ensuring robustness in case of failures. Additionally, modified comments to clarify the behavior of batch embedding fallbacks. Key changes: - Added retry logic in embed method for transient errors - Enhanced error handling and logging - Updated comments for clarity on batch embedding behavior
7f4e1e4 to
575b9ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional HTTP-based remote LLM backend (targeting llama.cpp servers) as an alternative to local node-llama-cpp, plus an embedding optimization that reduces query time significantly on large indexes.
New features:
src/llm-remote.ts:RemoteLLMclass — embed/rerank/generate via HTTP (llama.cpp compatible)hybridQuery,vectorSearchQuery,structuredSearchaccept an optionalllmoverride so callers can use a remote backend without changing global config--localflag to force local node-llama-cpp.qmddirectory resolution for DB and collection config pathsserver/docker-compose.ymlfor spinning up llama.cpp embed/rerank/generate servicesWhy: On large corpora (200k+ files) local embedding becomes a bottleneck. This lets QMD scale to server-side models while keeping local mode fully intact.
Test plan
--local) still works unchanged🤖 AI-assisted (Claude) | Tested on local instance with ~25 GB index