Skip to content
Docs

Ollama Embedding Provider

The Ollama embedding provider implements the embedding.Embedder interface using the Ollama REST API. It enables fully local embedding generation with no external API dependencies, making it suitable for development, testing, and privacy-sensitive deployments.

Choose Ollama embeddings for local development, offline environments, or when data cannot leave your network. Running embeddings locally eliminates API costs and network latency, making it well-suited for iterating on RAG pipelines during development. For production, consider cloud providers for higher throughput.

Terminal window
go get github.com/lookatitude/beluga-ai/rag/embedding/providers/ollama

Ensure Ollama is running locally:

Terminal window
# Install Ollama (see https://ollama.ai)
ollama pull nomic-embed-text
ollama serve
package main
import (
"context"
"fmt"
"log"
"github.com/lookatitude/beluga-ai/config"
"github.com/lookatitude/beluga-ai/rag/embedding"
_ "github.com/lookatitude/beluga-ai/rag/embedding/providers/ollama"
)
func main() {
emb, err := embedding.New("ollama", config.ProviderConfig{})
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
vec, err := emb.EmbedSingle(ctx, "Beluga AI is a Go framework for agentic systems")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Vector length: %d\n", len(vec))
fmt.Printf("Dimensions: %d\n", emb.Dimensions())
}
ParameterTypeDefaultDescription
Modelstringnomic-embed-textOllama model name
BaseURLstringhttp://localhost:11434Ollama server URL
Timeouttime.Duration0 (no timeout)Request timeout
Options["dimensions"]float64Model-dependentOverride vector dimensions
ModelDefault Dimensions
nomic-embed-text768
mxbai-embed-large1024
all-minilm384
snowflake-arctic-embed1024

Any model available in Ollama that supports the embed API can be used. Pull the model first with ollama pull <model>.

import (
ollamaemb "github.com/lookatitude/beluga-ai/rag/embedding/providers/ollama"
)
emb, err := ollamaemb.New(config.ProviderConfig{
BaseURL: "http://localhost:11434",
Model: "mxbai-embed-large",
})
if err != nil {
log.Fatal(err)
}

Connect to a remote Ollama instance by specifying the base URL:

emb, err := embedding.New("ollama", config.ProviderConfig{
BaseURL: "http://gpu-server.internal:11434",
Model: "nomic-embed-text",
})

The Ollama provider processes batch requests sequentially, embedding one text at a time via the /api/embed endpoint. For high-throughput scenarios, consider using a cloud-based provider that supports native batch embedding.