{"record":{"id":"dbd2c61026ec3cfb","repo":"BerriAI/litellm","slug":"reranker-requires-2-sentences","errorCode":null,"errorMessage":"reranker requires 2+ sentences","messagePattern":"reranker requires 2\\+ sentences","errorType":"validation","errorClass":"HuggingFaceError","httpStatus":400,"severity":"error","filePath":"litellm/llms/huggingface/embedding/handler.py","lineNumber":87,"sourceCode":"    _client_session: httpx.Client | None = None\n    _aclient_session: httpx.AsyncClient | None = None\n\n    def __init__(self) -> None:\n        super().__init__()\n\n    def _transform_input_on_pipeline_tag(self, input: list, pipeline_tag: str | None) -> dict:\n        if pipeline_tag is None:\n            return {\"inputs\": input}\n        if pipeline_tag == \"sentence-similarity\" or pipeline_tag == \"similarity\":\n            if len(input) < 2:\n                raise HuggingFaceError(\n                    status_code=400,\n                    message=\"sentence-similarity requires 2+ sentences\",\n                )\n            return {\"inputs\": {\"source_sentence\": input[0], \"sentences\": input[1:]}}\n        elif pipeline_tag == \"rerank\":\n            if len(input) < 2:\n                raise HuggingFaceError(\n                    status_code=400,\n                    message=\"reranker requires 2+ sentences\",\n                )\n            return {\"inputs\": {\"query\": input[0], \"texts\": input[1:]}}\n        return {\"inputs\": input}  # default to feature-extraction pipeline tag\n\n    async def _async_transform_input(\n        self,\n        model: str,\n        task_type: str | None,\n        embed_url: str,\n        input: list,\n        optional_params: dict,\n    ) -> dict:\n        hf_task = await async_get_hf_task_embedding_for_model(model=model, task_type=task_type, api_base=HF_HUB_URL)\n\n        data: Final = self._transform_input_on_pipeline_tag(input=input, pipeline_tag=hf_task)\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/huggingface/embedding/handler.py#L69-L105","documentation":"Raised by the HuggingFace embedding handler when the pipeline tag is 'rerank' and the input list has fewer than 2 entries. The rerank endpoint needs a query (input[0]) plus at least one document to score (input[1:]), so litellm fails fast with HTTP 400.","triggerScenarios":"Calling the embedding endpoint on a model whose HF pipeline tag is 'rerank' (e.g. BAAI/bge-reranker-base) with input=['query'] or input=[]; the request is rejected before any HTTP call is made.","commonSituations":"Developer points an embedding integration at a reranker model by mistake, or sends only the query because the documents list was empty after upstream filtering.","solutions":["Pass input=[query, doc1, doc2, ...] so there is at least one document to rerank.","If you want embeddings rather than reranking, switch to a feature-extraction model.","If you want reranking, prefer litellm.rerank() with the huggingface provider, which maps query/documents correctly."],"exampleFix":"# before\ninput_list = [query]  # documents list was empty\nlitellm.embedding(model='huggingface/BAAI/bge-reranker-base', input=input_list)\n\n# after\ninput_list = [query] + documents\nlitellm.rerank(model='huggingface/BAAI/bge-reranker-base', query=query, documents=documents)","handlingStrategy":"validation","validationCode":"def validate_rerank_input(input_list: list[str]) -> bool:\n    # query + at least one document\n    return len(input_list) >= 2 and bool(input_list[1])","typeGuard":null,"tryCatchPattern":"try:\n    litellm.embedding(model=model, input=texts)\nexcept litellm.llms.huggingface.common_utils.HuggingFaceError as e:\n    if 'reranker requires' in str(e):\n        logger.warning('reranker model used via embedding API; falling back to empty scores')\n        return []\n    raise","preventionTips":["Route reranker models through litellm.rerank(), not embedding()","Assert non-empty documents before scoring"],"tags":["huggingface","rerank","validation","input-validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}