fix(python)!: compute JinaEmbeddings.ndims() per model (#4840)

BREAKING CHANGE: `JinaEmbeddings.ndims()` previously returned 768 for
unlisted model names. It now raises `ValueError`. When creating a schema
with an unlisted model, pass its documented output width to
`Vector(width)`.

Fixes the `# TODO: fix hardcoding` in `JinaEmbeddings.ndims()` (same
kind of fix as #4737, which made the OpenAI-compatible models use their
real dimension).

**Root cause:** `ndims()` returned 768 for every model. Any model whose
default output is not 768 (jina-clip-v2 and jina-embeddings-v3: 1024,
jina-embeddings-v4: 2048, jina-embeddings-v2-small-en: 512) produced a
vector column of the wrong size.

**Fix:** per-model lookup table of default output dimensions, only for
models whose dimension is documented (model configs on Hugging Face
`hidden_size`/`projection_dim`, and https://jina.ai/models/ pages).
Unknown models raise a `ValueError` listing the supported names instead
of silently guessing 768. The default `jina-clip-v1` still returns 768.
When appending to a table, generated vectors are validated against the
width of the stored fixed-size column, so existing tables that use an
unlisted model keep working.

**Test:** `python/tests/test_jina_embeddings.py` (no network, no API
key), including reopening a table with an unlisted model, appending a
matching vector and rejecting a mismatched width.

This change was prepared with an AI coding assistant (Claude).

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Alex Castillo González
2026-11-30 20:23:42 +08:00
committed by GitHub
co-authored by Claude Sonnet 5.5
parent 2ff3bee923
commit d31c1568e0
4 changed files with 131 additions and 4 deletions
+19
View File
@@ -8,6 +8,25 @@ import {
PyEmbeddingJinaMultimodal,
} from '/snippets/provider_examples.mdx';
## Vector Dimensions {#vector-dimensions}
`ndims()`, used when declaring a schema such as `Vector(func.ndims())`, returns the default width of these models:
| Model | Dimensions |
|---|---|
| `jina-clip-v1` | 768 |
| `jina-clip-v2` | 1024 |
| `jina-embeddings-v2-small-en` | 512 |
| `jina-embeddings-v2-base-en` | 768 |
| `jina-embeddings-v2-base-code` | 768 |
| `jina-embeddings-v2-base-de` | 768 |
| `jina-embeddings-v2-base-zh` | 768 |
| `jina-embeddings-v2-base-es` | 768 |
| `jina-embeddings-v3` | 1024 |
| `jina-embeddings-v4` | 2048 |
For any other model name, `ndims()` raises `ValueError`. Appending to an existing table whose vector column is a fixed-size list does not call `ndims()`: the generated vectors are checked against the width stored in the table.
## Text Embedding Models {#text-embedding-models}
Jina embeddings are used to generate embeddings for text and image data.