Optimizador de Dimensiones de Vectores
Vector Database (RAG) Embeddings Dimension Reducer & Optimizer es una herramienta local de simulación de vectores. Realice truncaciones normalizadas L2 y cuantificaciones a 1-bit directamente en su navegador.
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;
}
Instrucciones
- 1
Ingrese dos vectores en formato de matriz float JSON (Vector A y Vector B).
- 2
Seleccione el tamaño de truncación MRL (Original, 512, 256 o 128).
- 3
Configure el formato de cuantificación (Float32, Int8 Escalar o Binario de 1-bit).
- 4
Analice la retención de similitud de coseno, el factor de compresión de memoria y descargue los bloques de código.
Preguntas Frecuentes
Related Tools
Domina Esta Herramienta
Guías detalladas y tutoriales para usuarios avanzados.
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.