feat: 🎉 Vectors na Vectors, the begining

Translate 1536 <-> 768 , 3072 <-> 2048
This commit is contained in:
2026-04-11 18:05:05 +02:00
parent d98ea7c222
commit 4009a54e39
58 changed files with 5324 additions and 2 deletions

32
pkg/adapter/projection.go Normal file
View File

@@ -0,0 +1,32 @@
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
}