Repository navigation
Problem proxying the reranker via litellm #11
Description
Activity
Thanks a lot for the detailed report and for sharing the curl example – this was very helpful.
You’re absolutely right about the root cause: on the Cohere‑compatible /v1/rerank (and /v2/rerank) endpoints, embed-rerank is currently returning a document field with a null value when return_documents is false or not provided. For example, responses look like:
{ "results": [ { "index": 0, "relevance_score": 0.87, "document": null } ], "meta": { ... } }However, the Cohere API (and litellm’s RerankResponse model) expect one of two things:
Either no document field at all, or
A proper object when return_documents=true.
Because embed-rerank is sending document: null, litellm’s Pydantic model rejects it with the error you’re seeing (Input should be a valid dictionary for results.[i].document).The fix on our side is to make the Cohere rerank endpoints omit document entirely when return_documents is false (or omitted), instead of including it with a null value. Concretely, we’ll update the Cohere router so that the response is serialized with None fields excluded, so the JSON becomes:
{ "results": [ { "index": 0, "relevance_score": 0.87 // no "document" field when return_documents=false } ], "meta": { ... } }This matches both Cohere’s behavior and litellm’s expectations.
As you noted, the HuggingFace/TEI /rerank endpoint already behaves correctly, which is why it works fine in your setup. The issue is specific to the Cohere‑compatible rerank endpoints and their current handling of document.
I’ll ship this change so that litellm’s Cohere proxy works out of the box. In the meantime, a possible workaround is to use the TEI /rerank or the OpenAI‑style /openai/rerank endpoint, which don’t include null documents.
Please check this :
#13So far no issues. Thanks!
Reacted by Joonsoo Kim
I'm was trying to proxy embed-rerank via litellm. embeddings works great but there seems to be an issue with the re-ranker. I've tried cohere compatible api, which keeps failing.
According to Claude, embed-rerank should omit the document field entirely when return_documents is false (or not provided), not include it with a null value.
Huggingface api works though.