Problem
When using an OpenAI-compatible embedding provider (e.g., Alibaba DashScope/Bailian text-embedding-v4) that supports a dimensions parameter but defaults to a different output dimension than what Honcho expects, the
embedding client fails with a dimension mismatch error.
For example, Bailian's text-embedding-v4 defaults to 1024 dimensions, but Honcho's pgvector schema uses vector(1536). This causes _validate_embedding_dimensions() to raise:
Embedding dimension mismatch for openai:text-embedding-v4. Expected 1536, got 1024.
Root Cause
The OpenAI embeddings.create() API supports a dimensions parameter that lets the caller specify the desired output dimensionality. Many OpenAI-compatible providers also support this parameter (Bailian/DashScope,
OpenRouter, etc.).
However, in src/embedding_client.py, the dimensions parameter is never passed for the OpenAI transport. The Gemini transport correctly passes output_dimensionality via its config dict, but the OpenAI transport ignores
it entirely.
The client already stores self.vector_dimensions (set from EMBEDDING_VECTOR_DIMENSIONS config), and even validates the returned embedding against it — but never sends it to the API, making the validation a post-hoc
check that can only fail, not prevent mismatches.
Affected Code
Three call sites in src/embedding_client.py need dimensions=self.vector_dimensions added:
- embed() method (~line 101):
Current
response = await self.client.embeddings.create(
model=self.model, input=[query]
)
Should be
response = await self.client.embeddings.create(
model=self.model, input=[query], dimensions=self.vector_dimensions
)
- simple_batch_embed() method (~line 138):
Current
response = await self.client.embeddings.create(
input=batch,
model=self.model,
)
Should be
response = await self.client.embeddings.create(
input=batch,
model=self.model,
dimensions=self.vector_dimensions,
)
- _process_batch() method (~line 285):
Current
response = await self.client.embeddings.create(
model=self.model, input=[item.text for item in batch]
)
Should be
response = await self.client.embeddings.create(
model=self.model,
input=[item.text for item in batch],
dimensions=self.vector_dimensions,
)
Compatibility Concern
The dimensions parameter was introduced by OpenAI for text-embedding-3-small/large. Some older OpenAI-compatible providers may not support it. Possible mitigations:
- Option A: Always pass dimensions — clearer error ("provider doesn't support dimensions") vs cryptic mismatch. Simple fix.
- Option B: Only pass when EMBEDDING_VECTOR_DIMENSIONS is explicitly configured by user.
- Option C: Catch unsupported error, retry without dimensions, rely on _validate_embedding_dimensions() as fallback.
I'd lean toward Option A — simplest fix, dimensions is now widely supported, and silent wrong-dimension embeddings are worse than an explicit error.
Environment
- macOS, Homebrew PostgreSQL 17 + pgvector
- Honcho local deployment (no Docker)
- Embedding model: text-embedding-v4 (defaults to 1024 dims, supports dimensions for 1536)
Problem
When using an OpenAI-compatible embedding provider (e.g., Alibaba DashScope/Bailian text-embedding-v4) that supports a dimensions parameter but defaults to a different output dimension than what Honcho expects, the
embedding client fails with a dimension mismatch error.
For example, Bailian's text-embedding-v4 defaults to 1024 dimensions, but Honcho's pgvector schema uses vector(1536). This causes _validate_embedding_dimensions() to raise:
Embedding dimension mismatch for openai:text-embedding-v4. Expected 1536, got 1024.
Root Cause
The OpenAI embeddings.create() API supports a dimensions parameter that lets the caller specify the desired output dimensionality. Many OpenAI-compatible providers also support this parameter (Bailian/DashScope,
OpenRouter, etc.).
However, in src/embedding_client.py, the dimensions parameter is never passed for the OpenAI transport. The Gemini transport correctly passes output_dimensionality via its config dict, but the OpenAI transport ignores
it entirely.
The client already stores self.vector_dimensions (set from EMBEDDING_VECTOR_DIMENSIONS config), and even validates the returned embedding against it — but never sends it to the API, making the validation a post-hoc
check that can only fail, not prevent mismatches.
Affected Code
Three call sites in src/embedding_client.py need dimensions=self.vector_dimensions added:
Current
response = await self.client.embeddings.create(
model=self.model, input=[query]
)
Should be
response = await self.client.embeddings.create(
model=self.model, input=[query], dimensions=self.vector_dimensions
)
Current
response = await self.client.embeddings.create(
input=batch,
model=self.model,
)
Should be
response = await self.client.embeddings.create(
input=batch,
model=self.model,
dimensions=self.vector_dimensions,
)
Current
response = await self.client.embeddings.create(
model=self.model, input=[item.text for item in batch]
)
Should be
response = await self.client.embeddings.create(
model=self.model,
input=[item.text for item in batch],
dimensions=self.vector_dimensions,
)
Compatibility Concern
The dimensions parameter was introduced by OpenAI for text-embedding-3-small/large. Some older OpenAI-compatible providers may not support it. Possible mitigations:
I'd lean toward Option A — simplest fix, dimensions is now widely supported, and silent wrong-dimension embeddings are worse than an explicit error.
Environment