Skip to main content

Embeddings

The embeddings endpoint generates vector representations of input text. This endpoint is compatible with OpenAI’s /v1/embeddings API.

Request

Parameters

Required

string | array
required
Input text to generate embeddings for. Can be:
  • A single string
  • An array of strings for batch processing
  • An array of token IDs (integers)
  • An array of arrays of token IDs
  • An array of multimodal embedding inputs (for multimodal models)
string
default:"default"
Model name to use for embeddings.

Optional

string
default:"float"
Format of the embeddings. Currently only "float" is supported.
integer
Number of dimensions for the output embeddings. If specified, the model will reduce the embedding dimensionality.
string
Unique identifier for the end-user.

SGLang Extensions

string
Path to LoRA adapter weights to apply to the model.
string
Request ID for tracking.
integer
Priority level for the request.

Multimodal Embeddings

For multimodal embedding models, you can provide text, images, and videos:

Multimodal Input Format

string
Text content for the embedding.
string
Image URL, file path, or base64-encoded image.
string
Video URL, file path, or base64-encoded video.

Response

string
Always "list".
array
Array of embedding objects.
string
Always "embedding".
array
Array of floating-point numbers representing the embedding vector.
integer
Index of the embedding in the input array.
string
Model used to generate embeddings.
object
Token usage information.
integer
Number of tokens in the input.
integer
Total tokens processed.

Examples

Single Text Embedding

Batch Embeddings

Semantic Similarity

With LoRA Adapter

Supported Models

SGLang supports various embedding models including:
  • Text Embeddings:
    • BAAI/bge-large-en-v1.5
    • BAAI/bge-base-en-v1.5
    • intfloat/e5-mistral-7b-instruct
    • sentence-transformers/all-MiniLM-L6-v2
  • Multimodal Embeddings:
    • Models supporting text + image embeddings
    • Models supporting text + video embeddings

Response Format

Use Cases

Retrieval-Augmented Generation (RAG)

Embeddings are commonly used in RAG systems to find relevant documents:

Clustering

Group similar texts together:

See Also