



A preprocessing technique that scales vectors to unit length, ensuring all vectors lie on a hypersphere. Essential for making cosine similarity equivalent to inner product and improving embedding quality in many applications.
Laden......
Op deze pagina
L2 Normalization (Vector Normalization)
L2 Normalization, also called vector normalization, is a preprocessing technique that scales vectors to unit length (magnitude = 1). This ensures all vectors lie on the surface of a unit hypersphere, which has important mathematical and computational benefits.
For a vector v, the L2-normalized vector v̂ is:
v̂ = v / ||v||₂
where ||v||₂ = sqrt(Σ vᵢ²) is the L2 norm (Euclidean length)
import numpy as np
def l2_normalize(vector):
norm = np.linalg.norm(vector)
if norm == 0:
return vector
return vector / norm
Before Indexing: Normalize vectors before adding to vector database Before Querying: Normalize query vectors to match indexed vectors During Training: Some models normalize internally
With normalized vectors:
Not applicable (mathematical preprocessing technique).
Ontdek meer items die hierop lijken