Documentation
¶
Index ¶
- func AvailableLocalEmbedders() []string
- func CategoryTexts(ctx context.Context, embedder ai.Embeddings, texts []string) ([][]float32, error)
- func DocumentTexts(ctx context.Context, embedder ai.Embeddings, texts []string) ([][]float32, error)
- func NewFromName(name string, dim int) (ai.Embeddings, error)
- func NewKelindarEmbedder(modelPath string, gpuLayers int) (ai.Embeddings, error)
- func NewProfiledEmbedder(base ai.Embeddings, profile EmbeddingProfile) ai.Embeddings
- func NormalizeVector(v []float32) []float32
- func QueryTexts(ctx context.Context, embedder ai.Embeddings, texts []string) ([][]float32, error)
- func RegisterLocalEmbedder(name string, factory LocalEmbedderFactory)
- type AgentEmbedder
- type EmbeddingProfile
- type GeminiEmbedder
- type Local
- func (e *Local) Close() error
- func (e *Local) Dim() int
- func (e *Local) EmbedCategoryTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (e *Local) EmbedDocumentTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (e *Local) EmbedQueryTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (e *Local) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (e *Local) Name() string
- type LocalEmbedderFactory
- type OllamaEmbedder
- type OpenAIEmbedder
- type ProfiledEmbedder
- func (p *ProfiledEmbedder) Dim() int
- func (p *ProfiledEmbedder) EmbedCategoryTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (p *ProfiledEmbedder) EmbedDocumentTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (p *ProfiledEmbedder) EmbedQueryTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (p *ProfiledEmbedder) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (p *ProfiledEmbedder) Name() string
- type ResilientEmbedder
- func (r *ResilientEmbedder) Dim() int
- func (r *ResilientEmbedder) EmbedCategoryTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (r *ResilientEmbedder) EmbedDocumentTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (r *ResilientEmbedder) EmbedQueryTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (r *ResilientEmbedder) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)
- func (r *ResilientEmbedder) Name() string
- type Simple
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AvailableLocalEmbedders ¶
func AvailableLocalEmbedders() []string
func CategoryTexts ¶
func DocumentTexts ¶
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 QueryTexts ¶
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 ¶
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 ¶
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 NewLocalWithProvider ¶
func (*Local) EmbedCategoryTexts ¶
func (*Local) EmbedDocumentTexts ¶
func (*Local) EmbedQueryTexts ¶
func (*Local) EmbedTexts ¶
type LocalEmbedderFactory ¶
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 ¶
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 ¶
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 (*ProfiledEmbedder) EmbedDocumentTexts ¶
func (*ProfiledEmbedder) EmbedQueryTexts ¶
func (*ProfiledEmbedder) EmbedTexts ¶
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 (*ResilientEmbedder) EmbedDocumentTexts ¶
func (*ResilientEmbedder) EmbedQueryTexts ¶
func (*ResilientEmbedder) EmbedTexts ¶
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 ¶
NewSimple creates a new embedder with optional custom synonyms. If synonyms is nil, it defaults to an empty map (no heuristics).
func (*Simple) EmbedTexts ¶
EmbedTexts generates embeddings for the given texts using a bag-of-words hashing approach.