Files
vecna/pkg/adapter/projection.go
Hein 4009a54e39 feat: 🎉 Vectors na Vectors, the begining
Translate 1536 <-> 768 , 3072 <-> 2048
2026-04-11 18:05:05 +02:00

33 lines
797 B
Go

package adapter
import "fmt"
type projectionAdapter struct {
sourceDim int
targetDim int
matrix [][]float32
}
func (a *projectionAdapter) SourceDim() int { return a.sourceDim }
func (a *projectionAdapter) TargetDim() int { return a.targetDim }
func (a *projectionAdapter) Adapt(vec []float32) ([]float32, error) {
if len(vec) != a.sourceDim {
return nil, fmt.Errorf("projection adapt: %w: got %d, want %d", ErrDimMismatch, len(vec), a.sourceDim)
}
return L2Norm(matVecMul(a.matrix, vec)), nil
}
// matVecMul computes m·v where m is [rows][cols] and v has len cols.
func matVecMul(m [][]float32, v []float32) []float32 {
out := make([]float32, len(m))
for i, row := range m {
var sum float32
for j, val := range row {
sum += val * v[j]
}
out[i] = sum
}
return out
}