임베딩 엔드포인트
임베딩 엔드포인트 (Embeddings Endpoints)
Embeddings API입니다. 텍스트를 고차원 벡터(임베딩)로 변환해 주는 엔드포인트를 소개할게요.
출처: 문서
본문
문장을 벡터로 바꿔서 검색·유사도 계산 등에 활용하고 싶을 때 쓰는 API예요. mistral-embed 같은 모델에 입력을 넣으면 벡터 배열이 나옵니다.
POST /v1/embeddings — Embeddings (임베딩 생성)
입력 텍스트를 임베딩 벡터로 변환합니다.
요청 본문:
input#string|array<string>(필수) — 임베딩할 텍스트.model#string(필수) — 사용할 모델의 ID.encoding_format#"float"|"base64"— 인코딩 포맷.output_dimension#integer|null— 출력 임베딩의 차원. 기능이 지원되는 모델에서 사용하며, 지정하지 않으면 기본 차원을 사용해요.output_dtype#"float"|"int8"|"uint8"|"binary"|"ubinary"— 출력 데이터 타입.metadata#map<any>|null— 메타데이터.
응답 필드 (200 Successful Response):
data#array<EmbeddingResponseData>(필수) — 임베딩 결과 배열.id#string(필수)model#string(필수)object#string(필수)usage#UsageInfo(필수) — 토큰 사용량 정보.
TypeScript:
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: proces...EY"] ?? "",
});
async function run() {
const result = await mistral.embeddings.create({
model: "mistral-embed",
inputs: [
"Embed this sentence.",
"As well as this one.",
],
});
console.log(result);
}
run();
Python:
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.embeddings.create(model="mistral-embed", inputs=[
"Embed this sentence.",
"As well as this one.",
])
# Handle response
print(res)
curl:
curl https://api.mistral.ai/v1/embeddings \
-X POST \
-H 'Authorization: Bearer ***' \
-H 'Content-Type: application/json' \
-d '{
"input": "Your value",
"model": "mistral-embed"
}'
응답 예시 (200):
{
"data": [
{
"embedding": [
-0.016632080078125,
0.0701904296875,
0.03143310546875,
0.01309967041015625,
0.0202789306640625
],
"index": 0,
"object": "embedding"
},
{
"embedding": [
-0.0230560302734375,
0.039337158203125,
0.0521240234375,
-0.0184783935546875,
0.034271240234375
],
"index": 1,
"object": "embedding"
}
],
"model": "mistral-embed",
"object": "list",
"usage": {
"prompt_tokens": 15,
"completion_tokens": 0,
"total_tokens": 15,
"prompt_audio_seconds": null
}
}
더 알아보기 (Learn more)
- Embeddings Endpoints — 공식 API 문서
- Embeddings — 임베딩 활용 가이드