embeddings

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 13 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 interface {
	// Get retrieves cached embeddings for texts
	Get(ctx context.Context, texts []string) ([][]float32, []bool, error)

	// Set stores embeddings for texts
	Set(ctx context.Context, texts []string, embeddings [][]float32) error

	// Clear removes all cached embeddings
	Clear(ctx context.Context) error

	// Close releases any resources used by the cache
	Close() error
}

Cache provides caching for embeddings to avoid regenerating them

type CachedModel

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

CachedModel wraps an embedding model with caching

func NewCachedModel

func NewCachedModel(model Model, cache Cache) *CachedModel

NewCachedModel creates a new cached embedding model

func (*CachedModel) Close

func (m *CachedModel) Close() error

Close implements Model.Close

func (*CachedModel) Dimension

func (m *CachedModel) Dimension() int

Dimension implements Model.Dimension

func (*CachedModel) Embed

func (m *CachedModel) Embed(ctx context.Context, texts []string) ([][]float32, error)

Embed implements Model.Embed with caching

type Config

type Config struct {
	Type    string                 `json:"type"`              // Type of embedding model
	Options map[string]interface{} `json:"options,omitempty"` // Model-specific options
}

Config holds configuration for embedding models

type LocalModel

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

LocalModel implements Model using a simple hashing-based approach This is only for testing and should not be used in production

func (*LocalModel) Close

func (m *LocalModel) Close() error

Close implements Model.Close

func (*LocalModel) Dimension

func (m *LocalModel) Dimension() int

Dimension implements Model.Dimension

func (*LocalModel) Embed

func (m *LocalModel) Embed(ctx context.Context, texts []string) ([][]float32, error)

Embed implements Model.Embed

type MemoryCache

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

MemoryCache provides in-memory caching for embeddings

func NewMemoryCache

func NewMemoryCache() *MemoryCache

NewMemoryCache creates a new in-memory cache

func (*MemoryCache) Clear

func (c *MemoryCache) Clear(ctx context.Context) error

Clear implements Cache.Clear

func (*MemoryCache) Close

func (c *MemoryCache) Close() error

Close implements Cache.Close

func (*MemoryCache) Get

func (c *MemoryCache) Get(ctx context.Context, texts []string) ([][]float32, []bool, error)

Get implements Cache.Get

func (*MemoryCache) Set

func (c *MemoryCache) Set(ctx context.Context, texts []string, embeddings [][]float32) error

Set implements Cache.Set

type Model

type Model interface {
	// Embed generates embeddings for the given texts
	Embed(ctx context.Context, texts []string) ([][]float32, error)

	// Dimension returns the dimension of the embeddings
	Dimension() int

	// Close releases any resources used by the model
	Close() error
}

Model represents a text embedding model

func NewLocalModel

func NewLocalModel(ctx context.Context, config Config) (Model, error)

NewLocalModel creates a new local embedding model

func NewModel

func NewModel(ctx context.Context, config Config) (Model, error)

NewModel creates a new embedding model based on config

func NewOpenAIModel

func NewOpenAIModel(ctx context.Context, config Config) (Model, error)

NewOpenAIModel creates a new OpenAI embedding model

func NewVertexAIModel

func NewVertexAIModel(ctx context.Context, config Config) (Model, error)

NewVertexAIModel creates a new Vertex AI embedding model

type ModelType

type ModelType string

ModelType represents supported embedding model types

const (
	TypeVertexAI ModelType = "vertex_ai" // Google Vertex AI embeddings
	TypeOpenAI   ModelType = "openai"    // OpenAI embeddings
	TypeLocal    ModelType = "local"     // Local embedding model
)

type OpenAIModel

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

OpenAIModel implements Model using OpenAI's API

func (*OpenAIModel) Close

func (m *OpenAIModel) Close() error

Close implements Model.Close

func (*OpenAIModel) Dimension

func (m *OpenAIModel) Dimension() int

Dimension implements Model.Dimension

func (*OpenAIModel) Embed

func (m *OpenAIModel) Embed(ctx context.Context, texts []string) ([][]float32, error)

Embed implements Model.Embed

type VertexAIModel

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

VertexAIModel implements Model using Google's Vertex AI

func (*VertexAIModel) Close

func (m *VertexAIModel) Close() error

Close implements Model.Close

func (*VertexAIModel) Dimension

func (m *VertexAIModel) Dimension() int

Dimension implements Model.Dimension

func (*VertexAIModel) Embed

func (m *VertexAIModel) Embed(ctx context.Context, texts []string) ([][]float32, error)

Embed implements Model.Embed

Jump to

Keyboard shortcuts

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