fix: resolve OpenRouter embedding dimensions from model table + env override#1004
fix: resolve OpenRouter embedding dimensions from model table + env override#1004kagura-agent wants to merge 3 commits into
Conversation
Add MODEL_DIMENSIONS table for known OpenRouter embedding models and support OPENROUTER_EMBEDDING_DIMENSIONS env override, matching the pattern established by OpenAIEmbeddingProvider. Previously dimensions was hardcoded to 1536 regardless of configured model. Models with different native dimensions (e.g. qwen3-embedding-8b at 4096) would produce vectors silently rejected by the index, causing semantic recall to return 0 hits with no logged error. Fixes rohitg00#1002
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughOpenRouterEmbeddingProvider now resolves embedding dimensions from the configured model or an override env var, and the new Vitest suite covers the constructor and request wiring behavior. ChangesOpenRouter embedding dimensions
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/providers/embedding/openrouter.ts`:
- Around line 28-39: The resolveDimensions helper in openrouter.ts silently
falls back to DEFAULT_DIMENSIONS when MODEL_DIMENSIONS has no entry for the
given model and no override is set. Add a warning log in resolveDimensions (or
its caller) when this fallback happens so unknown or custom models are clearly
surfaced, and keep the existing override validation path intact. Use the
resolveDimensions function and MODEL_DIMENSIONS lookup to locate the change.
- Around line 28-37: The override parsing in resolveDimensions allows malformed
OPENROUTER_EMBEDDING_DIMENSIONS values to pass because parseInt truncates
trailing characters and decimals. Update resolveDimensions in openrouter.ts to
validate the override string strictly before converting it to a number, so only
whole positive integers are accepted and values like “100abc” or “10.5” are
rejected with the existing error message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b76640bd-a540-4324-b341-47178f80332d
📒 Files selected for processing (2)
src/providers/embedding/openrouter.tstest/openrouter-embedding.test.ts
…back - Replace parseInt() with Number() + isInteger check to reject malformed overrides like '100abc' (trailing garbage) and '10.5' (decimals) - Add console.warn when model is not in MODEL_DIMENSIONS and no override is set, so users know they're using the default 1536 dimensions Addresses CodeRabbit review feedback on rohitg00#1004.
|
@kagura-agent is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
Summary
OpenRouterEmbeddingProviderhardcodeddimensions = 1536regardless of the configured model. Models with different native dimensions (e.g.qwen/qwen3-embedding-8bat 4096) produced vectors silently rejected by the index, causing semantic recall to return 0 hits with no logged error.Changes
src/providers/embedding/openrouter.ts:MODEL_DIMENSIONStable for known OpenRouter-accessible embedding models, following the pattern established byOpenAIEmbeddingProviderOPENROUTER_EMBEDDING_DIMENSIONSenv var override for custom/unlisted modelsresolveDimensions()helper (same shape as the OpenAI provider)openai/text-embedding-3-smallstill resolves to 1536test/openrouter-embedding.test.ts(new):How it works
OPENROUTER_EMBEDDING_DIMENSIONSenv var — if set, use it (explicit override always wins)MODEL_DIMENSIONStableThe existing
withDimensionGuardwrapper (applied increateEmbeddingProvider) will catch any remaining mismatches at runtime.Fixes #1002
Summary by CodeRabbit