Skip to content

Gömme vektörleri, metni sayısal vektörlere dönüştürür; bu vektörleri bir vektör veritabanında saklayabilir, kosinüs benzerliği ile arayabilir veya RAG pipeline'larında kullanabilirsiniz. Vektör uzunluğu modele bağlıdır (genellikle 384–1024 boyut).

Önerilen modeller

Gömme vektörleri oluşturma

CLI

Gömme vektörlerini doğrudan komut satırından oluşturun:

shell
ollama run embeddinggemma "Hello world"

Ayrıca metni boru hattı (pipe) kullanarak gömme vektörleri oluşturabilirsiniz:

shell
echo "Hello world" | ollama run embeddinggemma

Çıktı bir JSON dizisidir.

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]))  # vektör uzunluğu

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) // vektör uzunluğu

Not

/api/embed uç noktası L2‑normlanmış (birim uzunluklu) vektörler döndürür.

Toplu gömme vektörleri oluşturma

input parametresine bir string dizisi gönderin.

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']))  # vektör sayısı

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) // vektör sayısı

İpuçları

  • Çoğu semantik arama kullanım durumu için kosinüs benzerliğini kullanın.
  • Hem indeksleme hem de sorgulama için aynı gömme vektör modelini kullanın.