From 042bd494825963cbc58482ae5854ba83b40837a5 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Thu, 17 Jul 2025 10:12:15 -0700 Subject: [PATCH] **refactor(core): remove verbose logging for Universal Sentence Encoder** - **Logging Cleanup**: - Removed redundant `console.log` statements in `brainyData.ts` and `embedding.ts` related to Universal Sentence Encoder initialization and load function detection. - Replaced detailed logs with concise comments to streamline debugging and reduce noisy outputs. - **Purpose**: - Improves code readability, reduces runtime logging noise, and aligns logging verbosity with the project's streamlined debugging practices. --- src/brainyData.ts | 6 +++--- src/utils/embedding.ts | 28 ++-------------------------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/brainyData.ts b/src/brainyData.ts index b2860b38..948775ec 100644 --- a/src/brainyData.ts +++ b/src/brainyData.ts @@ -255,10 +255,10 @@ export class BrainyData implements BrainyDataInterface { // Pre-load the embedding model early to ensure it's always available // This helps prevent issues with the Universal Sentence Encoder not being loaded try { - console.log('Pre-loading Universal Sentence Encoder model...') + // Pre-loading Universal Sentence Encoder model // Call embedding function directly to avoid circular dependency with embed() await this.embeddingFunction('') - console.log('Universal Sentence Encoder model loaded successfully') + // Universal Sentence Encoder model loaded successfully } catch (embedError) { console.warn( 'Failed to pre-load Universal Sentence Encoder:', @@ -266,7 +266,7 @@ export class BrainyData implements BrainyDataInterface { ) // Try again with a retry mechanism - console.log('Retrying Universal Sentence Encoder initialization...') + // Retrying Universal Sentence Encoder initialization try { // Wait a moment before retrying await new Promise((resolve) => setTimeout(resolve, 1000)) diff --git a/src/utils/embedding.ts b/src/utils/embedding.ts index 9601a7a9..a8f2a411 100644 --- a/src/utils/embedding.ts +++ b/src/utils/embedding.ts @@ -298,12 +298,7 @@ export class UniversalSentenceEncoder implements EmbeddingModel { await this.tf.setBackend(this.backend) } - // Log the module structure to help with debugging - console.log( - 'Universal Sentence Encoder module structure in main thread:', - Object.keys(this.use), - this.use.default ? Object.keys(this.use.default) : 'No default export' - ) + // Module structure available for debugging if needed // Try to find the load function in different possible module structures const loadFunction = findUSELoadFunction(this.use) @@ -488,14 +483,7 @@ export class UniversalSentenceEncoder implements EmbeddingModel { function findUSELoadFunction( sentenceEncoderModule: any ): (() => Promise) | null { - // Log the module structure for debugging - console.log( - 'Universal Sentence Encoder module structure:', - Object.keys(sentenceEncoderModule), - sentenceEncoderModule.default - ? Object.keys(sentenceEncoderModule.default) - : 'No default export' - ) + // Module structure available for debugging if needed let loadFunction = null @@ -505,7 +493,6 @@ function findUSELoadFunction( typeof sentenceEncoderModule.load === 'function' ) { loadFunction = sentenceEncoderModule.load - console.log('Using sentenceEncoderModule.load') } // Then try sentenceEncoderModule.default.load (default export) else if ( @@ -514,7 +501,6 @@ function findUSELoadFunction( typeof sentenceEncoderModule.default.load === 'function' ) { loadFunction = sentenceEncoderModule.default.load - console.log('Using sentenceEncoderModule.default.load') } // Try sentenceEncoderModule.default directly if it's a function else if ( @@ -522,12 +508,10 @@ function findUSELoadFunction( typeof sentenceEncoderModule.default === 'function' ) { loadFunction = sentenceEncoderModule.default - console.log('Using sentenceEncoderModule.default as function') } // Try sentenceEncoderModule directly if it's a function else if (typeof sentenceEncoderModule === 'function') { loadFunction = sentenceEncoderModule - console.log('Using sentenceEncoderModule as function') } // Try additional common patterns else if ( @@ -535,7 +519,6 @@ function findUSELoadFunction( typeof sentenceEncoderModule.UniversalSentenceEncoder.load === 'function' ) { loadFunction = sentenceEncoderModule.UniversalSentenceEncoder.load - console.log('Using sentenceEncoderModule.UniversalSentenceEncoder.load') } else if ( sentenceEncoderModule.default && sentenceEncoderModule.default.UniversalSentenceEncoder && @@ -543,9 +526,6 @@ function findUSELoadFunction( 'function' ) { loadFunction = sentenceEncoderModule.default.UniversalSentenceEncoder.load - console.log( - 'Using sentenceEncoderModule.default.UniversalSentenceEncoder.load' - ) } // Try to find the load function in the module's properties else { @@ -556,7 +536,6 @@ function findUSELoadFunction( const fnName = sentenceEncoderModule[key].name || key if (fnName.toLowerCase().includes('load')) { loadFunction = sentenceEncoderModule[key] - console.log(`Using sentenceEncoderModule.${key} as load function`) break } } @@ -571,9 +550,6 @@ function findUSELoadFunction( sentenceEncoderModule[key][nestedKey].name || nestedKey if (fnName.toLowerCase().includes('load')) { loadFunction = sentenceEncoderModule[key][nestedKey] - console.log( - `Using sentenceEncoderModule.${key}.${nestedKey} as load function` - ) break } }