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
106 lines
2.6 KiB
TypeScript
106 lines
2.6 KiB
TypeScript
/**
|
|
* Unified Embedding Manager
|
|
*
|
|
* THE single source of truth for all embedding operations in Brainy.
|
|
* Combines model management, precision configuration, and embedding generation
|
|
* into one clean, maintainable class.
|
|
*
|
|
* Features:
|
|
* - Singleton pattern ensures ONE model instance
|
|
* - Automatic Q8 (default) or FP32 precision
|
|
* - Model downloading and caching
|
|
* - Thread-safe initialization
|
|
* - Memory monitoring
|
|
*
|
|
* This replaces: SingletonModelManager, TransformerEmbedding, ModelPrecisionManager,
|
|
* hybridModelManager, universalMemoryManager, and more.
|
|
*/
|
|
import { Vector, EmbeddingFunction } from '../coreTypes.js';
|
|
export type ModelPrecision = 'q8' | 'fp32';
|
|
interface EmbeddingStats {
|
|
initialized: boolean;
|
|
precision: ModelPrecision;
|
|
modelName: string;
|
|
embedCount: number;
|
|
initTime: number | null;
|
|
memoryMB: number | null;
|
|
}
|
|
/**
|
|
* Unified Embedding Manager - Clean, simple, reliable
|
|
*/
|
|
export declare class EmbeddingManager {
|
|
private model;
|
|
private precision;
|
|
private modelName;
|
|
private initialized;
|
|
private initTime;
|
|
private embedCount;
|
|
private locked;
|
|
private constructor();
|
|
/**
|
|
* Get the singleton instance
|
|
*/
|
|
static getInstance(): EmbeddingManager;
|
|
/**
|
|
* Initialize the model (happens once)
|
|
*/
|
|
init(): Promise<void>;
|
|
/**
|
|
* Perform actual initialization
|
|
*/
|
|
private performInit;
|
|
/**
|
|
* Generate embeddings
|
|
*/
|
|
embed(text: string | string[]): Promise<Vector>;
|
|
/**
|
|
* Generate mock embeddings for unit tests
|
|
*/
|
|
private getMockEmbedding;
|
|
/**
|
|
* Get embedding function for compatibility
|
|
*/
|
|
getEmbeddingFunction(): EmbeddingFunction;
|
|
/**
|
|
* Determine model precision
|
|
*/
|
|
private determinePrecision;
|
|
/**
|
|
* Get models directory path
|
|
*/
|
|
private getModelsPath;
|
|
/**
|
|
* Get memory usage in MB
|
|
*/
|
|
private getMemoryUsage;
|
|
/**
|
|
* Get current statistics
|
|
*/
|
|
getStats(): EmbeddingStats;
|
|
/**
|
|
* Check if initialized
|
|
*/
|
|
isInitialized(): boolean;
|
|
/**
|
|
* Get current precision
|
|
*/
|
|
getPrecision(): ModelPrecision;
|
|
/**
|
|
* Validate precision matches expected
|
|
*/
|
|
validatePrecision(expected: ModelPrecision): void;
|
|
}
|
|
export declare const embeddingManager: EmbeddingManager;
|
|
/**
|
|
* Direct embed function
|
|
*/
|
|
export declare function embed(text: string | string[]): Promise<Vector>;
|
|
/**
|
|
* Get embedding function for compatibility
|
|
*/
|
|
export declare function getEmbeddingFunction(): EmbeddingFunction;
|
|
/**
|
|
* Get statistics
|
|
*/
|
|
export declare function getEmbeddingStats(): EmbeddingStats;
|
|
export {};
|