embed

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultEmbedServerHost = "127.0.0.1"

DefaultEmbedServerHost is the default host for cortex-embed

View Source
const DefaultEmbedServerPort = 8121

DefaultEmbedServerPort is the default port for cortex-embed HTTP server

View Source
const EmbedServerVersion = "v1.0.1"

EmbedServerVersion is the well-known version of the cortex-embed binary. This is decoupled from the main cortex version to allow independent releases.

Variables

This section is empty.

Functions

func EnsureBinaryInstalled

func EnsureBinaryInstalled(downloader Downloader) (string, error)

EnsureBinaryInstalled checks if cortex-embed is installed and downloads it if not. Returns the absolute path to the binary. If downloader is nil, uses HTTPDownloader.

Types

type Config

type Config struct {
	// Provider specifies which embedding provider to use ("local", "openai", etc.)
	Provider string

	// Endpoint is the URL for the embedding service (for local provider)
	Endpoint string

	// APIKey for cloud providers (future)
	APIKey string

	// Model name (future: for provider-specific model selection)
	Model string
}

Config contains configuration for creating an embedding provider.

type Downloader

type Downloader interface {
	DownloadAndExtract(url, targetDir, ext string) error
}

Downloader handles downloading and extracting archives.

func NewHTTPDownloader

func NewHTTPDownloader() Downloader

NewHTTPDownloader creates a new HTTP-based downloader.

type EmbedMode

type EmbedMode string

EmbedMode specifies the type of embedding to generate.

const (
	// EmbedModeQuery generates embeddings optimized for search queries.
	// Use this when embedding user questions or search terms.
	EmbedModeQuery EmbedMode = "query"

	// EmbedModePassage generates embeddings optimized for document passages.
	// Use this when embedding code chunks, documentation, or any searchable content.
	EmbedModePassage EmbedMode = "passage"
)

type HTTPDownloader

type HTTPDownloader struct{}

HTTPDownloader implements Downloader using real HTTP requests.

func (*HTTPDownloader) DownloadAndExtract

func (d *HTTPDownloader) DownloadAndExtract(url, targetDir, ext string) error

DownloadAndExtract downloads the archive from the given URL and extracts it to targetDir.

type MockProvider

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

MockProvider is a test implementation that generates deterministic embeddings. It tracks Close() calls and can simulate errors.

func NewMockProvider

func NewMockProvider() *MockProvider

NewMockProvider creates a mock embedding provider for testing. It generates deterministic embeddings based on text content.

func (*MockProvider) Close

func (p *MockProvider) Close() error

Close tracks that close was called and returns configured error if set.

func (*MockProvider) Dimensions

func (p *MockProvider) Dimensions() int

Dimensions returns the dimensionality of mock embeddings.

func (*MockProvider) Embed

func (p *MockProvider) Embed(ctx context.Context, texts []string, mode EmbedMode) ([][]float32, error)

Embed generates mock embeddings by hashing the input text. This ensures deterministic, reproducible embeddings for testing.

func (*MockProvider) Initialize added in v1.3.0

func (p *MockProvider) Initialize(ctx context.Context) error

Initialize is a no-op for MockProvider as it's always ready.

func (*MockProvider) IsClosed

func (p *MockProvider) IsClosed() bool

IsClosed returns whether Close() has been called.

func (*MockProvider) SetCloseError

func (p *MockProvider) SetCloseError(err error)

SetCloseError configures the mock to return an error on Close().

func (*MockProvider) SetEmbedError

func (p *MockProvider) SetEmbedError(err error)

SetEmbedError configures the mock to return an error on Embed().

type Provider

type Provider interface {
	// Initialize prepares the provider and blocks until ready.
	// For LocalProvider: detects/downloads binary, starts process, waits for health check.
	// For other providers: validates credentials, checks connectivity.
	// Must be called before Embed().
	Initialize(ctx context.Context) error

	// Embed converts a slice of text strings into their vector representations.
	// The mode parameter specifies whether embeddings are for queries or passages.
	// Returns a slice of vectors where each vector is a slice of float32 values.
	// Initialize() must be called first.
	Embed(ctx context.Context, texts []string, mode EmbedMode) ([][]float32, error)

	// Dimensions returns the dimensionality of the embedding vectors produced by this provider.
	Dimensions() int

	// Close releases any resources held by the provider.
	// For local providers, this may include stopping background processes.
	Close() error
}

Provider defines the interface for embedding text into vectors. Implementations may use local models, remote APIs, or other embedding services.

func NewProvider

func NewProvider(config Config) (Provider, error)

NewProvider creates an embedding provider based on the configuration. Currently supports "local" and "mock" providers. Future: OpenAI, Anthropic, etc. Call Initialize() on the returned provider before use.

Directories

Path Synopsis
generate command

Jump to

Keyboard shortcuts

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