Skip to content

fix(store): respect QMD_EMBED_MODEL env var in DEFAULT_EMBED_MODEL#348

Open
byheaven wants to merge 1 commit intotobi:mainfrom
byheaven:fix/store-embed-model-env-override
Open

fix(store): respect QMD_EMBED_MODEL env var in DEFAULT_EMBED_MODEL#348
byheaven wants to merge 1 commit intotobi:mainfrom
byheaven:fix/store-embed-model-env-override

Conversation

@byheaven
Copy link
Contributor

Problem

When QMD_EMBED_MODEL is set to a custom embedding model (e.g. Qwen3-Embedding), search queries use the wrong prompt template, degrading search quality.

This is because store.ts hardcodes DEFAULT_EMBED_MODEL = "embeddinggemma", and this value is passed through the call chain:

store.ts hybridQuery/vectorSearchQuery/structuredSearch
  → store.searchVec(query, DEFAULT_EMBED_MODEL, ...)
    → getEmbedding(query, "embeddinggemma", true, session)
      → formatQueryForEmbedding(query, "embeddinggemma")

In formatQueryForEmbedding (llm.ts:38), since modelUri is "embeddinggemma" (truthy), it does not fall through to process.env.QMD_EMBED_MODEL. Then isQwen3EmbeddingModel("embeddinggemma") returns false, so the query is formatted with the embeddinggemma template (task: search result | query: ...) instead of the Qwen3 instruct template.

This means documents are embedded with the correct Qwen3 format (because llm.ts reads the env var), but queries use the wrong format — causing a mismatch that hurts search quality.

Solution

Make store.ts read QMD_EMBED_MODEL with the same fallback pattern as llm.ts:

// Before
export const DEFAULT_EMBED_MODEL = "embeddinggemma";

// After
export const DEFAULT_EMBED_MODEL = process.env.QMD_EMBED_MODEL ?? "embeddinggemma";

Relation to #332

PR #332 fixes the display issue in qmd.ts (showing the wrong model name during qmd embed). This PR fixes the functional bug in store.ts where search queries use the wrong prompt template. The two fixes are complementary.

Fixes #328

Co-Authored-By: Oz oz-agent@warp.dev

store.ts hardcoded DEFAULT_EMBED_MODEL to "embeddinggemma", ignoring the
QMD_EMBED_MODEL env var that llm.ts already respects. This caused
formatQueryForEmbedding() to use the wrong prompt template during search
when a custom embedding model (e.g. Qwen3-Embedding) was configured via
the env var, because the hardcoded "embeddinggemma" string was passed as
modelUri and isQwen3EmbeddingModel() returned false.

Now store.ts reads process.env.QMD_EMBED_MODEL with "embeddinggemma" as
fallback, consistent with llm.ts.

Co-Authored-By: Oz <oz-agent@warp.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qmd embed displays hardcoded 'Model: embeddinggemma' when using QMD_EMBED_MODEL

1 participant