Skip to content
Docs

Voyage AI Embedding Provider

The Voyage AI embedding provider implements the embedding.Embedder interface using the Voyage Embed API. Voyage models are optimized for retrieval tasks and support input type differentiation for asymmetric search.

Choose Voyage embeddings when retrieval quality is critical, especially for code search (voyage-code-2) or when you need asymmetric document/query embeddings. Voyage models consistently rank highly on retrieval benchmarks and offer specialized models for code, legal, and financial domains.

Terminal window
go get github.com/lookatitude/beluga-ai/rag/embedding/providers/voyage
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/lookatitude/beluga-ai/config"
"github.com/lookatitude/beluga-ai/rag/embedding"
_ "github.com/lookatitude/beluga-ai/rag/embedding/providers/voyage"
)
func main() {
emb, err := embedding.New("voyage", config.ProviderConfig{
APIKey: os.Getenv("VOYAGE_API_KEY"),
})
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
APIKeystring(required)Voyage AI API key
Modelstringvoyage-2Embedding model name
BaseURLstringhttps://api.voyageai.com/v1API base URL
Timeouttime.Duration0 (no timeout)Request timeout
Options["input_type"]stringdocumentInput type for embedding
Options["dimensions"]float64Model-dependentOverride vector dimensions
ModelDefault Dimensions
voyage-21024
voyage-large-21536
voyage-code-21536
voyage-lite-02-instruct1024
voyage-31024
voyage-3-lite512

Voyage supports input type differentiation for asymmetric retrieval. Set the input_type option accordingly:

  • document (default) — Use when embedding documents for storage
  • query — Use when embedding queries for retrieval
// Embed documents for storage
docEmb, err := embedding.New("voyage", config.ProviderConfig{
APIKey: os.Getenv("VOYAGE_API_KEY"),
Options: map[string]any{
"input_type": "document",
},
})
// Embed queries for retrieval
queryEmb, err := embedding.New("voyage", config.ProviderConfig{
APIKey: os.Getenv("VOYAGE_API_KEY"),
Options: map[string]any{
"input_type": "query",
},
})
import (
voyageemb "github.com/lookatitude/beluga-ai/rag/embedding/providers/voyage"
)
emb, err := voyageemb.New(config.ProviderConfig{
APIKey: os.Getenv("VOYAGE_API_KEY"),
Model: "voyage-code-2",
Options: map[string]any{
"input_type": "document",
},
})
if err != nil {
log.Fatal(err)
}

Voyage’s voyage-code-2 model is specifically tuned for code retrieval tasks:

emb, err := embedding.New("voyage", config.ProviderConfig{
APIKey: os.Getenv("VOYAGE_API_KEY"),
Model: "voyage-code-2",
})
if err != nil {
log.Fatal(err)
}
vectors, err := emb.Embed(ctx, []string{
"func main() { fmt.Println(\"hello\") }",
"def main(): print('hello')",
})