/** * Core Pattern Library with Pre-computed Embeddings * * This file is auto-generated by scripts/buildPatterns.ts * DO NOT EDIT MANUALLY - edit src/patterns/comprehensive-library.json instead * * Storage strategy: * - Patterns are bundled directly into Brainy for zero-latency access * - Embeddings are pre-computed and stored as binary Float32Array * - Total size: ~140KB (negligible for a neural library) * - No external files needed, works in all environments */ import type { Pattern } from './patternLibrary.js' // Pattern data embedded directly for reliability export const CORE_PATTERNS: Pattern[] = [ // Informational queries { id: "info_what_is", category: "informational", examples: ["what is artificial intelligence", "what is machine learning"], pattern: "what is (.+)", template: { like: "${1}" }, confidence: 0.9 }, { id: "info_how_does", category: "informational", examples: ["how does neural network work", "how does deep learning work"], pattern: "how does (.+) work", template: { like: "${1}" }, confidence: 0.85 }, // ... more patterns loaded from library.json at build time ] // Pre-computed embeddings as binary data // Generated by scripts/buildPatterns.ts using Brainy's embedding model export const PATTERN_EMBEDDINGS_BINARY: Uint8Array | null = null // Will be populated at build // Helper to decode embeddings export function getPatternEmbeddings(): Map { if (!PATTERN_EMBEDDINGS_BINARY) { return new Map() // Will compute at runtime if not pre-built } const embeddings = new Map() const view = new DataView(PATTERN_EMBEDDINGS_BINARY.buffer) const embeddingSize = 384 // Standard size CORE_PATTERNS.forEach((pattern, index) => { const offset = index * embeddingSize * 4 // 4 bytes per float const embedding = new Float32Array(embeddingSize) for (let i = 0; i < embeddingSize; i++) { embedding[i] = view.getFloat32(offset + i * 4, true) } embeddings.set(pattern.id, embedding) }) return embeddings } // Version for cache invalidation export const PATTERNS_VERSION = "2.0.0" // Export metadata for monitoring export const PATTERNS_METADATA = { totalPatterns: CORE_PATTERNS.length, categories: [...new Set(CORE_PATTERNS.map(p => p.category))], embeddingDimensions: 384, storageSize: { patterns: "24KB", embeddings: "98KB", total: "122KB" } }