Skip to content

feat: support OpenRouter embedding dimensions#811

Open
lukeaus wants to merge 2 commits into
rohitg00:mainfrom
lukeaus:fix/openrouter-embedding-dimensions
Open

feat: support OpenRouter embedding dimensions#811
lukeaus wants to merge 2 commits into
rohitg00:mainfrom
lukeaus:fix/openrouter-embedding-dimensions

Conversation

@lukeaus
Copy link
Copy Markdown

@lukeaus lukeaus commented Jun 3, 2026

Summary

Allows OpenRouter embedding models to declare and request non-1536 vector dimensions.

Fixes #809.

Changes

  • Add OPENROUTER_EMBEDDING_DIMENSIONS support with positive-integer validation.
  • Default to 1536 for backward compatibility.
  • Send dimensions in OpenRouter embedding requests.
  • Document the new env var.
  • Add focused OpenRouter embedding-provider tests.

Verification

  • HOME=$(mktemp -d) npx vitest run test/embedding-provider.test.ts
  • npm run build

Summary by CodeRabbit

  • New Features

    • OpenRouter embedding now supports configurable embedding dimensions via an environment setting.
  • Documentation

    • README and environment docs updated with OpenRouter embedding options and guidance on when to supply dimensions.
  • Tests

    • Added tests for default dimensions, conditional inclusion of dimensions in requests, and validation of invalid dimension values.

Review Change Stack

Copilot AI review requested due to automatic review settings June 3, 2026 11:34
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

@lukeaus is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e4aab4a8-b20d-435a-874c-5e0ea5f1f618

📥 Commits

Reviewing files that changed from the base of the PR and between 534b2ff and b116c51.

📒 Files selected for processing (2)
  • src/providers/embedding/openrouter.ts
  • test/embedding-provider.test.ts

📝 Walkthrough

Walkthrough

OpenRouterEmbeddingProvider now resolves embedding dimensions from the OPENROUTER_EMBEDDING_DIMENSIONS environment variable with validation, defaults to 1536 for backward compatibility, stores the dimension value as a readonly property, includes it in embedding request bodies, and is covered by comprehensive test cases validating parsing, defaults, and error handling.

Changes

OpenRouter Configurable Embedding Dimensions

Layer / File(s) Summary
Configuration and documentation
.env.example, README.md
Environment example and README document the new OPENROUTER_EMBEDDING_DIMENSIONS configuration option and clarify when it is required for non-1536 models.
Provider dimensions resolution and usage
src/providers/embedding/openrouter.ts
OpenRouterEmbeddingProvider resolves dimensions from OPENROUTER_EMBEDDING_DIMENSIONS via a new resolveDimensions() validator, stores them as a readonly property, and includes dimensions in the embedding request payload. resolveDimensions() defaults to 1536, validates the env var as a positive safe integer, and throws on invalid values.
Provider test coverage
test/embedding-provider.test.ts
Test suite validates default dimensions when the env var is unset, correct parsing and usage of OPENROUTER_EMBEDDING_DIMENSIONS, inclusion of dimensions in the request body, and constructor error handling for invalid values (non-numeric, negative, zero).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • rohitg00

Poem

🐰 A rabbit hops through dimensions newfound,
Reading env lines where values are bound,
If digits are tidy and greater than none,
The provider sends dimensions, the job's neatly done,
Defaulting to 1536 — backward safe and sound.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main feature: adding support for configurable OpenRouter embedding dimensions instead of hardcoding 1536.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from #809: exposes OPENROUTER_EMBEDDING_DIMENSIONS env var, defaults to 1536, validates positive integer values, sends dimensions in request body, and includes comprehensive tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the OpenRouter embedding dimensions feature. Documentation updates, code implementation, and tests all relate to the stated objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lukeaus
Copy link
Copy Markdown
Author

lukeaus commented Jun 3, 2026

Linked issue: #809

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds configurable embedding dimensions support for the OpenRouter embedding provider, with tests and documentation updates.

Changes:

  • Add OPENROUTER_EMBEDDING_DIMENSIONS parsing/validation and wire it into OpenRouter requests.
  • Add Vitest coverage for default, explicit, and invalid OpenRouter dimensions behavior.
  • Document new OpenRouter embedding env vars in README and .env.example.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
test/embedding-provider.test.ts Adds unit tests validating OpenRouter dimensions defaulting, request payload, and env var validation.
src/providers/embedding/openrouter.ts Implements env-driven dimensions resolution and includes it in the embeddings request body.
README.md Documents OpenRouter embedding model/dimensions environment variables.
.env.example Adds example OPENROUTER_EMBEDDING_DIMENSIONS configuration entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/embedding-provider.test.ts Outdated
Comment thread test/embedding-provider.test.ts
Comment thread src/providers/embedding/openrouter.ts Outdated
Comment thread src/providers/embedding/openrouter.ts
Signed-off-by: Luke Scott <luke.scott@investflo.ai>
@lukeaus lukeaus force-pushed the fix/openrouter-embedding-dimensions branch from 4dabbaf to 534b2ff Compare June 3, 2026 11:41
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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 71-74: resolveDimensions currently throws when the env value is
whitespace-only; change its logic so that whitespace-only values are treated as
unset and return the default 1536 (same behavior as when raw is undefined).
Specifically, in the resolveDimensions function trim the input and if trimmed
=== "" return 1536; only validate and throw an error when trimmed is non-empty
and not all digits (use the existing /^\d+$/ check), so numeric strings parse to
a number, empty/whitespace returns default, and invalid non-numeric values still
throw.
🪄 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: c5d4fe15-37b5-499d-81cf-9427c38a3f74

📥 Commits

Reviewing files that changed from the base of the PR and between 4dabbaf and 534b2ff.

📒 Files selected for processing (4)
  • .env.example
  • README.md
  • src/providers/embedding/openrouter.ts
  • test/embedding-provider.test.ts
✅ Files skipped from review due to trivial changes (1)
  • .env.example

Comment thread src/providers/embedding/openrouter.ts
@lukeaus
Copy link
Copy Markdown
Author

lukeaus commented Jun 3, 2026

Status update after review pass:

  • Addressed and resolved all review threads.
  • Local validation passed on the latest head b116c51: npm run build, HOME=$(mktemp -d) npx vitest run test/embedding-provider.test.ts, and the full non-integration suite (npm test -- --exclude test/integration.test.ts) from a temporary checkout named agentmemory with 125 test files / 1,386 tests passing.
  • CodeRabbit check is passing/skipped on the latest head.
  • The remaining failing check is Vercel authorization for the upstream rohitg00 Vercel team (Authorization required to deploy), which requires repo/team owner action.
  • I attempted to merge, but GitHub rejected it because lukeaus does not have MergePullRequest permission on rohitg00/agentmemory.

@lukeaus
Copy link
Copy Markdown
Author

lukeaus commented Jun 3, 2026

Reviewed the latest CodeRabbit comments. There are no outstanding actionable CodeRabbit review threads on this PR.

The prior actionable whitespace-only OPENROUTER_EMBEDDING_DIMENSIONS feedback was addressed in the latest head (b116c51), and CodeRabbit is now passing/skipped. The remaining CodeRabbit top-level docstring-coverage warning is a generic pre-merge warning, not tied to an actionable inline review item for this TypeScript provider/test change.

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.

OpenRouterEmbeddingProvider hardcodes 1536 dimensions, breaking non-1536 embedding models

2 participants