Inference Providers documentation
Feature Extraction
Get Started
Guides
Your First API CallBuilding Your First AI AppStructured Outputs with LLMsFunction CallingResponses API (beta)How to use OpenAI gpt-ossBuild an Image EditorAutomating Code Review with GitHub ActionsAgentic Coding Environments with OpenEnvEvaluating Models with Inspect
Integrations
OverviewAdd Your IntegrationClaude CodeHermes AgentNeMo Data DesignerMacWhisperOpenCodePiVision AgentsVS Code with GitHub Copilot
Inference Tasks
Providers
CerebrasCohereDeepInfraFal AIFeatherless AIFireworksGroqHyperbolicHF InferenceNovitaNscaleOVHcloud AI EndpointsPublic AIReplicateSambaNovaScalewayTogetherWaveSpeedAIZ.ai
Hub APIRegister as an Inference ProviderFeature 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-extractiontask, 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
Language
Client
Provider
Copied
import os
from huggingface_hub import InferenceClient
client = InferenceClient(
provider="hf-inference",
api_key=os.environ["HF_TOKEN"],
)
result = client.feature_extraction(
"Today is a sunny day and I will get some ice cream.",
model="ibm-granite/granite-embedding-97m-multilingual-r2",
)API specification
Request
| Headers | ||
|---|---|---|
| authorization | string | Authentication 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* | unknown | One of the following: |
| (#1) | string | |
| (#2) | string[] | |
| normalize | boolean | |
| prompt_name | string | The 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. |
| truncate | boolean | |
| truncation_direction | enum | Possible values: left, right. |
Response
| Body | ||
|---|---|---|
| (array) | array[] | Output is an array of arrays. |