OpenRouterEmbeddingProvider hardcodes 1536 dimensions, breaking non-1536 embedding models
Summary
OpenRouterEmbeddingProvider currently declares:
readonly dimensions = 1536;
This breaks OpenRouter embedding models that return a different vector size.
Example:
EMBEDDING_PROVIDER=openrouter
OPENROUTER_EMBEDDING_MODEL=perplexity/pplx-embed-v1-0.6b
This model returns 1024-dimensional vectors.
Current behavior
AgentMemory assumes all OpenRouter embedding models are 1536-dimensional. When an OpenRouter embedding model returns a different size, the dimension guard rejects the vectors or the index can become incompatible.
Expected behavior
OpenRouter embedding dimensions should be configurable, similar to OpenAI custom embedding dimensions.
Example config:
EMBEDDING_PROVIDER=openrouter
OPENROUTER_EMBEDDING_MODEL=perplexity/pplx-embed-v1-0.6b
OPENROUTER_EMBEDDING_DIMENSIONS=1024
The provider should:
- expose
dimensionsfromOPENROUTER_EMBEDDING_DIMENSIONS - default to
1536for backward compatibility - validate that the value is a positive integer
- send
dimensionsin the OpenRouter embeddings request body
Why this matters
OpenRouter exposes multiple embedding models with different dimensions. Hardcoding 1536 prevents users from selecting cheaper or better-fit embedding models such as:
perplexity/pplx-embed-v1-0.6bat 1024 dimensions- other OpenRouter embedding models with non-1536 output sizes
Suggested fix
Add:
OPENROUTER_EMBEDDING_DIMENSIONS=1536
and update OpenRouterEmbeddingProvider to use it.
Suggested behavior:
readonly dimensions = resolveDimensions();
body: JSON.stringify({
model: this.model,
input: texts,
dimensions: this.dimensions,
})
Local validation
Tested locally with:
EMBEDDING_PROVIDER=openrouter
OPENROUTER_EMBEDDING_MODEL=perplexity/pplx-embed-v1-0.6b
OPENROUTER_EMBEDDING_DIMENSIONS=1024
Direct OpenRouter call returned a 1024-dimensional embedding. After patching AgentMemory, agentmemory status reported embeddings enabled and a REST save/search smoke test succeeded.
Linked PR: #811
I'll contribute to this
Fixed on main and in the released versions: the OpenRouter embedding provider takes its dimensions from OPENROUTER_EMBEDDING_DIMENSIONS or from the model and no longer uses a fixed 1536 (#1002, via #1136). It does not send a dimensions field in the request; please open a new issue if you need that.