Skip to content

RAG embed

Embedding turns each *rag.Chunk from the upstream chunk stage into a fixed-dimension vector, and turns each query string from retrieve into a vector compatible with the vector store. The package defines a single embed.Embedder interface implemented by eleven providers, plus a multimodal interface for text+image+audio. A provider registry resolves a config block (provider, model, api_key, base_url, batch_size, timeout_seconds) into an Embedder via embed.NewEmbedder(config).

Every provider auto-batches its inputs against the API's per-request limit and re-orders responses by index. None of them sit on a separate Go SDK — each is a direct HTTP client so a provider outage doesn't cascade.

Embedder interface

type Embedder interface {
    Embed(ctx, texts []string) ([][]float32, error)
    EmbedSingle(ctx, text string) ([]float32, error)
    Dimensions() int
    Provider() string
    Model() string
}

MultimodalEmbedder adds EmbedImage and EmbedImages.

Providers

openai — OpenAI Embeddings API

rag:
  embed:
    provider: openai
    model: text-embedding-3-small
    api_key: ${OPENAI_API_KEY}
Field Type Default Description
model string text-embedding-3-small Also supports text-embedding-3-large (3072d), text-embedding-ada-002.
api_key string — Required.
base_url string https://api.openai.com/v1 Override for self-hosted compatible APIs.
batch_size int 2048 Inputs per request.
timeout_seconds int 60 HTTP timeout.

Dimensions: 1536 (-3-small, ada-002) or 3072 (-3-large). The default for most production RAG. Source: pkg/rag/embed/openai.go.

cohere — Cohere Embed API

rag:
  embed:
    provider: cohere
    model: embed-v4.0
    api_key: ${COHERE_API_KEY}
Field Type Default Description
model string embed-v4.0 Also embed-english-v3.0, embed-multilingual-v3.0 (1024d), embed-english-light-v3.0 (384d).
api_key string — Required.

Batch size 96. Multilingual variant supports 100+ languages. Embedder defaults to search_document input type; call SetInputType("search_query") in code when embedding a query (the DSL's retrieve stage does not yet flip this — file an issue if you need it). Source: pkg/rag/embed/cohere.go.

huggingface — HuggingFace Inference API

rag:
  embed:
    provider: huggingface
    model: BAAI/bge-large-en-v1.5
    api_key: ${HF_TOKEN}
Field Type Default Description
model string BAAI/bge-large-en-v1.5 Also: bge-base (768d), bge-small (384d), all-MiniLM-L6-v2 (384d), all-mpnet-base-v2 (768d).
api_key string — Required.

Batch size 64, 120s timeout (cold models can be slow). Use for any sentence-transformer hosted on HF. Source: pkg/rag/embed/huggingface.go.

rag:
  embed:
    provider: voyage
    model: voyage-3
    api_key: ${VOYAGE_API_KEY}
Field Type Default Description
model string voyage-3 Also voyage-3-large, voyage-3-lite (512d), voyage-code-3 for code.

Batch size 128. The same factory is also registered under provider: anthropic (Anthropic doesn't ship its own embeddings API and recommends Voyage). Use voyage-code-3 when indexing source code. Source: pkg/rag/embed/voyage.go.

bedrock — AWS Bedrock (Titan + Cohere on AWS)

rag:
  embed:
    provider: bedrock
    model: amazon.titan-embed-text-v2:0
    api_key: AKIA...:secretKey      # or AKIA...:secretKey:sessionToken
    base_url: us-east-1
Field Type Default Description
model string amazon.titan-embed-text-v2:0 Also titan-embed-text-v1 (1536d), cohere.embed-english-v3, cohere.embed-multilingual-v3.
api_key string — accessKeyId:secretAccessKey[:sessionToken] — colon-separated.
base_url string us-east-1 AWS region.

Implements SigV4 signing in pure Go. No batching — sends one request per text (Bedrock Titan limitation). Source: pkg/rag/embed/bedrock.go.

vertex / gemini — Google Vertex / Gemini

rag:
  embed:
    provider: vertex
    model: text-embedding-004
    api_key: ${GOOGLE_API_KEY}
Field Type Default Description
model string text-embedding-004 Also embedding-001 (768d).

Batch size 100, uses Gemini's batchEmbedContents endpoint. Both provider: vertex and provider: gemini resolve to this. Source: pkg/rag/embed/vertex.go.

jina — Jina AI Embeddings

rag:
  embed:
    provider: jina
    model: jina-embeddings-v3
    api_key: ${JINA_API_KEY}
Field Type Default Description
model string jina-embeddings-v3 Also v2 base (768d), v2 small (512d).

Batch size 500. Strong multilingual performance. Source: pkg/rag/embed/jina.go.

mistral — Mistral Embeddings

rag:
  embed:
    provider: mistral
    model: mistral-embed
    api_key: ${MISTRAL_API_KEY}
Field Type Default Description
model string mistral-embed 1024d, currently the only model.

Batch size 512. Source: pkg/rag/embed/mistral.go.

nomic — Nomic Atlas Embeddings

rag:
  embed:
    provider: nomic
    model: nomic-embed-text-v1.5
    api_key: ${NOMIC_API_KEY}
Field Type Default Description
model string nomic-embed-text-v1.5 Also v1 (both 768d).

Batch size 400. Defaults to task_type: search_document; call SetTaskType("search_query") for query encoding. Source: pkg/rag/embed/nomic.go.

ollama — local Ollama server

rag:
  embed:
    provider: ollama
    model: nomic-embed-text
    base_url: http://localhost:11434
Field Type Default Description
model string nomic-embed-text Also mxbai-embed-large (1024d), all-minilm (384d), snowflake-arctic-embed (1024d).
base_url string http://localhost:11434 Local Ollama address.

No API key. One HTTP call per text (no batch endpoint). 120s timeout. The right choice when you want zero outbound network calls during ingest. Source: pkg/rag/embed/ollama.go.

clip — multimodal CLIP via REST

rag:
  embed:
    provider: clip
    model: clip-vit-large-patch14
    base_url: http://localhost:9090
    api_key: ${CLIP_API_KEY}
Field Type Default Description
model string — The CLIP variant served by your endpoint.
base_url string — OpenAI-compatible embeddings endpoint.
api_key string — Optional.

Constructed via embed.NewCLIPEmbedder(baseURL, apiKey, model, dimensions). Implements MultimodalEmbedder — call EmbedImage(data, mimeType) or EmbedImages([]ImageInput) to embed images in the same vector space as text. Use this when image search must work with the same store as text search. Source: pkg/rag/embed/multimodal.go.

Choosing between them

If you need… Pick
Best general-purpose quality openai text-embedding-3-large
Cost-optimized cloud openai text-embedding-3-small
Strong multilingual cohere embed-multilingual-v3.0, jina v3
Open-source / on-prem huggingface BAAI/bge-large-en-v1.5
Air-gapped / local ollama nomic-embed-text
Anthropic stack voyage voyage-3 (or voyage-code-3 for code)
AWS infrastructure bedrock amazon.titan-embed-text-v2:0
Google Cloud vertex text-embedding-004
Multimodal (text + image) clip

The vector store's Dimensions field must match the embedder's Dimensions(). Mixing models in one collection is unsupported — the embedder is part of the index's schema.

See also

  • chunk — produces the []*rag.Chunk this stage embeds.
  • store — accepts the []*rag.Embedding this stage emits.
  • retrieve — query-side embedder; must match the index-side.
  • Multimodal guide — CLIP and image/audio embedding patterns.