Skip to content

Commit 755e703

Browse files
authored
fix(litellm): explicitly pass encoding_format="float" (#144)
LiteLLM documents encoding_format as defaulting to float, but in practice some providers (e.g. nvidia_nim) error out when it's not provided. Pass it explicitly as a workaround.
1 parent a81b729 commit 755e703

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/cocoindex_code/litellm_embedder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ async def run_embedding_request(self, *, input: list[str], **kwargs: Any) -> Any
8585
response = await self._aembedding_with_rate_limit_retries(
8686
model=self._model,
8787
input=input,
88+
encoding_format="float",
8889
**kwargs,
8990
)
9091

tests/test_litellm_embedder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def fake_aembedding(*, model: str, input: list[str], **kwargs: Any) -> Any
2525
attempts += 1
2626
assert model == "text-embedding-3-small"
2727
assert input == ["hello"]
28-
assert kwargs == {}
28+
assert kwargs == {"encoding_format": "float"}
2929
if attempts == 1:
3030
raise Exception("Rate limit exceeded. Please try again in 250ms")
3131
return SimpleNamespace(data=[{"embedding": [1.0, 2.0]}])
@@ -54,7 +54,7 @@ async def fake_sleep(delay: float) -> None:
5454

5555
async def fake_aembedding(*, model: str, input: list[str], **kwargs: Any) -> Any:
5656
assert model == "text-embedding-3-small"
57-
assert kwargs == {}
57+
assert kwargs == {"encoding_format": "float"}
5858
inputs_seen.append(input)
5959
return SimpleNamespace(data=[{"embedding": [1.0, 2.0]}])
6060

0 commit comments

Comments
 (0)