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

23
pkg/adapter/normalize.go Normal file
View File

@@ -0,0 +1,23 @@
package adapter
import "math"
// L2Norm returns a new slice with the vector normalized to unit length.
// If the vector has zero magnitude it is returned unchanged.
func L2Norm(v []float32) []float32 {
var sum float64
for _, x := range v {
sum += float64(x) * float64(x)
}
if sum == 0 {
out := make([]float32, len(v))
copy(out, v)
return out
}
norm := float32(math.Sqrt(sum))
out := make([]float32, len(v))
for i, x := range v {
out[i] = x / norm
}
return out
}