provider

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToFloat32Slice

func BytesToFloat32Slice(b []byte) []float32

BytesToFloat32Slice converts little-endian bytes to a float32 slice. This is used to retrieve embeddings from SQLite BLOBs.

func Float32SliceToBytes

func Float32SliceToBytes(floats []float32) []byte

Float32SliceToBytes converts a float32 slice to little-endian bytes. This is used to store embeddings as BLOBs in SQLite.

func GetModelDefaultMaxTokens

func GetModelDefaultMaxTokens(cfg config.ProviderConfig, apiKey string) (int, error)

GetModelDefaultMaxTokens returns the default MaxTokens for a model without applying config overrides. This is useful for showing the default value during configuration.

func RegisterEmbeddingProvider

func RegisterEmbeddingProvider(name string, factory EmbeddingProviderFactory)

RegisterEmbeddingProvider registers an embedding provider factory

func RegisterLLMProvider

func RegisterLLMProvider(name string, factory LLMProviderFactory)

RegisterLLMProvider registers an LLM provider factory

Types

type BatchEmbedResult

type BatchEmbedResult struct {
	Results []EmbedResult
	Errors  int
}

BatchEmbedResult contains results from a batch embedding operation

type EmbedRequest

type EmbedRequest struct {
	ID      int
	Content string
}

EmbedRequest represents a chunk to embed

type EmbedResult

type EmbedResult struct {
	ID        int
	Embedding []float32
	Error     error
}

EmbedResult represents an embedding result for a single chunk

type EmbeddingProvider

type EmbeddingProvider interface {
	// Name returns the provider name (e.g., "gemini", "ollama")
	Name() string

	// Dimensions returns the embedding vector dimensions
	Dimensions() int

	// BatchSize returns the maximum batch size for embedding requests
	BatchSize() int

	// MaxTokens returns the maximum token limit for this model
	MaxTokens() int

	// EmbedChunks embeds multiple chunks in a batch
	EmbedChunks(ctx context.Context, chunks []EmbedRequest) BatchEmbedResult

	// EmbedQuery embeds a single query for search
	EmbedQuery(ctx context.Context, query string) []float32

	// Validate tests the provider connection/credentials
	Validate(ctx context.Context) error
}

EmbeddingProvider defines the interface for embedding operations

func NewEmbeddingProvider

func NewEmbeddingProvider(cfg config.ProviderConfig, apiKey string) (EmbeddingProvider, error)

NewEmbeddingProvider creates an EmbeddingProvider based on config If cfg.MaxTokens is set (> 0), it wraps the provider to use the custom value

type EmbeddingProviderFactory

type EmbeddingProviderFactory func(cfg config.ProviderConfig, apiKey string) (EmbeddingProvider, error)

EmbeddingProviderFactory is a function that creates an EmbeddingProvider

type LLMError

type LLMError struct {
	Message    string
	StatusCode int
}

LLMError represents an error from an LLM call

type LLMProvider

type LLMProvider interface {
	// Name returns the provider name
	Name() string

	// Call makes a non-streaming LLM request
	Call(ctx context.Context, req LLMRequest) (*LLMResult, *LLMError)

	// Stream makes a streaming LLM request, calling onChunk for each token
	Stream(ctx context.Context, req LLMRequest, onChunk func(string)) (*LLMResult, *LLMError)

	// Validate tests the provider connection/credentials
	Validate(ctx context.Context) error
}

LLMProvider defines the interface for LLM operations

func NewLLMProvider

func NewLLMProvider(cfg config.ProviderConfig, apiKey string) (LLMProvider, error)

NewLLMProvider creates an LLMProvider based on config

type LLMProviderFactory

type LLMProviderFactory func(cfg config.ProviderConfig, apiKey string) (LLMProvider, error)

LLMProviderFactory is a function that creates an LLMProvider

type LLMRequest

type LLMRequest struct {
	Prompt       string
	SystemPrompt string
	MaxTokens    int
	Temperature  float32
}

LLMRequest represents a request to an LLM

type LLMResult

type LLMResult struct {
	Text         string
	InputTokens  int
	OutputTokens int
}

LLMResult represents the response from an LLM

type MockEmbeddingProvider

type MockEmbeddingProvider struct {
	NameVal       string
	DimensionsVal int
	BatchSizeVal  int
	MaxTokensVal  int
	EmbedFunc     func(ctx context.Context, chunks []EmbedRequest) BatchEmbedResult
	QueryFunc     func(ctx context.Context, query string) []float32
}

MockEmbeddingProvider is a test double for EmbeddingProvider

func NewMockEmbeddingProvider

func NewMockEmbeddingProvider() *MockEmbeddingProvider

NewMockEmbeddingProvider creates a mock embedding provider with sensible defaults

func (*MockEmbeddingProvider) BatchSize

func (m *MockEmbeddingProvider) BatchSize() int

func (*MockEmbeddingProvider) Dimensions

func (m *MockEmbeddingProvider) Dimensions() int

func (*MockEmbeddingProvider) EmbedChunks

func (m *MockEmbeddingProvider) EmbedChunks(ctx context.Context, chunks []EmbedRequest) BatchEmbedResult

func (*MockEmbeddingProvider) EmbedQuery

func (m *MockEmbeddingProvider) EmbedQuery(ctx context.Context, query string) []float32

func (*MockEmbeddingProvider) MaxTokens

func (m *MockEmbeddingProvider) MaxTokens() int

func (*MockEmbeddingProvider) Name

func (m *MockEmbeddingProvider) Name() string

func (*MockEmbeddingProvider) Validate

func (m *MockEmbeddingProvider) Validate(_ context.Context) error

type MockLLMProvider

type MockLLMProvider struct {
	NameVal    string
	CallFunc   func(ctx context.Context, req LLMRequest) (*LLMResult, *LLMError)
	StreamFunc func(ctx context.Context, req LLMRequest, onChunk func(string)) (*LLMResult, *LLMError)
}

MockLLMProvider is a test double for LLMProvider

func NewMockLLMProvider

func NewMockLLMProvider() *MockLLMProvider

NewMockLLMProvider creates a mock LLM provider with sensible defaults

func (*MockLLMProvider) Call

func (*MockLLMProvider) Name

func (m *MockLLMProvider) Name() string

func (*MockLLMProvider) Stream

func (m *MockLLMProvider) Stream(ctx context.Context, req LLMRequest, onChunk func(string)) (*LLMResult, *LLMError)

func (*MockLLMProvider) Validate

func (m *MockLLMProvider) Validate(_ context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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