refactor: replace Brainy with TransformerEmbedding in buildEmbeddedPatterns

- Replace Brainy with TransformerEmbedding for embedding patterns
- Update initialization logic to support TransformerEmbedding features like `localFilesOnly`
- Adjust embedding logic to use TransformerEmbedding's embed method
- Remove unused Brainy-related code (e.g., close method)
This commit is contained in:
David Snelling 2025-09-29 10:05:46 -07:00
parent 797839c135
commit 04477fef84
3 changed files with 12 additions and 13 deletions

1
.gitignore vendored
View file

@ -92,3 +92,4 @@ docs/internal/
# Temporary files (redundant but explicit) # Temporary files (redundant but explicit)
*.tmp *.tmp
/.junie/guidelines.md

View file

@ -6,7 +6,7 @@
* NO runtime loading, NO external files needed! * NO runtime loading, NO external files needed!
*/ */
import { Brainy } from '../dist/brainy.js' import { TransformerEmbedding } from '../src/utils/embedding.js'
import * as fs from 'fs/promises' import * as fs from 'fs/promises'
import * as path from 'path' import * as path from 'path'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
@ -22,14 +22,14 @@ async function buildEmbeddedPatterns() {
console.log(`📚 Processing ${libraryData.patterns.length} patterns...`) console.log(`📚 Processing ${libraryData.patterns.length} patterns...`)
// Initialize Brainy for embedding (one-time only!) // Initialize TransformerEmbedding for embedding (one-time only!)
const brain = new Brainy({ const embedder = new TransformerEmbedding({
// Use in-memory storage for build process verbose: true,
storage: { type: 'memory' } localFilesOnly: false // Allow downloading models during build
}) })
await brain.init() await embedder.init()
console.log('✅ Brainy initialized for embedding') console.log('✅ TransformerEmbedding initialized for embedding')
// Process patterns in batches to avoid memory issues // Process patterns in batches to avoid memory issues
const batchSize = 10 const batchSize = 10
@ -45,8 +45,8 @@ async function buildEmbeddedPatterns() {
for (const example of pattern.examples || []) { for (const example of pattern.examples || []) {
try { try {
// Use brain's embed method directly - no add/delete needed! // Use embedder's embed method directly - no add/delete needed!
const embedding = await (brain as any).embed(example) const embedding = await embedder.embed(example)
if (embedding && Array.isArray(embedding)) { if (embedding && Array.isArray(embedding)) {
embeddings.push(embedding) embeddings.push(embedding)
} }
@ -218,8 +218,6 @@ The patterns are now embedded directly in Brainy!
No external files needed, instant availability. No external files needed, instant availability.
`) `)
// Close Brainy instance
await brain.close()
} }
// Run if called directly // Run if called directly
@ -227,4 +225,4 @@ if (import.meta.url === `file://${process.argv[1]}`) {
buildEmbeddedPatterns().catch(console.error) buildEmbeddedPatterns().catch(console.error)
} }
export { buildEmbeddedPatterns } export { buildEmbeddedPatterns }

View file

@ -2,7 +2,7 @@
* 🧠 BRAINY EMBEDDED PATTERNS * 🧠 BRAINY EMBEDDED PATTERNS
* *
* AUTO-GENERATED - DO NOT EDIT * AUTO-GENERATED - DO NOT EDIT
* Generated: 2025-09-15T16:41:42.483Z * Generated: 2025-09-29T17:05:30.153Z
* Patterns: 220 * Patterns: 220
* Coverage: 94-98% of all queries * Coverage: 94-98% of all queries
* *