임베딩 모델
임베딩 모델 (Embedding models)
이 페이지는 FlashInfer 가속과 SGLang의 배칭 인프라를 활용한 밀집(dense) 및 희소(sparse) 임베딩 모델을 설명해요. SGLang은 효율적인 서빙 메커니즘과 유연한 프로그래밍 인터페이스를 통합해 임베딩 모델을 강력하게 지원해요. 덕분에 더 빠르고 정확한 검색(retrieval)과 의미 검색(semantic search)이 가능해져요.
출처: 문서
본문
SGLang은 효율적인 서빙 메커니즘과 유연한 프로그래밍 인터페이스를 통합해 임베딩 모델을 강력하게 지원해요. 이 통합은 임베딩 작업의 원활한 처리를 가능하게 해, 더 빠르고 정확한 검색과 의미 검색 작업을 촉진해요. SGLang의 아키텍처는 임베딩 모델 배포에서 더 나은 리소스 활용과 낮은 지연 시간을 가능하게 해요.
Warning 네이티브 인코더 임베딩 아키텍처와
google/embeddinggemma-300m는 자동으로 감지돼요. 디코더 스타일 임베딩 모델은--is-embedding이 필요하며, 모델이 요구할 때--trust-remote-code를 추가해요.
빠른 시작 (Quick Start)
서버 실행 (Launch Server)
sglang serve \
--model-path Qwen/Qwen3-Embedding-4B \
--is-embedding
EmbeddingGemma
EmbeddingGemma는 양방향 어텐션(bidirectional attention)을 사용하며 자동 감지되므로, 최적의 기본 명령은 단순히:
sglang serve --model-path google/embeddinggemma-300m
CUDA에서 SGLang은 전체 인코더 prefill에 분리 가능한 CUDA 그래프(BCG, breakable CUDA graph)를 자동으로 사용하고, 호환되지 않는 radix-cache와 chunked-prefill 동작을 비활성화해요. 폐기된 piecewise CUDA 그래프 knob을 추가하지 마세요.
클라이언트 요청 (Client Request)
import requests
url = "http://127.0.0.1:30000"
payload = {
"model": "Qwen/Qwen3-Embedding-4B",
"input": "What is the capital of France?",
"encoding_format": "float" # or "base64" for compact FP32 responses
}
response = requests.post(url + "/v1/embeddings", json=payload).json()
print("Embedding:", response["data"][0]["embedding"])
멀티모달 임베딩 예시 (Multimodal Embedding Example)
텍스트와 이미지를 모두 지원하는 GME 같은 멀티모달 모델의 경우:
sglang serve \
--model-path Alibaba-NLP/gme-Qwen2-VL-2B-Instruct \
--is-embedding \
--chat-template gme-qwen2-vl
import requests
url = "http://127.0.0.1:30000"
text_input = "Represent this image in embedding space."
image_path = "https://huggingface.co/datasets/liuhaotian/llava-bench-in-the-wild/resolve/main/images/023.jpg"
payload = {
"model": "gme-qwen2-vl",
"input": [
{
"text": text_input
},
{
"image": image_path
}
],
}
response = requests.post(url + "/v1/embeddings", json=payload).json()
print("Embeddings:", [x.get("embedding") for x in response.get("data", [])])
Matryoshka 임베딩 예시 (Matryoshka Embedding Example)
Matryoshka Embeddings 또는 Matryoshka Representation Learning (MRL)은 임베딩 모델 훈련에 사용되는 기법이에요. 사용자가 성능과 비용 사이에서 트레이드오프를 할 수 있게 해줘요.
1. Matryoshka 지원 모델 실행 (Launch a Matryoshka‑capable model)
모델 구성에 이미 matryoshka_dimensions 또는 is_matryoshka가 있으면 오버라이드가 필요 없어요. 그렇지 않으면 아래처럼 --json-model-override-args를 사용할 수 있어요:
sglang serve \
--model-path Qwen/Qwen3-Embedding-0.6B \
--is-embedding \
--json-model-override-args '{"matryoshka_dimensions": [128, 256, 512, 1024, 1536]}'
"is_matryoshka": true로 설정하면 임의의 차원으로 자르기(truncating)가 허용돼요. 그렇지 않으면 서버는 요청에서 지정한 차원이matryoshka_dimensions중 하나인지 검증해요.- 요청에서
dimensions를 생략하면 전체 벡터를 반환해요.
2. 서로 다른 출력 차원으로 요청하기 (Make requests with different output dimensions)
import requests
url = "http://127.0.0.1:30000"
# Request a truncated (Matryoshka) embedding by specifying a supported dimension.
payload = {
"model": "Qwen/Qwen3-Embedding-0.6B",
"input": "Explain diffusion models simply.",
"dimensions": 512 # change to 128 / 1024 / omit for full size
}
response = requests.post(url + "/v1/embeddings", json=payload).json()
print("Embedding:", response["data"][0]["embedding"])
지원 모델 (Supported Models)
| Model Family | Example Model | Chat template | Description |
|---|---|---|---|
| EmbeddingGemma | google/embeddinggemma-300m |
N/A | 양방향 Gemma3 텍스트 인코더; 자동 감지되며 기본적으로 BCG로 서빙 |
| E5 (Llama/Mistral based) | intfloat/e5-mistral-7b-instruct |
N/A | Mistral/Llama 아키텍처 기반 고품질 텍스트 임베딩 |
| GTE-Qwen2 | Alibaba-NLP/gte-Qwen2-7B-instruct |
N/A | 다국어 지원을 갖춘 Alibaba의 텍스트 임베딩 모델 |
| Qwen3-Embedding | Qwen/Qwen3-Embedding-4B |
N/A | 의미 표현을 위한 최신 Qwen3 기반 텍스트 임베딩 모델 |
| Qwen3 (bare backbone) | microsoft/harrier-oss-v1-0.6b |
N/A | LM 헤드가 없는 베어 Qwen3Model 백본; SGLang의 융합 Qwen3 커널에서 네이티브 서빙되며 임베딩 모델로 자동 분류 |
| BGE | BAAI/bge-large-en-v1.5 |
N/A | BAAI의 텍스트 임베딩 (attention-backend triton/torch_native 필요) |
| GME (Multimodal) | Alibaba-NLP/gme-Qwen2-VL-2B-Instruct |
gme-qwen2-vl |
텍스트와 이미지 크로스모달 작업을 위한 멀티모달 임베딩 |
| CLIP | openai/clip-vit-large-patch14-336 |
N/A | 이미지와 텍스트 임베딩용 OpenAI의 CLIP |