Skip to main content

Integrations: Embeddings

LangChainGo produces embeddings in two ways. Either way you get an embeddings.Embedder with EmbedDocuments(ctx, texts) and EmbedQuery(ctx, text), ready to pass to a vector store.

Using an LLM client

Providers whose LLM client can also embed satisfy embeddings.EmbedderClient; wrap the client with embeddings.NewEmbedder to get a full Embedder:

import (
"github.com/vxcontrol/langchaingo/embeddings"
"github.com/vxcontrol/langchaingo/llms/openai"
)

llm, err := openai.New()
embedder, err := embeddings.NewEmbedder(llm)

vectors, err := embedder.EmbedDocuments(ctx, []string{"hello", "world"})

The same NewEmbedder(client) pattern works with:

ClientPackage
OpenAIllms/openai
Google Geminillms/googleai
Vertex AIllms/googleai/vertex
Ollamallms/ollama

Dedicated embedding providers

These packages under embeddings/ implement embeddings.Embedder directly — use their constructor, no NewEmbedder wrapper needed:

import "github.com/vxcontrol/langchaingo/embeddings/voyageai"

// Reads VOYAGEAI_API_KEY from the environment; default model "voyage-4".
embedder, err := voyageai.NewVoyageAI(voyageai.WithModel("voyage-4"))
ProviderConstructorAuth / notes
AWS Bedrockbedrock.NewBedrock(...)AWS credentials; default model Titan Embeddings G1
VoyageAIvoyageai.NewVoyageAI(...)VOYAGEAI_API_KEY
Jinajina.NewJina(...)JINA_API_KEY; default jina-embeddings-v2-small-en
Hugging Facehuggingface.NewHuggingface(...)Hugging Face inference API; default BAAI/bge-small-en-v1.5
Cybertroncybertron.NewCybertron(...)Fully local (no API key); downloads the model on first use

Common options on these constructors include WithModel, WithBatchSize, and (where applicable) WithAPIKey / WithToken.

For more on using embeddings with vector stores, see the Embeddings documentation and Vector stores.