Réducteur & Optimiseur de Vecteurs
Vector Database (RAG) Embeddings Dimension Reducer & Optimizer est un outil local. Simulez la troncature normalisée L2 et les quantifications binaires 1-bit directement dans votre navigateur.
Paste vector floats in Vector A and Vector B to begin calculation. Or load a preset above to test the math.
/**
* client-reducer.ts
* Browser-safe embedding dimensionality reducer & optimizer.
* Designed for Matryoshka Representation Learning (MRL) and local quantization.
*/
export function optimizeEmbedding(
vector: number[],
targetDim: number = 256,
format: 'float32' | 'int8' | 'binary' = 'float32'
): {
data: Float32Array | Int8Array | Uint8Array;
scale?: number;
} {
// 1. Matryoshka Truncation (Slice prefix)
const sliced = vector.slice(0, targetDim);
// 2. L2 Re-normalization (Ensure unit length)
let sumSq = 0;
for (let i = 0; i < targetDim; i++) {
sumSq += sliced[i] * sliced[i];
}
const norm = Math.sqrt(sumSq);
const normalized = new Float32Array(targetDim);
if (norm > 0) {
for (let i = 0; i < targetDim; i++) {
normalized[i] = sliced[i] / norm;
}
}
// 3. Apply Quantization Format
if (format === 'float32') {
return { data: normalized };
}
if (format === 'int8') {
// Find absolute maximum value for scaling
let maxVal = 0;
for (let i = 0; i < targetDim; i++) {
const abs = Math.abs(normalized[i]);
if (abs > maxVal) maxVal = abs;
}
const scale = maxVal > 0 ? 127 / maxVal : 1;
const int8Data = new Int8Array(targetDim);
for (let i = 0; i < targetDim; i++) {
int8Data[i] = Math.round(normalized[i] * scale);
}
return { data: int8Data, scale };
}
if (format === 'binary') {
// Pack every 8 float values into a single byte
const byteLen = Math.ceil(targetDim / 8);
const binaryData = new Uint8Array(byteLen);
for (let i = 0; i < targetDim; i++) {
if (normalized[i] >= 0) {
const byteIdx = Math.floor(i / 8);
const bitIdx = i % 8;
binaryData[byteIdx] |= (1 << bitIdx);
}
}
return { data: binaryData };
}
throw new Error('Unsupported quantization format');
}
/**
* Helper to calculate Hamming Distance between two Packed Binary Vectors
*/
export function hammingDistance(a: Uint8Array, b: Uint8Array): number {
let distance = 0;
for (let i = 0; i < a.length; i++) {
let xor = a[i] ^ b[i];
while (xor > 0) {
if (xor & 1) distance++;
xor >>= 1;
}
}
return distance;
}
Instructions
- 1
Fournissez deux vecteurs sous forme de tableau de floats JSON (Vecteur A et Vecteur B).
- 2
Sélectionnez une taille de troncature MRL cible (Original, 512, 256 ou 128).
- 3
Configurez le format de quantification (Float32, Int8 Scalaire ou Binaire 1-bit).
- 4
Analysez le taux de rétention de similitude cosinus, le facteur de compression mémoire et téléchargez les blocs de code.
- 5
Copiez le code du réducteur client ou le schéma SQL pgvector.
Questions Fréquemment Posées
Related Tools
Maîtrisez Cet Outil
Guides approfondis et tutoriels pour les experts.
Decoding React Server Components Flight Data: A Local-First Audit Guide
Discover the hidden data leaks in your Next.js network stream. Learn how to debug Next.js RSC data and inspect RSC payloads 100% locally.
Vector Dimensionality: Why Misaligned Embeddings Break RAG
Discover why projecting 3072-D embeddings into 1536-D indices destroys semantic retrieval. Learn to audit vector math using Cosine Similarity to prevent AI hallucinations.
Securing AI Agents: How to Detect & Prevent Prompt Injection
A Cybersecurity Architect's guide to prompt injection in 2026. Learn about Token to Shell vectors, RAG poisoning, and embedding-based anomaly detection.
Understanding MCP Transport Layers: stdio vs. HTTP vs. WebSockets
A technical deep dive into Model Context Protocol (MCP) transport mechanisms. Compare stdio, HTTP with SSE, and WebSockets for secure AI agent integration.
Debugging RAG: Cosine vs Euclidean Distance
A technical guide for AI Architects on measuring embedding proximity. Learn to debug RAG retrieval errors using vector math and Cosine Similarity metrics.