Documentation
¶
Overview ¶
Package ollama implements the Embedder interface via Ollama's HTTP API. Useful when ONNX model files are unavailable (e.g. HuggingFace blocked) or when the user prefers Ollama's model management.
Prerequisites: Ollama running locally (ollama serve) with the desired model pulled (ollama pull bge-m3).
Usage:
ckv build --embedder=ollama --model-name=bge-m3 --src ./project
Index ¶
- Constants
- type Adapter
- func (a *Adapter) Close() error
- func (a *Adapter) Dimension() int
- func (a *Adapter) Embed(ctx context.Context, batch []string) ([][]float32, error)
- func (a *Adapter) EmbedQuery(ctx context.Context, queries []string) ([][]float32, error)
- func (a *Adapter) Identity() types.EmbeddingIdentity
- func (a *Adapter) MaxInputTokens() int
- func (a *Adapter) Name() string
- type Options
Constants ¶
const DefaultEndpoint = "http://localhost:11434"
DefaultEndpoint is the default Ollama API base URL. Override with CKV_OLLAMA_ENDPOINT environment variable.
const DefaultMaxInputTokens = 8192
DefaultMaxInputTokens is the fallback context limit for an Ollama model not present in the embedding registry. bge-m3's value; safe for BERT-family embedders that don't advertise a larger window.
const DefaultTimeout = 60 * time.Second
DefaultTimeout bounds every request to the Ollama daemon. Without it a wedged daemon (model loading, stuck GPU) that accepts the connection but never responds would block embed calls — and the startup probe — forever, hanging the build, the query path, and any consumer that opens the adapter at startup. A single embed of a chunk batch should be well under this.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements types.Embedder via Ollama's /api/embed endpoint.
func Open ¶
Open creates an Ollama adapter and verifies connectivity by embedding a test string to determine the output dimension.
func (*Adapter) EmbedQuery ¶
EmbedQuery embeds retrieval queries. For an asymmetric model (Qwen3, which carries a QueryInstruct in the registry) it wraps each query in the model's instruct prompt before embedding; symmetric models (bge-*) fall through to Embed unchanged. Passages always go through Embed. Implements types.QueryEmbedder.
func (*Adapter) Identity ¶
func (a *Adapter) Identity() types.EmbeddingIdentity
Identity reports the embedding space. Ollama performs tokenization and pooling internally and does not expose those, so Pooling/Normalize are left empty; Provider+Model+Dim still distinguish an Ollama-built index from one built by another backend (e.g. ONNX) for the same model name, which is the swap query.Open must reject.
func (*Adapter) MaxInputTokens ¶
type Options ¶
type Options struct {
Endpoint string // Ollama API URL (default: http://localhost:11434)
ModelName string // model name as known to Ollama (e.g. "bge-m3")
Timeout time.Duration // per-request timeout (default: DefaultTimeout); <=0 uses the default
// TargetDim, when >0 and smaller than the model's native dimension,
// truncates every embedding to its first TargetDim components and
// re-normalizes to unit length (Matryoshka Representation Learning). Used
// by Qwen3-Embedding, which is MRL-trained, to trade a little precision for
// a smaller vector (storage + search cost). 0 keeps the native dimension.
TargetDim int
}
Options configures the Ollama adapter.