Skip to content

Commit 206dd5e

Browse files
GoodbyePlanetclaude
andcommitted
chore: Narrow jina-api known models to v2-base-code and code-embeddings family
Drops jina-embeddings-v3, v2-base-en, and clip-v2 from the known-models list and adds verified native dimensions (and Matryoshka sizes in the comment) for jina-code-embeddings-0.5b (896) and jina-code-embeddings-1.5b (1536). The task-aware prefix is now scoped to the code-embeddings family. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 33253e2 commit 206dd5e

3 files changed

Lines changed: 25 additions & 42 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ configured model — no need to set dimensions manually unless you want to overr
246246
| `JINA_MODEL` | `jinaai/jina-embeddings-v2-base-code` | `jina` | Informational only — the TEI container's `--model-id` flag is what actually loads. Edit `docker-compose.yaml` to change models. |
247247
| `JINA_DIMENSIONS` | `768` | `jina` | Vector dimensions of the TEI model |
248248
| `JINA_API_KEY` | *(required if provider=jina-api)* | `jina-api` | Jina AI API key (hosted endpoint at `api.jina.ai`) |
249-
| `JINA_API_MODEL` | `jina-embeddings-v2-base-code` | `jina-api` | Hosted Jina model — also supports `jina-embeddings-v3`, `jina-code-embeddings-0.5b`, `jina-code-embeddings-1.5b` |
250-
| `JINA_API_DIMENSIONS` | *(native)* | `jina-api` | Optional Matryoshka override (v3 and code-embeddings models support shrinking); required for models without a native default |
249+
| `JINA_API_MODEL` | `jina-embeddings-v2-base-code` | `jina-api` | Hosted Jina model — also supports `jina-code-embeddings-0.5b`, `jina-code-embeddings-1.5b` |
250+
| `JINA_API_DIMENSIONS` | *(native)* | `jina-api` | Optional Matryoshka override (code-embeddings models support shrinking); required for models without a native default |
251251
| `VOYAGE_API_KEY` | *(required if provider=voyage)* | `voyage` | Voyage AI API key |
252252
| `VOYAGE_MODEL` | `voyage-code-3` | `voyage` | Voyage embedding model |
253253
| `VOYAGE_DIMENSIONS` | *(native)* | `voyage` | Optional override — Voyage code-3 supports `256` / `512` / `1024` / `2048` |

server/embeddings/jina_api.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@
1616
_BATCH_SIZE = 128
1717
_BACKOFF_DELAYS = [10, 20, 30, 40]
1818

19-
# Native output dimensions for known models. v3 and the jina-code-embeddings
20-
# family support Matryoshka truncation via the `dimensions` API parameter —
21-
# override with JINA_API_DIMENSIONS.
22-
#
23-
# Other code-tuned models available on the hosted API:
24-
# - jina-code-embeddings-0.5b
25-
# - jina-code-embeddings-1.5b
26-
# Their native dimensions vary; set JINA_API_DIMENSIONS to declare the size.
19+
# Native output dimensions for known models. The jina-code-embeddings family
20+
# supports Matryoshka truncation via the `dimensions` API parameter —
21+
# override with JINA_API_DIMENSIONS to one of the supported sizes:
22+
# - jina-code-embeddings-0.5b: 64, 128, 256, 512, 896 (native)
23+
# https://jina.ai/models/jina-code-embeddings-0.5b
24+
# - jina-code-embeddings-1.5b: 128, 256, 512, 1024, 1536 (native)
25+
# https://jina.ai/models/jina-code-embeddings-1.5b
26+
# jina-embeddings-v2-base-code is fixed-size and does not support truncation.
27+
# https://jina.ai/models/jina-embeddings-v2-base-code
2728
_NATIVE_DIMENSIONS: dict[str, int] = {
2829
"jina-embeddings-v2-base-code": 768,
29-
"jina-embeddings-v2-base-en": 768,
30-
"jina-embeddings-v3": 1024,
31-
"jina-clip-v2": 1024,
30+
"jina-code-embeddings-0.5b": 896,
31+
"jina-code-embeddings-1.5b": 1536,
3232
}
3333

34-
# Models that accept the `task` parameter (asymmetric retrieval). v2 models
35-
# are single-mode and reject `task`, so we omit it for them.
36-
_TASK_AWARE_PREFIXES = ("jina-embeddings-v3", "jina-code-embeddings-")
34+
# Models that accept the `task` parameter (asymmetric retrieval). The v2 model
35+
# is single-mode and rejects `task`, so we omit it.
36+
_TASK_AWARE_PREFIXES = ("jina-code-embeddings-",)
3737

3838

3939
class JinaApiEmbeddingProvider(EmbeddingProvider):

tests/embeddings/test_jina_api.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_missing_api_key_raises(monkeypatch):
3737

3838
def test_unknown_model_without_dimensions_raises(monkeypatch):
3939
monkeypatch.setattr(settings, "jina_api_key", "k")
40-
monkeypatch.setattr(settings, "jina_api_model", "jina-code-embeddings-0.5b")
40+
monkeypatch.setattr(settings, "jina_api_model", "jina-future-99")
4141
monkeypatch.setattr(settings, "jina_api_dimensions", None)
4242
with pytest.raises(RuntimeError, match="JINA_API_DIMENSIONS"):
4343
JinaApiEmbeddingProvider()
@@ -50,7 +50,7 @@ def test_dimensions_native(jina_api_settings):
5050

5151
def test_dimensions_override(monkeypatch):
5252
monkeypatch.setattr(settings, "jina_api_key", "k")
53-
monkeypatch.setattr(settings, "jina_api_model", "jina-embeddings-v3")
53+
monkeypatch.setattr(settings, "jina_api_model", "jina-code-embeddings-1.5b")
5454
monkeypatch.setattr(settings, "jina_api_dimensions", 512)
5555
p = JinaApiEmbeddingProvider()
5656
assert p.dimensions == 512
@@ -81,12 +81,12 @@ async def test_embed_query_omits_task_for_v2_model(provider):
8181

8282

8383
@respx.mock
84-
async def test_embed_batch_sends_task_for_v3_model(monkeypatch):
84+
async def test_embed_batch_sends_task_for_code_embeddings_model(monkeypatch):
8585
monkeypatch.setattr(settings, "jina_api_key", "test-key")
86-
monkeypatch.setattr(settings, "jina_api_model", "jina-embeddings-v3")
86+
monkeypatch.setattr(settings, "jina_api_model", "jina-code-embeddings-1.5b")
8787
monkeypatch.setattr(settings, "jina_api_dimensions", None)
8888
route = respx.post("https://api.jina.ai/v1/embeddings").mock(
89-
return_value=httpx.Response(200, json=_vectors_response(["a"], dim=1024))
89+
return_value=httpx.Response(200, json=_vectors_response(["a"], dim=1536))
9090
)
9191
p = JinaApiEmbeddingProvider()
9292
try:
@@ -98,12 +98,12 @@ async def test_embed_batch_sends_task_for_v3_model(monkeypatch):
9898

9999

100100
@respx.mock
101-
async def test_embed_query_sends_task_for_v3_model(monkeypatch):
101+
async def test_embed_query_sends_task_for_code_embeddings_model(monkeypatch):
102102
monkeypatch.setattr(settings, "jina_api_key", "test-key")
103-
monkeypatch.setattr(settings, "jina_api_model", "jina-embeddings-v3")
103+
monkeypatch.setattr(settings, "jina_api_model", "jina-code-embeddings-1.5b")
104104
monkeypatch.setattr(settings, "jina_api_dimensions", None)
105105
route = respx.post("https://api.jina.ai/v1/embeddings").mock(
106-
return_value=httpx.Response(200, json=_vectors_response(["q"], dim=1024))
106+
return_value=httpx.Response(200, json=_vectors_response(["q"], dim=1536))
107107
)
108108
p = JinaApiEmbeddingProvider()
109109
try:
@@ -114,23 +114,6 @@ async def test_embed_query_sends_task_for_v3_model(monkeypatch):
114114
assert body["task"] == "retrieval.query"
115115

116116

117-
@respx.mock
118-
async def test_embed_batch_sends_task_for_code_embeddings_model(monkeypatch):
119-
monkeypatch.setattr(settings, "jina_api_key", "test-key")
120-
monkeypatch.setattr(settings, "jina_api_model", "jina-code-embeddings-1.5b")
121-
monkeypatch.setattr(settings, "jina_api_dimensions", 1024)
122-
route = respx.post("https://api.jina.ai/v1/embeddings").mock(
123-
return_value=httpx.Response(200, json=_vectors_response(["a"], dim=1024))
124-
)
125-
p = JinaApiEmbeddingProvider()
126-
try:
127-
await p.embed_batch(["a"])
128-
finally:
129-
await p.close()
130-
body = json.loads(route.calls.last.request.read())
131-
assert body["task"] == "retrieval.passage"
132-
133-
134117
@respx.mock
135118
async def test_embed_batch_chunks_at_128(provider):
136119
route = respx.post("https://api.jina.ai/v1/embeddings").mock(
@@ -159,7 +142,7 @@ async def test_authorization_header_set(provider):
159142
@respx.mock
160143
async def test_embed_batch_passes_dimensions_when_overridden(monkeypatch):
161144
monkeypatch.setattr(settings, "jina_api_key", "test-key")
162-
monkeypatch.setattr(settings, "jina_api_model", "jina-embeddings-v3")
145+
monkeypatch.setattr(settings, "jina_api_model", "jina-code-embeddings-1.5b")
163146
monkeypatch.setattr(settings, "jina_api_dimensions", 256)
164147

165148
route = respx.post("https://api.jina.ai/v1/embeddings").mock(

0 commit comments

Comments
 (0)