agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

OpenRouterEmbeddingProvider hardcodes 1536 dimensions, breaking non-1536 embedding models

Open lukeaus opened this issue 6 months ago • 3 comments

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 dimensions from OPENROUTER_EMBEDDING_DIMENSIONS
  • default to 1536 for backward compatibility
  • validate that the value is a positive integer
  • send dimensions in 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.6b at 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.

lukeaus avatar Jun 03 '26 11:06 lukeaus

Linked PR: #811

lukeaus avatar Jun 03 '26 11:06 lukeaus

I'll contribute to this

Sushanth012 avatar Jun 08 '26 04:06 Sushanth012

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.

rohitg00 avatar Nov 29 '26 11:11 rohitg00