Skip to content

Commit 24774cc

Browse files
committed
fix: make base url as part of params for jina document embedder
1 parent 37135c7 commit 24774cc

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

integrations/jina/src/haystack_integrations/components/embedders/jina/document_embedder.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(
4141
self,
4242
api_key: Secret = Secret.from_env_var("JINA_API_KEY"), # noqa: B008
4343
model: str = "jina-embeddings-v3",
44+
base_url: str = JINA_API_URL,
4445
prefix: str = "",
4546
suffix: str = "",
4647
batch_size: int = 32,
@@ -57,6 +58,7 @@ def __init__(
5758
:param api_key: The Jina API key.
5859
:param model: The name of the Jina model to use.
5960
Check the list of available models on [Jina documentation](https://jina.ai/embeddings/).
61+
:param base_url: The base URL of the Jina API.
6062
:param prefix: A string to add to the beginning of each text.
6163
:param suffix: A string to add to the end of each text.
6264
:param batch_size: Number of Documents to encode at once.
@@ -79,6 +81,7 @@ def __init__(
7981

8082
self.api_key = api_key
8183
self.model_name = model
84+
self.base_url = base_url
8285
self.prefix = prefix
8386
self.suffix = suffix
8487
self.batch_size = batch_size
@@ -113,6 +116,7 @@ def to_dict(self) -> dict[str, Any]:
113116
kwargs = {
114117
"api_key": self.api_key.to_dict(),
115118
"model": self.model_name,
119+
"base_url": self.base_url,
116120
"prefix": self.prefix,
117121
"suffix": self.suffix,
118122
"batch_size": self.batch_size,
@@ -173,7 +177,7 @@ def _embed_batch(
173177
):
174178
batch = texts_to_embed[i : i + batch_size]
175179
response = self._session.post(
176-
JINA_API_URL,
180+
self.base_url,
177181
json={"input": batch, "model": self.model_name, **(parameters or {})},
178182
).json()
179183
if "data" not in response:

integrations/jina/src/haystack_integrations/components/embedders/jina/text_embedder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def __init__(
5151
environment variable `JINA_API_KEY` (recommended).
5252
:param model: The name of the Jina model to use.
5353
Check the list of available models on [Jina documentation](https://jina.ai/embeddings/).
54+
:param base_url: The base URL of the Jina API.
5455
:param prefix: A string to add to the beginning of each text.
5556
:param suffix: A string to add to the end of each text.
5657
:param task: The downstream task for which the embeddings will be used.

integrations/jina/tests/test_document_embedder.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_init_default(self, monkeypatch):
3333

3434
assert embedder.api_key == Secret.from_env_var("JINA_API_KEY")
3535
assert embedder.model_name == "jina-embeddings-v3"
36+
assert embedder.base_url == "https://api.jina.ai/v1/embeddings"
3637
assert embedder.prefix == ""
3738
assert embedder.suffix == ""
3839
assert embedder.batch_size == 32
@@ -44,6 +45,7 @@ def test_init_with_parameters(self):
4445
embedder = JinaDocumentEmbedder(
4546
api_key=Secret.from_token("fake-api-key"),
4647
model="model",
48+
base_url="http://api.jina.ai/v1/embeddings",
4749
prefix="prefix",
4850
suffix="suffix",
4951
batch_size=64,
@@ -57,6 +59,7 @@ def test_init_with_parameters(self):
5759

5860
assert embedder.api_key == Secret.from_token("fake-api-key")
5961
assert embedder.model_name == "model"
62+
assert embedder.base_url == "http://api.jina.ai/v1/embeddings"
6063
assert embedder.prefix == "prefix"
6164
assert embedder.suffix == "suffix"
6265
assert embedder.batch_size == 64
@@ -81,6 +84,7 @@ def test_to_dict(self, monkeypatch):
8184
"init_parameters": {
8285
"api_key": {"env_vars": ["JINA_API_KEY"], "strict": True, "type": "env_var"},
8386
"model": "jina-embeddings-v3",
87+
"base_url": "https://api.jina.ai/v1/embeddings",
8488
"prefix": "",
8589
"suffix": "",
8690
"batch_size": 32,
@@ -94,6 +98,7 @@ def test_to_dict_with_custom_init_parameters(self, monkeypatch):
9498
monkeypatch.setenv("JINA_API_KEY", "fake-api-key")
9599
component = JinaDocumentEmbedder(
96100
model="model",
101+
base_url="http://api.jina.ai/v1/embeddings",
97102
prefix="prefix",
98103
suffix="suffix",
99104
batch_size=64,
@@ -109,6 +114,7 @@ def test_to_dict_with_custom_init_parameters(self, monkeypatch):
109114
"init_parameters": {
110115
"api_key": {"env_vars": ["JINA_API_KEY"], "strict": True, "type": "env_var"},
111116
"model": "model",
117+
"base_url": "http://api.jina.ai/v1/embeddings",
112118
"prefix": "prefix",
113119
"suffix": "suffix",
114120
"batch_size": 64,

0 commit comments

Comments
 (0)