feat(adapter): add passthrough adapter for unchanged vectors

This commit is contained in:
2026-04-11 20:57:44 +02:00
parent 5c070e441e
commit c5608bf5cd
4 changed files with 57 additions and 32 deletions

View File

@@ -6,65 +6,66 @@ import (
"os"
"strings"
"github.com/go-viper/mapstructure/v2"
"github.com/spf13/viper"
)
// Config is the root configuration for vecna.
type Config struct {
Server ServerConfig `mapstructure:"server"`
Metrics MetricsConfig `mapstructure:"metrics"`
Forward ForwardConfig `mapstructure:"forward"`
Adapter AdapterConfig `mapstructure:"adapter"`
Server ServerConfig `mapstructure:"server" json:"server" yaml:"server" xml:"server"`
Metrics MetricsConfig `mapstructure:"metrics" json:"metrics" yaml:"metrics" xml:"metrics"`
Forward ForwardConfig `mapstructure:"forward" json:"forward" yaml:"forward" xml:"forward"`
Adapter AdapterConfig `mapstructure:"adapter" json:"adapter" yaml:"adapter" xml:"adapter"`
}
// ServerConfig controls the HTTP listener and inbound auth.
type ServerConfig struct {
Port int `mapstructure:"port"`
Host string `mapstructure:"host"`
APIKeys []string `mapstructure:"api_keys"`
Port int `mapstructure:"port" json:"port" yaml:"port" xml:"port"`
Host string `mapstructure:"host" json:"host" yaml:"host" xml:"host"`
APIKeys []string `mapstructure:"api_keys" json:"api_keys" yaml:"api_keys" xml:"api_keys"`
}
// MetricsConfig controls Prometheus metrics exposure.
type MetricsConfig struct {
Enabled bool `mapstructure:"enabled"`
Path string `mapstructure:"path"`
APIKey string `mapstructure:"api_key"`
Enabled bool `mapstructure:"enabled" json:"enabled" yaml:"enabled" xml:"enabled"`
Path string `mapstructure:"path" json:"path" yaml:"path" xml:"path"`
APIKey string `mapstructure:"api_key" json:"api_key" yaml:"api_key" xml:"api_key"`
}
// ForwardConfig holds all named forwarding targets.
type ForwardConfig struct {
Default string `mapstructure:"default"`
Targets map[string]ForwardTarget `mapstructure:"targets"`
Default string `mapstructure:"default" json:"default" yaml:"default" xml:"default"`
Targets map[string]ForwardTarget `mapstructure:"targets" json:"targets" yaml:"targets" xml:"targets"`
}
// ForwardTarget is a named backing embedding model with one or more endpoints.
type ForwardTarget struct {
Endpoints []EndpointConfig `mapstructure:"endpoints"`
Model string `mapstructure:"model"`
APIKey string `mapstructure:"api_key"`
APIType string `mapstructure:"api_type"`
TimeoutSecs int `mapstructure:"timeout_secs"`
CooldownSecs int `mapstructure:"cooldown_secs"`
PriorityDecay int `mapstructure:"priority_decay"`
PriorityRecovery int `mapstructure:"priority_recovery"`
Endpoints []EndpointConfig `mapstructure:"endpoints" json:"endpoints" yaml:"endpoints" xml:"endpoints"`
Model string `mapstructure:"model" json:"model" yaml:"model" xml:"model"`
APIKey string `mapstructure:"api_key" json:"api_key" yaml:"api_key" xml:"api_key"`
APIType string `mapstructure:"api_type" json:"api_type" yaml:"api_type" xml:"api_type"`
TimeoutSecs int `mapstructure:"timeout_secs" json:"timeout_secs" yaml:"timeout_secs" xml:"timeout_secs"`
CooldownSecs int `mapstructure:"cooldown_secs" json:"cooldown_secs" yaml:"cooldown_secs" xml:"cooldown_secs"`
PriorityDecay int `mapstructure:"priority_decay" json:"priority_decay" yaml:"priority_decay" xml:"priority_decay"`
PriorityRecovery int `mapstructure:"priority_recovery" json:"priority_recovery" yaml:"priority_recovery" xml:"priority_recovery"`
}
// EndpointConfig is a single URL within a ForwardTarget.
type EndpointConfig struct {
URL string `mapstructure:"url"`
Priority int `mapstructure:"priority"`
APIKey string `mapstructure:"api_key"`
URL string `mapstructure:"url" json:"url" yaml:"url" xml:"url"`
Priority int `mapstructure:"priority" json:"priority" yaml:"priority" xml:"priority"`
APIKey string `mapstructure:"api_key" json:"api_key" yaml:"api_key" xml:"api_key"`
}
// AdapterConfig selects and tunes the dimension adapter.
type AdapterConfig struct {
Type string `mapstructure:"type"`
SourceDim int `mapstructure:"source_dim"`
TargetDim int `mapstructure:"target_dim"`
TruncateMode string `mapstructure:"truncate_mode"`
PadMode string `mapstructure:"pad_mode"`
Seed int64 `mapstructure:"seed"`
MatrixFile string `mapstructure:"matrix_file"`
Type string `mapstructure:"type" json:"type" yaml:"type" xml:"type"`
SourceDim int `mapstructure:"source_dim" json:"source_dim" yaml:"source_dim" xml:"source_dim"`
TargetDim int `mapstructure:"target_dim" json:"target_dim" yaml:"target_dim" xml:"target_dim"`
TruncateMode string `mapstructure:"truncate_mode" json:"truncate_mode" yaml:"truncate_mode" xml:"truncate_mode"`
PadMode string `mapstructure:"pad_mode" json:"pad_mode" yaml:"pad_mode" xml:"pad_mode"`
Seed int64 `mapstructure:"seed" json:"seed" yaml:"seed" xml:"seed"`
MatrixFile string `mapstructure:"matrix_file" json:"matrix_file" yaml:"matrix_file" xml:"matrix_file"`
}
// extensions viper will detect automatically.
@@ -132,7 +133,17 @@ func Load(cfgFile string) (*Config, error) {
}
var cfg Config
if err := v.Unmarshal(&cfg); err != nil {
if err := v.Unmarshal(&cfg, func(dc *mapstructure.DecoderConfig) {
// Viper lowercases all keys (e.g. "SourceDim" → "sourcedim"), but
// mapstructure tags use snake_case ("source_dim"). Strip underscores
// before comparing so both forms resolve correctly.
dc.MatchName = func(mapKey, fieldName string) bool {
norm := func(s string) string {
return strings.ToLower(strings.ReplaceAll(s, "_", ""))
}
return norm(mapKey) == norm(fieldName)
}
}); err != nil {
return nil, fmt.Errorf("unmarshal config: %w", err)
}