embeddings

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache provides content-hash-based caching for embeddings

func NewCache

func NewCache(dir string, logger *slog.Logger) (*Cache, error)

NewCache creates a new embedding cache

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes all cached embeddings

func (*Cache) Delete

func (c *Cache) Delete(hash string) error

Delete removes an embedding from cache

func (*Cache) Get

func (c *Cache) Get(hash string) ([]float32, bool)

Get retrieves an embedding from cache by content hash Returns the embedding and true if found, nil and false otherwise

func (*Cache) Set

func (c *Cache) Set(hash string, embedding []float32) error

Set stores an embedding in cache by content hash

type EmbeddingResult

type EmbeddingResult struct {
	Text      string    `json:"text"`
	Embedding []float32 `json:"embedding"`
	Model     string    `json:"model"`
}

EmbeddingResult contains the result of an embedding operation

type OpenAIConfig

type OpenAIConfig struct {
	APIKey     string
	Model      string
	Dimensions int
}

OpenAIConfig contains configuration for the OpenAI provider

func DefaultOpenAIConfig

func DefaultOpenAIConfig() OpenAIConfig

DefaultOpenAIConfig returns default configuration for OpenAI provider

type OpenAIProvider

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

OpenAIProvider implements the Provider interface using OpenAI's embedding API

func NewOpenAIProvider

func NewOpenAIProvider(config OpenAIConfig, logger *slog.Logger) (*OpenAIProvider, error)

NewOpenAIProvider creates a new OpenAI embedding provider

func (*OpenAIProvider) Dimensions

func (p *OpenAIProvider) Dimensions() int

Dimensions returns the number of dimensions in the embedding vector

func (*OpenAIProvider) Embed

func (p *OpenAIProvider) Embed(ctx context.Context, text string) ([]float32, error)

Embed generates an embedding vector for a single text

func (*OpenAIProvider) EmbedBatch

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

EmbedBatch generates embedding vectors for multiple texts

func (*OpenAIProvider) Model

func (p *OpenAIProvider) Model() string

Model returns the model name being used

type Provider

type Provider interface {
	// Embed generates an embedding vector for a single text
	Embed(ctx context.Context, text string) ([]float32, error)

	// EmbedBatch generates embedding vectors for multiple texts
	// This is more efficient than calling Embed multiple times
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

	// Dimensions returns the number of dimensions in the embedding vector
	Dimensions() int

	// Model returns the model name being used
	Model() string
}

Provider defines the interface for embedding generation

Jump to

Keyboard shortcuts

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