export interface CompressionReport { originalBytes: number; compressedBytes: number; compressionRatio: number; vectorCount: number; dim: number; encodingError: { meanAbs: number; max: number; }; durationMs: number; } export interface QuantizedEntry { q: Int8Array; scale: number; } export interface CompressedIndex { vectors: Map; dim: number; recallFn: (query: number[], topK: number) => Array<{ id: string; score: number; }>; } export interface RoundtripErrorReport { meanAbs: number; max: number; samples: number; } export declare class BrainQuantize { /** Symmetric int8 quantization with per-vector scale. */ quantize(vector: number[]): Int8Array; /** Recover an approximation of the original float vector. */ dequantize(q: Int8Array, scale: number): number[]; /** * Cosine similarity on quantized vectors WITHOUT dequantizing first. * * If `a` and `b` were derived from unit-norm float vectors, the cosine is * just the dot product after rescaling. We compute the integer dot then * apply `scaleA * scaleB` to convert back to the float dot, and clamp to * [-1, 1] for numeric safety. Note: the dim/127^2 factor in the spec is the * theoretical worst-case scale (when every element is ±127); the actual * normalization is captured entirely by scaleA*scaleB, so we use that and * do not double-divide. The clamp guards against quantization rounding * pushing the result slightly out of range. */ cosineQuantized(a: Int8Array, scaleA: number, b: Int8Array, scaleB: number): number; /** Convert a v2 sharded JSON index into a single compressed .q8 binary. */ compressIndex(srcPath: string, outPath: string): Promise; /** Load a .q8 file and return vectors plus a ready-to-use recall function. */ loadCompressedIndex(filePath: string): Promise; /** Self-test: report mean / max absolute reconstruction error on `vectors`. */ quantizeRoundtripError(vectors: number[][]): RoundtripErrorReport; private scaleOf; private readShardDocs; private collectDocs; private measureBytes; private atomicWrite; } export declare function getBrainQuantize(): BrainQuantize; export declare function resetBrainQuantizeForTests(): void; //# sourceMappingURL=brain-quantize.d.ts.map