embed

package
v0.0.0-...-edaca3c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AvailableLocalEmbedders

func AvailableLocalEmbedders() []string

func CategoryTexts

func CategoryTexts(ctx context.Context, embedder ai.Embeddings, texts []string) ([][]float32, error)

func DocumentTexts

func DocumentTexts(ctx context.Context, embedder ai.Embeddings, texts []string) ([][]float32, error)

func NewFromName

func NewFromName(name string, dim int) (ai.Embeddings, error)

NewFromName creates an embedder using the configured provider/model name. It is intentionally lightweight and self-contained so callers can construct a concrete embedder without needing a separate factory callback.

func NewKelindarEmbedder

func NewKelindarEmbedder(modelPath string, gpuLayers int) (ai.Embeddings, error)

NewKelindarEmbedder creates a reusable local embedder for the Kelindar/Nomic stack.

The helper is intentionally small and reusable from client code because the broader KnowledgeBase flow expects any ai.Embeddings implementation.

func NewProfiledEmbedder

func NewProfiledEmbedder(base ai.Embeddings, profile EmbeddingProfile) ai.Embeddings

func NormalizeVector

func NormalizeVector(v []float32) []float32

func QueryTexts

func QueryTexts(ctx context.Context, embedder ai.Embeddings, texts []string) ([][]float32, error)

func RegisterLocalEmbedder

func RegisterLocalEmbedder(name string, factory LocalEmbedderFactory)

Types

type AgentEmbedder

type AgentEmbedder[T any] struct {
	// contains filtered or unexported fields
}

AgentEmbedder wraps an AI Agent to use its understanding for embedding. It asks the agent to "summarize" or "extract concepts" from the text, and then embeds those concepts using a base embedder (like Simple).

func NewAgentEmbedder

func NewAgentEmbedder[T any](agent ai.Agent[T], base ai.Embeddings, instruction string) *AgentEmbedder[T]

NewAgentEmbedder creates a new embedder that uses an agent to preprocess text.

func (*AgentEmbedder[T]) Agent

func (ae *AgentEmbedder[T]) Agent() ai.Agent[T]

Agent returns the underlying agent used for embedding.

func (*AgentEmbedder[T]) Dim

func (ae *AgentEmbedder[T]) Dim() int

Dim returns the dimension of the embeddings.

func (*AgentEmbedder[T]) EmbedTexts

func (ae *AgentEmbedder[T]) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

EmbedTexts generates embeddings for the given texts. It first enhances the texts using the agent, then embeds the enhanced texts using the base embedder.

func (*AgentEmbedder[T]) Name

func (ae *AgentEmbedder[T]) Name() string

Name returns the name of the embedder.

type EmbeddingProfile

type EmbeddingProfile struct {
	ModelName          string
	DisplayName        string
	MaxContextTokens   int
	SupportsMatryoshka bool
	RoutingDim         int
	DocumentDim        int
	RoutingPrefix      string
	DocStorePrefix     string
	DocQueryPrefix     string
}

EmbeddingProfile captures the model-specific routing/document contract.

type GeminiEmbedder

type GeminiEmbedder struct {
	// contains filtered or unexported fields
}

GeminiEmbedder connects to the Google Generative Language API to generate semantic embeddings.

func NewGemini

func NewGemini(apiKey, model string) *GeminiEmbedder

NewGemini creates a new Google Gemini embedder.

func (*GeminiEmbedder) Dim

func (e *GeminiEmbedder) Dim() int

func (*GeminiEmbedder) EmbedTexts

func (e *GeminiEmbedder) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

EmbedTexts generates embeddings for a batch of strings via Google's Gemini API.

func (*GeminiEmbedder) Name

func (e *GeminiEmbedder) Name() string

type Local

type Local struct {
	// contains filtered or unexported fields
}

func NewLocal

func NewLocal(modelPath string, gpuLayers int) (*Local, error)

func NewLocalWithProvider

func NewLocalWithProvider(providerName, modelPath string, gpuLayers int) (*Local, error)

func (*Local) Close

func (e *Local) Close() error

func (*Local) Dim

func (e *Local) Dim() int

func (*Local) EmbedCategoryTexts

func (e *Local) EmbedCategoryTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*Local) EmbedDocumentTexts

func (e *Local) EmbedDocumentTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*Local) EmbedQueryTexts

func (e *Local) EmbedQueryTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*Local) EmbedTexts

func (e *Local) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*Local) Name

func (e *Local) Name() string

type LocalEmbedderFactory

type LocalEmbedderFactory func(modelPath string, gpuLayers int) (localVectorizer, error)

type OllamaEmbedder

type OllamaEmbedder struct {
	// contains filtered or unexported fields
}

OllamaEmbedder uses a local Ollama instance to generate semantic embeddings.

func NewOllama

func NewOllama(baseURL, model string) *OllamaEmbedder

NewOllama creates a new Ollama embedder.

func (*OllamaEmbedder) Dim

func (e *OllamaEmbedder) Dim() int

func (*OllamaEmbedder) EmbedTexts

func (e *OllamaEmbedder) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

EmbedTexts generates embeddings for the given texts using the Ollama API.

func (*OllamaEmbedder) Name

func (e *OllamaEmbedder) Name() string

type OpenAIEmbedder

type OpenAIEmbedder struct {
	// contains filtered or unexported fields
}

OpenAIEmbedder uses the OpenAI embeddings API or a compatible relay.

func NewOpenAI

func NewOpenAI(apiKey, model, baseURL string) *OpenAIEmbedder

NewOpenAI creates a new OpenAI-compatible embedder.

func (*OpenAIEmbedder) Dim

func (e *OpenAIEmbedder) Dim() int

func (*OpenAIEmbedder) EmbedTexts

func (e *OpenAIEmbedder) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

EmbedTexts generates embeddings using the OpenAI embeddings API.

func (*OpenAIEmbedder) Name

func (e *OpenAIEmbedder) Name() string

type ProfiledEmbedder

type ProfiledEmbedder struct {
	// contains filtered or unexported fields
}

ProfiledEmbedder wraps any ai.Embeddings with explicit category/document/query modes.

func (*ProfiledEmbedder) Dim

func (p *ProfiledEmbedder) Dim() int

func (*ProfiledEmbedder) EmbedCategoryTexts

func (p *ProfiledEmbedder) EmbedCategoryTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ProfiledEmbedder) EmbedDocumentTexts

func (p *ProfiledEmbedder) EmbedDocumentTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ProfiledEmbedder) EmbedQueryTexts

func (p *ProfiledEmbedder) EmbedQueryTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ProfiledEmbedder) EmbedTexts

func (p *ProfiledEmbedder) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ProfiledEmbedder) Name

func (p *ProfiledEmbedder) Name() string

type ResilientEmbedder

type ResilientEmbedder struct {
	// contains filtered or unexported fields
}

ResilientEmbedder wraps an existing Embeddings model automatically backing off and retrying in case of network or API limit errors.

func NewResilientEmbedder

func NewResilientEmbedder(base ai.Embeddings) *ResilientEmbedder

NewResilientEmbedder creates a ResilientEmbedder wrapping base Embeddings.

func (*ResilientEmbedder) Dim

func (r *ResilientEmbedder) Dim() int

func (*ResilientEmbedder) EmbedCategoryTexts

func (r *ResilientEmbedder) EmbedCategoryTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ResilientEmbedder) EmbedDocumentTexts

func (r *ResilientEmbedder) EmbedDocumentTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ResilientEmbedder) EmbedQueryTexts

func (r *ResilientEmbedder) EmbedQueryTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ResilientEmbedder) EmbedTexts

func (r *ResilientEmbedder) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ResilientEmbedder) Name

func (r *ResilientEmbedder) Name() string

type Simple

type Simple struct {
	// contains filtered or unexported fields
}

Simple is a naive bag-of-words hashing embedder with configurable synonym heuristics.

func NewSimple

func NewSimple(name string, dim int, synonyms map[string]string) *Simple

NewSimple creates a new embedder with optional custom synonyms. If synonyms is nil, it defaults to an empty map (no heuristics).

func (*Simple) Dim

func (s *Simple) Dim() int

Dim returns the dimension of the embeddings.

func (*Simple) EmbedTexts

func (s *Simple) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

EmbedTexts generates embeddings for the given texts using a bag-of-words hashing approach.

func (*Simple) Name

func (s *Simple) Name() string

Name returns the name of the embedder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL