Skip to content

OpenRouterEmbeddingProvider hardcodes 1536 dimensions, breaking non-1536 embedding models #809

@lukeaus

Description

@lukeaus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions