feat: add QMD_EMBED_MODEL env var for multilingual embedding support#273
Open
feat: add QMD_EMBED_MODEL env var for multilingual embedding support#273
Conversation
The default embeddinggemma-300M model is English-centric and produces poor embeddings for CJK (Chinese, Japanese, Korean) text. This change allows overriding the embedding model via the QMD_EMBED_MODEL environment variable. Changes: - DEFAULT_EMBED_MODEL now reads from QMD_EMBED_MODEL env var (fallback to embeddinggemma-300M for backward compatibility) - getDefaultLlamaCpp() passes QMD_EMBED_MODEL to LlamaCpp config when set - formatQueryForEmbedding() and formatDocForEmbedding() detect Qwen3-Embedding models and apply the correct prompt format (Qwen3 uses task-instruction format; embeddinggemma uses nomic-style prefix format) - store.ts: pass model URI to format functions so format selection is consistent between indexing and query time - README: document QMD_EMBED_MODEL with Qwen3-Embedding example Recommended multilingual model: QMD_EMBED_MODEL=hf:Qwen/Qwen3-Embedding-0.6B-GGUF/qwen3-embedding-0.6b-q8_0.gguf After changing the model, run: qmd embed -f
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.
Problem
The default
embeddinggemma-300Membedding model is English-centric and produces poor vector representations for CJK (Chinese, Japanese, Korean) text. Users working with multilingual document collections have no way to switch to a better embedding model without modifying source code.Solution
Add
QMD_EMBED_MODELenvironment variable to override the default embedding model at runtime.Changes
src/llm.ts:DEFAULT_EMBED_MODELnow reads fromQMD_EMBED_MODELenv var (falls back toembeddinggemma-300Mfor backward compatibility)src/llm.ts:getDefaultLlamaCpp()passesQMD_EMBED_MODELtoLlamaCppconfig when setsrc/llm.ts: AddisQwen3EmbeddingModel()helper to detect Qwen3-Embedding model familysrc/llm.ts:formatQueryForEmbedding()andformatDocForEmbedding()auto-detect model family and apply the correct prompt format:task: search result | query: ...(unchanged)Instruct: ...\nQuery: ...src/store.ts: pass model URI to format functions for consistency between indexing and query timeREADME.md: documentQMD_EMBED_MODELwith usage exampleUsage
Notes
QMD_EMBED_MODELis unsetQwen3-Reranker-0.6B) already ships with QMD; this PR aligns the embedding side for users who want a consistent Qwen3 pipeline