Documentation
¶
Index ¶
- func BytesToFloat32Slice(b []byte) []float32
- func Float32SliceToBytes(floats []float32) []byte
- func GetModelDefaultMaxTokens(cfg config.ProviderConfig, apiKey string) (int, error)
- func RegisterEmbeddingProvider(name string, factory EmbeddingProviderFactory)
- func RegisterLLMProvider(name string, factory LLMProviderFactory)
- type BatchEmbedResult
- type EmbedRequest
- type EmbedResult
- type EmbeddingProvider
- type EmbeddingProviderFactory
- type LLMError
- type LLMProvider
- type LLMProviderFactory
- type LLMRequest
- type LLMResult
- type MockEmbeddingProvider
- func (m *MockEmbeddingProvider) BatchSize() int
- func (m *MockEmbeddingProvider) Dimensions() int
- func (m *MockEmbeddingProvider) EmbedChunks(ctx context.Context, chunks []EmbedRequest) BatchEmbedResult
- func (m *MockEmbeddingProvider) EmbedQuery(ctx context.Context, query string) []float32
- func (m *MockEmbeddingProvider) MaxTokens() int
- func (m *MockEmbeddingProvider) Name() string
- func (m *MockEmbeddingProvider) Validate(_ context.Context) error
- type MockLLMProvider
- func (m *MockLLMProvider) Call(ctx context.Context, req LLMRequest) (*LLMResult, *LLMError)
- func (m *MockLLMProvider) Name() string
- func (m *MockLLMProvider) Stream(ctx context.Context, req LLMRequest, onChunk func(string)) (*LLMResult, *LLMError)
- func (m *MockLLMProvider) Validate(_ context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToFloat32Slice ¶
BytesToFloat32Slice converts little-endian bytes to a float32 slice. This is used to retrieve embeddings from SQLite BLOBs.
func Float32SliceToBytes ¶
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 ¶
EmbedRequest represents a chunk to embed
type EmbedResult ¶
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 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 ¶
LLMRequest represents a request to 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
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 (m *MockLLMProvider) Call(ctx context.Context, req LLMRequest) (*LLMResult, *LLMError)
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)