BerriAI/litellm · error · HuggingFaceError
sentence-similarity requires 2+ sentences
Error message
sentence-similarity requires 2+ sentences
What it means
Raised by the HuggingFace embedding handler when the model's pipeline tag is 'sentence-similarity' (or 'similarity') and the input list contains fewer than 2 strings. The sentence-similarity API shape requires one source_sentence plus at least one comparison sentence, so litellm refuses the call with HTTP 400 before sending a request.
Source
Thrown at litellm/llms/huggingface/embedding/handler.py:80
pipeline_tag: Final[str | None] = model_info_dict.get("pipeline_tag", None)
return pipeline_tag
class HuggingFaceEmbedding(BaseLLM):
_client_session: httpx.Client | None = None
_aclient_session: httpx.AsyncClient | None = None
def __init__(self) -> None:
super().__init__()
def _transform_input_on_pipeline_tag(self, input: list, pipeline_tag: str | None) -> dict:
if pipeline_tag is None:
return {"inputs": input}
if pipeline_tag == "sentence-similarity" or pipeline_tag == "similarity":
if len(input) < 2:
raise HuggingFaceError(
status_code=400,
message="sentence-similarity requires 2+ sentences",
)
return {"inputs": {"source_sentence": input[0], "sentences": input[1:]}}
elif pipeline_tag == "rerank":
if len(input) < 2:
raise HuggingFaceError(
status_code=400,
message="reranker requires 2+ sentences",
)
return {"inputs": {"query": input[0], "texts": input[1:]}}
return {"inputs": input} # default to feature-extraction pipeline tag
async def _async_transform_input(
self,
model: str,
task_type: str | None,
embed_url: str,View on GitHub (pinned to 6c2dcb801b)
Solutions
- Pass at least 2 strings in the input list: the first becomes source_sentence, the rest become sentences to compare.
- If you only want vector embeddings, use a feature-extraction model (e.g. sentence-transformers/all-MiniLM-L6-v2) instead of a similarity model.
- If you intended cross-encoder scoring of one pair, still pass both members: input=[query, candidate].
Example fix
# before litellm.embedding(model='huggingface/sentence-transformers/all-MiniLM-L6-v2', input=['hello world']) # after litellm.embedding(model='huggingface/sentence-transformers/all-MiniLM-L6-v2', input=['hello world', 'hi there'])
Defensive patterns
Strategy: validation
Validate before calling
def validate_similarity_input(input_list: list[str]) -> bool:
# sentence-similarity path needs a source sentence + >=1 comparison
return isinstance(input_list, list) and len(input_list) >= 2 and all(isinstance(x, str) and x.strip() for x in input_list) Try / catch
try:
resp = litellm.embedding(model=model, input=texts)
except litellm.llms.huggingface.common_utils.HuggingFaceError as e:
if 'requires 2+ sentences' in str(e):
raise ValueError(f'Need >=2 texts for similarity model {model}') from e
raise Prevention
- Check len(input) >= 2 before calling similarity-tagged models
- Keep a model-to-pipeline-tag map in config so you know which models need pairs
When it happens
Trigger: Calling litellm.embedding(model='huggingface/BAAI/bge-...', input=['only one sentence']) or input=[] on a model whose HuggingFace pipeline tag is sentence-similarity/similarity, or explicitly passing task='sentence-similarity' with a single-element input list.
Common situations: Developer reuses an embedding call written for feature-extraction models (which accept a single string) against a cross-encoder/similarity model; or splits a document and the chunking step yields one chunk.
Related errors
- Invalid task_type={task_type}. Expected one of={hf_tasks_emb
- reranker requires 2+ sentences
- sentence transformers requires 2+ sentences
- model is required
- {embeddings[error]}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/fd4fc563c44787ae.
Report an issue: GitHub.