Support list[str] inputs in feature_extraction#4115
Support list[str] inputs in feature_extraction#4115hanouticelina merged 2 commits intohuggingface:mainfrom
Conversation
|
Hi @SJeffZhang thanks for the PR :) Did you tested this PR on a real endpoint? If yes, could you share the code snippet you used? As per the PR itself, I think it's fine to add it (cf #2824 (comment)) but I'll let the final go to @hanouticelina |
|
@Wauplin thanks for the feedback and for taking a look. from huggingface_hub import InferenceClient
client = InferenceClient(
model="sentence-transformers/all-MiniLM-L6-v2",
provider="hf-inference",
)
embeddings = client.feature_extraction(["hello world", "how are you"])
print(type(embeddings).__name__)
print(embeddings.dtype)
print(embeddings.shape)It returned:
So list[str] inputs are accepted correctly on a real embedding endpoint and returned as a 2D float32 numpy array. I also ran the full local test suite with: The suite completed locally, and the PR-related tests passed. I did see a few unrelated failures in live/environment-dependent tests, but nothing pointing to this feature_extraction change. @hanouticelina could you please review this when you have a chance? |
hanouticelina
left a comment
There was a problem hiding this comment.
Makes sense and tested the PR as well ✅ thanks @SJeffZhang for the PR!
(will merge as soon as the CI is green)
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Failing tests are unrelated and the added tests are passing ✅ |
|
This PR has been shipped as part of the v1.13.0 release. |

Fixes #2824.
Summary
This updates
InferenceClient.feature_extractionandAsyncInferenceClient.feature_extractionto accept either a single string or a list of strings.Why
FeatureExtractionInput.inputsalready supports bothstrandlist[str], but the public client methods were still typed and documented as single-string only. That made the public API inconsistent with the underlying request shape and existing provider support for batched embeddings.Changes
str | list[str]in syncfeature_extractionstr | list[str]in asyncfeature_extractionfloat32numpy arraysImpact
Users can now batch embedding requests through the public client API without relying on undocumented behavior or type ignores.
Validation
python -m pytest tests/test_inference_client.py tests/test_inference_async_client.py -k "feature_extraction_accepts_list_inputs or sync_vs_async_signatures"git diff --checkNote
Low Risk
Small, backward-compatible API surface expansion (type/docs + tests) with no changes to request/response handling logic beyond allowing list inputs.
Overview
InferenceClient.feature_extractionandAsyncInferenceClient.feature_extractionnow acceptstr | list[str], aligning the public API and docs with provider support for batched embedding requests.Adds sync/async regression tests that pass a list of texts, assert the list is forwarded unchanged to
prepare_request, and verify the returned embeddings are converted intofloat32numpyarrays (including new async mocking imports).Reviewed by Cursor Bugbot for commit cefe287. Bugbot is set up for automated code reviews on this repo. Configure here.