Skip to main content

Module utils

Module utils 

Source
Expand description

Shared utilities for embedding input sanitization and response handling.

Functionsยง

compute_norm
Compute L2 norm of a vector
handle_embedding_response
Replace embeddings for originally-invalid inputs with zero vectors.
is_embeddable
Returns true if s is non-empty after stripping ASCII whitespace.
l2_normalize
L2 normalize a vector to unit length
mean_pool
Mean pooling over sequence dimension with attention mask
sanitize_embedding_inputs
Replace empty/whitespace-only strings with "." to prevent API errors.