brainy/.recovery-workspace/dist-backup-20250910-141917/config/modelPrecisionManager.js
David Snelling 8ff382ca3b chore: recovery checkpoint - v3.0 API successfully recovered
CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB

Recovery Status:
- Successfully recovered brainy.ts from compiled JavaScript
- All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.)
- Neural subsystem intact (562KB embedded patterns, NLP working)
- Augmentation pipeline operational (20+ augmentations)
- HNSW clustering system complete
- Triple Intelligence compiled (needs constructor fix)
- Test suite validates functionality

Changes preserved:
- 898 files with changes from last 3 days
- 144,475 insertions
- All augmentation improvements
- All test coverage enhancements
- Complete v3.0 feature set

This is a LOCAL checkpoint only - contains recovered work after corruption incident.
Created backup in .backups/brainy-full-20250910-151314.tar.gz

Branch: recovery-checkpoint-20250910-151433
Date: Wed Sep 10 03:18:04 PM PDT 2025
2025-09-10 15:18:04 -07:00

98 lines
No EOL
3.3 KiB
JavaScript

/**
* Central Model Precision Manager
*
* Single source of truth for model precision configuration.
* Ensures consistent usage of Q8 or FP32 models throughout the system.
*/
export class ModelPrecisionManager {
constructor() {
this.precision = 'q8'; // DEFAULT TO Q8
this.isLocked = false;
// Check environment variable override
const envPrecision = process.env.BRAINY_MODEL_PRECISION;
if (envPrecision === 'fp32' || envPrecision === 'q8') {
this.precision = envPrecision;
console.log(`Model precision set from environment: ${envPrecision.toUpperCase()}`);
}
else {
console.log('Using default model precision: Q8 (75% smaller, 99% accuracy)');
}
}
static getInstance() {
if (!ModelPrecisionManager.instance) {
ModelPrecisionManager.instance = new ModelPrecisionManager();
}
return ModelPrecisionManager.instance;
}
/**
* Get the current model precision
*/
getPrecision() {
return this.precision;
}
/**
* Set the model precision (can only be done before first model load)
*/
setPrecision(precision) {
if (this.isLocked) {
console.warn(`⚠️ Cannot change precision after model initialization. Current: ${this.precision.toUpperCase()}`);
return;
}
if (precision !== this.precision) {
console.log(`Model precision changed: ${this.precision.toUpperCase()}${precision.toUpperCase()}`);
this.precision = precision;
}
}
/**
* Lock the precision (called after first model load)
*/
lock() {
if (!this.isLocked) {
this.isLocked = true;
console.log(`Model precision locked: ${this.precision.toUpperCase()}`);
}
}
/**
* Check if precision is locked
*/
isConfigLocked() {
return this.isLocked;
}
/**
* Get precision info for logging
*/
getInfo() {
const info = this.precision === 'q8'
? 'Q8 (quantized, 23MB, 99% accuracy)'
: 'FP32 (full precision, 90MB, 100% accuracy)';
return `${info}${this.isLocked ? ' [LOCKED]' : ''}`;
}
/**
* Validate that a given precision matches the configured one
*/
validatePrecision(precision) {
if (precision !== this.precision) {
console.error(`❌ Precision mismatch! Expected: ${this.precision.toUpperCase()}, Got: ${precision.toUpperCase()}`);
console.error('This will cause incompatible embeddings!');
return false;
}
return true;
}
}
// Export singleton instance getter
export const getModelPrecision = () => {
return ModelPrecisionManager.getInstance().getPrecision();
};
// Export setter (for configuration phase)
export const setModelPrecision = (precision) => {
ModelPrecisionManager.getInstance().setPrecision(precision);
};
// Export lock function (for after model initialization)
export const lockModelPrecision = () => {
ModelPrecisionManager.getInstance().lock();
};
// Export validation function
export const validateModelPrecision = (precision) => {
return ModelPrecisionManager.getInstance().validatePrecision(precision);
};
//# sourceMappingURL=modelPrecisionManager.js.map