Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/embedding_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ async def _call_gemini() -> list[float]:
openai_client = self.client

async def _call_openai() -> list[float]:
openai_kwargs: dict[str, Any] = {"model": self.model, "input": [query]}
openai_kwargs: dict[str, Any] = {
"model": self.model,
"input": [query],
"encoding_format": "float",
}
if self.send_dimensions:
openai_kwargs["dimensions"] = self.vector_dimensions
response = await openai_client.embeddings.create(**openai_kwargs)
Expand Down Expand Up @@ -287,6 +291,7 @@ async def _embed_batch(batch: list[str] = batch) -> list[list[float]]:
openai_kwargs: dict[str, Any] = {
"input": batch,
"model": self.model,
"encoding_format": "float",
}
if self.send_dimensions:
openai_kwargs["dimensions"] = self.vector_dimensions
Expand Down Expand Up @@ -452,6 +457,7 @@ async def _call_provider() -> dict[str, dict[int, list[float]]]:
openai_kwargs: dict[str, Any] = {
"model": self.model,
"input": [item.text for item in batch],
"encoding_format": "float",
}
if self.send_dimensions:
openai_kwargs["dimensions"] = self.vector_dimensions
Expand Down
17 changes: 15 additions & 2 deletions tests/llm/test_embedding_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def __init__(self, *, api_key: str | None, base_url: str | None) -> None:

assert embedding == [0.1] * 8
assert fake_embeddings.calls == [
{"model": "text-embedding-3-small", "input": ["hello world"]}
{
"model": "text-embedding-3-small",
"input": ["hello world"],
"encoding_format": "float",
}
]


Expand Down Expand Up @@ -200,6 +204,7 @@ async def test_openai_embed_forwards_dimensions_when_send_dimensions_true(
{
"model": "text-embedding-3-small",
"input": ["hello"],
"encoding_format": "float",
"dimensions": 768,
}
]
Expand All @@ -219,7 +224,13 @@ async def test_openai_embed_omits_dimensions_when_send_dimensions_false(

await client.embed("hello")

assert fake.calls == [{"model": "text-embedding-3-small", "input": ["hello"]}]
assert fake.calls == [
{
"model": "text-embedding-3-small",
"input": ["hello"],
"encoding_format": "float",
}
]


@pytest.mark.asyncio
Expand All @@ -238,6 +249,7 @@ async def test_openai_simple_batch_embed_forwards_dimensions(

assert len(fake.calls) == 1
assert fake.calls[0]["dimensions"] == 768
assert fake.calls[0]["encoding_format"] == "float"
assert fake.calls[0]["input"] == ["a", "b"]


Expand All @@ -257,6 +269,7 @@ async def test_openai_batch_embed_forwards_dimensions(

assert len(fake.calls) == 1
assert fake.calls[0]["dimensions"] == 768
assert fake.calls[0]["encoding_format"] == "float"


def _build_embedding_settings(
Expand Down