Skip to content

임베딩은 텍스트를 수치 벡터로 변환하여 벡터 데이터베이스에 저장하거나, 코사인 유사도로 검색하거나, RAG 파이프라인에서 사용할 수 있습니다. 벡터 길이는 모델에 따라 다르며(일반적으로 384~1024 차원)입니다.

권장 모델

임베딩 생성

CLI

명령줄에서 직접 임베딩을 생성할 수 있습니다:

```shell
ollama run embeddinggemma "Hello world"
```

텍스트를 파이프하여 임베딩을 생성할 수도 있습니다:

```shell
echo "Hello world" | ollama run embeddinggemma
```

출력은 JSON 배열입니다.

cURL

```shell
curl -X POST http://localhost:11434/api/embed \
  -H "Content-Type: application/json" \
  -d '{
    "model": "embeddinggemma",
    "input": "The quick brown fox jumps over the lazy dog."
  }'
```

Python

```python
import ollama

single = ollama.embed(
  model='embeddinggemma',
  input='The quick brown fox jumps over the lazy dog.'
)
print(len(single['embeddings'][0]))  # vector length
```

JavaScript

```javascript
import ollama from 'ollama'

const single = await ollama.embed({
  model: 'embeddinggemma',
  input: 'The quick brown fox jumps over the lazy dog.',
})
console.log(single.embeddings[0].length) // vector length
```

Note

/api/embed 엔드포인트는 L2 정규화(단위 길이) 벡터를 반환합니다.

배치 임베딩 생성

input에 문자열 배열을 전달하세요.

cURL

```shell
curl -X POST http://localhost:11434/api/embed \
  -H "Content-Type: application/json" \
  -d '{
    "model": "embeddinggemma",
    "input": [
      "First sentence",
      "Second sentence",
      "Third sentence"
    ]
  }'
```

Python

```python
import ollama

batch = ollama.embed(
  model='embeddinggemma',
  input=[
    'The quick brown fox jumps over the lazy dog.',
    'The five boxing wizards jump quickly.',
    'Jackdaws love my big sphinx of quartz.',
  ]
)
print(len(batch['embeddings']))  # number of vectors
```

JavaScript

```javascript
import ollama from 'ollama'

const batch = await ollama.embed({
  model: 'embeddinggemma',
  input: [
    'The quick brown fox jumps over the lazy dog.',
    'The five boxing wizards jump quickly.',
    'Jackdaws love my big sphinx of quartz.',
  ],
})
console.log(batch.embeddings.length) // number of vectors
```

  • 대부분의 시맨틱 검색 사용 사례에서 코사인 유사도를 사용하세요.
  • 인덱싱과 쿼리 모두에 동일한 임베딩 모델을 사용하세요.