임베딩 생성하기
임베딩 생성하기 (Generate embeddings)
입력 텍스트를 나타내는 벡터 임베딩을 생성합니다.
/api/embed 엔드포인트는 입력 텍스트를 벡터 임베딩으로 만들어 줍니다. 아래는 Ollama HTTP API의 OpenAPI 명세 기준으로, 요청과 응답 각각의 필드를 살펴볼 수 있어요.
출처: 공식문서
기본 요청
모델 이름과 임베딩할 텍스트만 넘기면 됩니다.
curl http://localhost:11434/api/embed -d '{
"model": "embeddinggemma",
"input": "Why is the sky blue?"
}'
여러 입력을 한 번에 보낼 수도 있어요.
curl http://localhost:11434/api/embed -d '{
"model": "embeddinggemma",
"input": [
"Why is the sky blue?",
"Why is the grass green?"
]
}'
주요 요청 필드
model(string, 필수) — 임베딩을 생성할 모델 이름input(string 또는 string 배열, 필수) — 임베딩을 생성할 텍스트(또는 텍스트 배열)truncate(boolean, 기본true) —true면 컨텍스트 윈도우를 초과하는 입력을 잘라내고,false면 오류를 반환합니다.dimensions(integer) — 생성할 임베딩의 차원 수keep_alive(string) — 모델 유지(keep-alive) 시간options— 텍스트 생성을 제어하는 런타임 옵션(seed,temperature,top_k,top_p,min_p,stop,num_ctx,num_predict등)
자르기(truncation)와 차원 지정 예시를 보면 이렇게 보냅니다.
curl http://localhost:11434/api/embed -d '{
"model": "embeddinggemma",
"input": "Generate embeddings for this text",
"truncate": true
}'
curl http://localhost:11434/api/embed -d '{
"model": "embeddinggemma",
"input": "Generate embeddings for this text",
"dimensions": 128
}'
응답 필드
model(string) — 임베딩을 생성한 모델embeddings(array) — 벡터 임베딩의 배열. 각 원소는 숫자 배열입니다.total_duration(integer) — 생성에 쓴 총 시간(나노초)load_duration(integer) — 모델 로드 시간(나노초)prompt_eval_count(integer) — 임베딩 생성에 처리한 입력 토큰 수
응답 예시(일부 벡터 값만 표기):
{
"model": "embeddinggemma",
"embeddings": [
[0.010071029, -0.0017594862, 0.05007221, 0.04692972, ...]
],
"total_duration": 14143917,
"load_duration": 1019500,
"prompt_eval_count": 8
}
더 알아보기 (Learn more)
- Embeddings — CLI·SDK로 임베딩 생성하기