fix: use fp32 models consistently everywhere to ensure compatibility

Changed default dtype from q8 to fp32 across all embedding implementations:
- embedding.ts: Default dtype changed to fp32
- worker-embedding.ts: Use fp32 for consistency
- universal-memory-manager.ts: Use fp32 for consistency
- lightweight-embedder.ts: Use fp32 for consistency
- hybridModelManager.ts: Use fp32 for all configurations

This ensures we use the exact same model (model.onnx) everywhere,
maintaining data compatibility and avoiding 404 errors for quantized models.
This commit is contained in:
David Snelling 2025-08-29 10:23:23 -07:00
parent d0f2e3e939
commit 32e39ded53
11 changed files with 11 additions and 30742 deletions

View file

@ -1,5 +0,0 @@
{
"model": "Xenova/all-MiniLM-L6-v2",
"bundledAt": "2025-08-22T20:58:25.896Z",
"version": "1.0.0"
}

View file

@ -1,25 +0,0 @@
{
"_name_or_path": "sentence-transformers/all-MiniLM-L6-v2",
"architectures": [
"BertModel"
],
"attention_probs_dropout_prob": 0.1,
"classifier_dropout": null,
"gradient_checkpointing": false,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 384,
"initializer_range": 0.02,
"intermediate_size": 1536,
"layer_norm_eps": 1e-12,
"max_position_embeddings": 512,
"model_type": "bert",
"num_attention_heads": 12,
"num_hidden_layers": 6,
"pad_token_id": 0,
"position_embedding_type": "absolute",
"transformers_version": "4.29.2",
"type_vocab_size": 2,
"use_cache": true,
"vocab_size": 30522
}

File diff suppressed because it is too large Load diff

View file

@ -1,15 +0,0 @@
{
"clean_up_tokenization_spaces": true,
"cls_token": "[CLS]",
"do_basic_tokenize": true,
"do_lower_case": true,
"mask_token": "[MASK]",
"model_max_length": 512,
"never_split": null,
"pad_token": "[PAD]",
"sep_token": "[SEP]",
"strip_accents": null,
"tokenize_chinese_chars": true,
"tokenizer_class": "BertTokenizer",
"unk_token": "[UNK]"
}

View file

@ -113,7 +113,7 @@ export class LightweightEmbedder {
console.log('⚠️ Loading ONNX model for complex text...')
const { TransformerEmbedding } = await import('../utils/embedding.js')
this.onnxEmbedder = new TransformerEmbedding({
dtype: 'q8',
dtype: 'fp32',
verbose: false
})
await this.onnxEmbedder.init()

View file

@ -139,7 +139,7 @@ export class UniversalMemoryManager {
this.embeddingFunction = new TransformerEmbedding({
verbose: false,
dtype: 'q8',
dtype: 'fp32',
localFilesOnly: process.env.BRAINY_ALLOW_REMOTE_MODELS !== 'true'
})

View file

@ -16,7 +16,7 @@ async function initModel(): Promise<void> {
if (!model) {
model = new TransformerEmbedding({
verbose: false,
dtype: 'q8',
dtype: 'fp32',
localFilesOnly: process.env.BRAINY_ALLOW_REMOTE_MODELS !== 'true'
})
await model.init()

View file

@ -128,7 +128,7 @@ export class TransformerEmbedding implements EmbeddingModel {
verbose: this.verbose,
cacheDir: options.cacheDir || './models',
localFilesOnly: localFilesOnly,
dtype: options.dtype || 'q8', // Changed from fp32 to q8 for 75% memory reduction
dtype: options.dtype || 'fp32', // Use fp32 by default as quantized models aren't available on CDN
device: options.device || 'auto'
}
@ -262,7 +262,7 @@ export class TransformerEmbedding implements EmbeddingModel {
const pipelineOptions: any = {
cache_dir: cacheDir,
local_files_only: isBrowser() ? false : this.options.localFilesOnly,
dtype: this.options.dtype || 'q8', // Use quantized model for lower memory
dtype: this.options.dtype || 'fp32', // Use fp32 model as quantized models aren't available on CDN
// CRITICAL: ONNX memory optimizations
session_options: {
enableCpuMemArena: false, // Disable pre-allocated memory arena

View file

@ -104,7 +104,7 @@ class HybridModelManager {
// Smart configuration based on environment
let options: TransformerEmbeddingOptions = {
verbose: !isTest && !isServerless,
dtype: 'q8',
dtype: 'fp32',
device: 'cpu'
}
@ -113,7 +113,7 @@ class HybridModelManager {
options = {
...options,
localFilesOnly: forceLocalOnly || false, // Respect environment variable
dtype: 'q8',
dtype: 'fp32',
device: 'cpu',
verbose: false
}
@ -121,7 +121,7 @@ class HybridModelManager {
options = {
...options,
localFilesOnly: forceLocalOnly || true, // Default true for serverless, but respect env
dtype: 'q8',
dtype: 'fp32',
device: 'cpu',
verbose: false
}
@ -138,7 +138,7 @@ class HybridModelManager {
options = {
...options,
localFilesOnly: forceLocalOnly || false, // Respect environment variable for tests
dtype: 'q8',
dtype: 'fp32',
device: 'cpu',
verbose: false
}
@ -146,7 +146,7 @@ class HybridModelManager {
options = {
...options,
localFilesOnly: forceLocalOnly || false, // Respect environment variable for default node
dtype: 'q8',
dtype: 'fp32',
device: 'auto',
verbose: true
}
@ -201,7 +201,7 @@ class HybridModelManager {
{ ...options, localFilesOnly: false, verbose: true, source: 'fallback-verbose' },
// 3. Last resort: basic configuration
{ verbose: false, dtype: 'q8' as const, device: 'cpu' as const, localFilesOnly: false, source: 'last-resort' }
{ verbose: false, dtype: 'fp32' as const, device: 'cpu' as const, localFilesOnly: false, source: 'last-resort' }
]
let lastError: Error | null = null