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)
*.tmp
/.junie/guidelines.md

View file

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

View file

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