73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
/**
|
|
* Embedding Normalization Utilities
|
|
*
|
|
* Features:
|
|
* - L2 (Euclidean) normalization
|
|
* - L1 (Manhattan) normalization
|
|
* - Min-max normalization
|
|
* - Z-score standardization
|
|
* - Batch normalization
|
|
*/
|
|
/**
|
|
* Normalization type
|
|
*/
|
|
export type NormalizationType = 'l2' | 'l1' | 'minmax' | 'zscore' | 'none';
|
|
/**
|
|
* Normalization options
|
|
*/
|
|
export interface NormalizationOptions {
|
|
/** Normalization type (default: 'l2') */
|
|
type?: NormalizationType;
|
|
/** Epsilon for numerical stability (default: 1e-12) */
|
|
epsilon?: number;
|
|
/** In-place modification (default: false) */
|
|
inPlace?: boolean;
|
|
}
|
|
/**
|
|
* L2 (Euclidean) normalize embedding to unit length
|
|
* Most common for cosine similarity
|
|
*
|
|
* @param embedding - Input embedding vector
|
|
* @param epsilon - Small value to prevent division by zero
|
|
* @returns Normalized embedding with ||v|| = 1
|
|
*/
|
|
export declare function l2Normalize(embedding: Float32Array | number[], epsilon?: number): Float32Array;
|
|
/**
|
|
* L2 normalize embedding in-place (modifies original array)
|
|
*/
|
|
export declare function l2NormalizeInPlace(embedding: Float32Array, epsilon?: number): Float32Array;
|
|
/**
|
|
* L1 (Manhattan) normalize embedding
|
|
* Sum of absolute values = 1
|
|
*/
|
|
export declare function l1Normalize(embedding: Float32Array | number[], epsilon?: number): Float32Array;
|
|
/**
|
|
* Min-max normalize embedding to [0, 1] range
|
|
*/
|
|
export declare function minMaxNormalize(embedding: Float32Array | number[], epsilon?: number): Float32Array;
|
|
/**
|
|
* Z-score standardize embedding (mean=0, std=1)
|
|
*/
|
|
export declare function zScoreNormalize(embedding: Float32Array | number[], epsilon?: number): Float32Array;
|
|
/**
|
|
* Normalize embedding using specified method
|
|
*/
|
|
export declare function normalize(embedding: Float32Array | number[], options?: NormalizationOptions): Float32Array;
|
|
/**
|
|
* Batch normalize multiple embeddings
|
|
*/
|
|
export declare function normalizeBatch(embeddings: Array<Float32Array | number[]>, options?: NormalizationOptions): Float32Array[];
|
|
/**
|
|
* Calculate L2 norm of embedding
|
|
*/
|
|
export declare function l2Norm(embedding: Float32Array | number[]): number;
|
|
/**
|
|
* Check if embedding is already normalized (L2 norm ≈ 1)
|
|
*/
|
|
export declare function isNormalized(embedding: Float32Array | number[], tolerance?: number): boolean;
|
|
/**
|
|
* Center embeddings by subtracting mean across batch
|
|
* Useful for improving similarity metrics
|
|
*/
|
|
export declare function centerEmbeddings(embeddings: Array<Float32Array | number[]>): Float32Array[];
|
|
//# sourceMappingURL=normalization.d.ts.map
|