Inference Providers documentation

Feature Extraction

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Feature Extraction

Feature extraction is the task of converting a text into a vector (often called “embedding”).

Example applications:

  • Retrieving the most relevant documents for a query (for RAG applications).
  • Reranking a list of documents based on their similarity to a query.
  • Calculating the similarity between two sentences.

For more details about the feature-extraction task, check out its dedicated page! You will find examples and related materials.

Recommended models

  • thenlper/gte-large: A powerful feature extraction model for natural language processing tasks.

Explore all available models and find the one that suits you best here.

Using the API

from huggingface_hub import InferenceClient client = InferenceClient( provider="hf-inference", api_key="hf_xxxxxxxxxxxxxxxxxxxxxxxx", ) result = client.feature_extraction( inputs="Today is a sunny day and I will get some ice cream.", model="intfloat/multilingual-e5-large-instruct", )

API specification

Request

Headers
authorizationstringAuthentication header in the form 'Bearer: hf_****' when hf_**** is a personal user access token with “Inference Providers” permission. You can generate one from your settings page.
Payload
inputs*unknownOne of the following:
         (#1)string
         (#2)string[]
normalizeboolean
prompt_namestringThe name of the prompt that should be used by for encoding. If not set, no prompt will be applied. Must be a key in the sentence-transformers configuration prompts dictionary. For example if prompt_name is “query” and the prompts is {“query”: “query: ”, …}, then the sentence “What is the capital of France?” will be encoded as “query: What is the capital of France?” because the prompt text will be prepended before any text to encode.
truncateboolean
truncation_directionenumPossible values: Left, Right.

Response

Body
(array)array[]Output is an array of arrays.
<>Update on GitHub

close