MCPcopy Create free account
hub / github.com/idosal/git-mcp / normalizeVector

Function normalizeVector

src/api/utils/vectorStore.ts:192–206  ·  view source on GitHub ↗

* Normalize a vector to unit length

(vector: Float32Array)

Source from the content-addressed store, hash-verified

190 * Normalize a vector to unit length
191 */
192function normalizeVector(vector: Float32Array): void {
193 // Calculate magnitude
194 let magnitude = 0;
195 for (let i = 0; i < vector.length; i++) {
196 magnitude += vector[i] * vector[i];
197 }
198 magnitude = Math.sqrt(magnitude);
199
200 // Normalize if magnitude isn't zero
201 if (magnitude > 0) {
202 for (let i = 0; i < vector.length; i++) {
203 vector[i] = vector[i] / magnitude;
204 }
205 }
206}
207
208/**
209 * Simple string hash function

Callers 1

getEmbeddingsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected