Explorar o código

check normalization

Roy Han hai 10 meses
pai
achega
b9c74df37b
Modificáronse 1 ficheiros con 9 adicións e 0 borrados
  1. 9 0
      server/routes.go

+ 9 - 0
server/routes.go

@@ -480,6 +480,15 @@ func (s *Server) EmbeddingsHandler(c *gin.Context) {
 		return
 	}
 
+	// assert that embedding is normalized
+	sum := 0.0
+	for _, v := range embedding {
+		sum += v * v
+	}
+	if math.Abs(sum-1) > 1e-6 {
+		slog.Info("embedding is not normalized", "sum", sum)
+	}
+
 	resp := api.EmbeddingResponse{
 		Embedding: embedding,
 	}