![Brainy Logo](brainy.png) [![npm version](https://badge.fury.io/js/%40soulcraft%2Fbrainy.svg)](https://badge.fury.io/js/%40soulcraft%2Fbrainy) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Node.js](https://img.shields.io/badge/node-%3E%3D24.4.1-brightgreen.svg)](https://nodejs.org/) [![TypeScript](https://img.shields.io/badge/TypeScript-5.4.5-blue.svg)](https://www.typescriptlang.org/) # BRAINY: The Brain in a Jar Databaseโ„ข **The world's only Vector + Graph + AI database and realtime data platform** *Zero-to-Smartโ„ข technology that thinks so you don't have to*
--- ## ๐Ÿš€ THE AMAZING BRAINY: See It In Action! ```javascript import { BrainyData } from '@soulcraft/brainy' // ๐Ÿงช Initialize your brain-in-a-jar const brainy = new BrainyData() // Zero config - it's ALIVE! await brainy.init() // ๐Ÿ”ฌ Feed it knowledge with relationships const openai = await brainy.add("OpenAI", { type: "company", funding: 11000000 }) const gpt4 = await brainy.add("GPT-4", { type: "product", users: 100000000 }) await brainy.relate(openai, gpt4, "develops") // โšก One query to rule them all - Vector + Graph + Faceted search! const results = await brainy.search("AI language models", 5, { metadata: { funding: { $gte: 10000000 } }, // MongoDB-style filtering includeVerbs: true // Graph relationships }) // Plus semantic vector search! ``` **๐ŸŽญ 8 lines. Three search paradigms. One brain-powered database.** ## ๐Ÿ’ซ WHY BRAINY? The Problem We Solve ### โŒ The Old Way: Database Frankenstein ``` Pinecone ($$$) + Neo4j ($$$) + Elasticsearch ($$$) + Sync Hell = ๐Ÿ˜ฑ ``` ### โœ… The Brainy Way: One Smart Brain ``` Vector Search + Graph Relations + Metadata Filtering + AI Intelligence = ๐Ÿง โœจ ``` **Your data gets a brain upgrade. No assembly required.** ## โšก QUICK & EASY: From Zero to Smart in 60 Seconds ### Installation ```bash npm install @soulcraft/brainy ``` ### Your First Brainy App ```javascript import { BrainyData } from '@soulcraft/brainy' // It's alive! (No config needed) const brainy = new BrainyData() await brainy.init() // Feed your brain some data await brainy.add("Tesla", { type: "company", sector: "automotive" }) await brainy.add("SpaceX", { type: "company", sector: "aerospace" }) // Ask it questions (semantic search) const similar = await brainy.search("electric vehicles") // Use relationships (graph database) await brainy.relate("Tesla", "SpaceX", "shares_founder_with") // Filter like MongoDB (faceted search) const results = await brainy.search("innovation", { metadata: { sector: "automotive" } }) ``` ## ๐ŸŽ† NEW! Talk to Your Data with Brainy Chat ```javascript import { BrainyChat } from '@soulcraft/brainy' const chat = new BrainyChat(brainy) // Your data becomes conversational! const answer = await chat.ask("What patterns do you see in customer behavior?") // โ†’ AI-powered insights from your knowledge graph! ``` **How it works:** Combines vector embeddings for semantic understanding โ€ข Graph relationships for connection patterns โ€ข Metadata filtering for structured analysis โ€ข Optional LLM for natural language insights **One line. Zero complexity. Optional LLM for genius-level responses.** [๐Ÿ“– **Learn More About Brainy Chat**](BRAINY-CHAT.md) ## ๐ŸŽฎ NEW! Brainy CLI - Command Center from the Future ### ๐Ÿ’ฌ Talk to Your Data ```bash # Have conversations with your knowledge graph brainy chat "What patterns exist in customer behavior?" brainy chat "Show me all connections between startups" ``` ### ๐Ÿ“ฅ Add & Import Data ```bash # Import with AI understanding brainy import data.csv --cortex --understand # Add individual items brainy add "OpenAI" --type company --metadata '{"founded": 2015}' # Bulk import with relationships brainy import relationships.json --detect-entities ``` ### ๐Ÿ” Explore & Query ```bash # Search semantically brainy search "artificial intelligence companies" # Query with filters brainy query --filter 'funding>1000000' --type company # Visualize relationships brainy graph "OpenAI" --depth 2 --format ascii ``` ### ๐Ÿ”„ Manage & Migrate ```bash # Export your brain brainy export my-brain.json --include-embeddings # Migrate between storage backends brainy migrate s3://old-bucket file://new-location # Backup and restore brainy backup --compress brainy restore backup-2024.tar.gz ``` ### ๐Ÿ” Environment & Secrets ```bash # Store configuration securely brainy config set api.key "sk-..." --encrypt brainy config set storage.s3.bucket "my-brain" # Load environment profiles brainy env use production brainy env create staging --from .env.staging ``` ### ๐Ÿ“Š Monitor & Optimize ```bash # Real-time dashboard brainy monitor --dashboard # Performance analysis brainy stats --detailed brainy optimize index --auto ``` **Command your data empire from the terminal!** [๐Ÿ“– **Full CLI Documentation**](docs/brainy-cli.md) ## ๐Ÿงฌ NEW! Cortex AI - Your Data Gets a PhD **Cortex automatically understands and enhances your data:** ```javascript // Enable Cortex Intelligence during import const brainy = new BrainyData({ cortex: { enabled: true, autoDetect: true // Automatically identify entities & relationships } }) // Import with understanding await brainy.cortexImport('customers.csv', { understand: true, // AI analyzes data structure detectRelations: true, // Finds hidden connections confidence: 0.8 // Quality threshold }) ``` **Your data becomes self-aware (in a good way)!** ## ๐Ÿ”Œ NEW! Augmentation Pipeline - Plug in Superpowers **8 types of augmentations to enhance your brain:** ```javascript // Add augmentations like installing apps on your brain brainy.augment({ type: 'PERCEPTION', // Visual/pattern recognition handler: myPerceptor }) brainy.augment({ type: 'COGNITION', // Deep thinking & analysis handler: myThinker }) // Premium augmentations (coming soon!) brainy.augment({ type: 'NOTION_SYNC', // Bi-directional Notion sync license: 'premium' }) ``` **Augmentation Types:** - ๐ŸŽฏ **SENSE** - Input processing - ๐Ÿง  **MEMORY** - Long-term storage - ๐Ÿ’ญ **COGNITION** - Deep analysis - ๐Ÿ”— **CONDUIT** - Data flow - โšก **ACTIVATION** - Triggers & events - ๐Ÿ‘๏ธ **PERCEPTION** - Pattern recognition - ๐Ÿ’ฌ **DIALOG** - Conversational AI - ๐ŸŒ **WEBSOCKET** - Real-time sync ## ๐Ÿ’ช POWERFUL FEATURES: What Makes Brainy Special ### โšก Performance That Defies Science ``` Vector Search (1M embeddings): 2-8ms latency ๐Ÿš€ Graph Traversal (100M relations): 1-3ms latency ๐Ÿ”ฅ Combined Vector+Graph+Filter: 5-15ms latency โšก Throughput: 10K+ queries/sec ๐Ÿ’ซ ``` ### ๐ŸŒ Write Once, Run Anywhere (Literally) - **Browser**: Uses OPFS, Web Workers - works offline! - **Node.js**: FileSystem, Worker Threads - server-ready! - **Edge/Serverless**: Memory-optimized - deploys anywhere! - **React/Vue/Angular**: Same code, automatic optimization! ### ๐Ÿ”ฎ The Power of Three-in-One Search ```javascript // This ONE query replaces THREE databases: const results = await brainy.search("AI startups in healthcare", 10, { // ๐Ÿ” Vector: Semantic similarity includeVerbs: true, // ๐Ÿ”— Graph: Relationship traversal verbTypes: ["invests_in", "partners_with"], // ๐Ÿ“Š Faceted: MongoDB-style filtering metadata: { industry: "healthcare", funding: { $gte: 1000000 }, stage: { $in: ["Series A", "Series B"] } } }) ``` ### ๐Ÿง  Self-Learning & Auto-Optimization **Brainy gets smarter the more you use it:** - Auto-indexes frequently searched fields - Learns query patterns for faster responses - Optimizes storage based on access patterns - Self-configures for your environment ## ๐ŸŽญ ADVANCED FEATURES: For Mad Scientists ### ๐Ÿ”ฌ MongoDB-Style Query Operators ```javascript const results = await brainy.search("quantum computing", { metadata: { $and: [ { price: { $gte: 100, $lte: 1000 } }, { category: { $in: ["electronics", "computing"] } }, { $or: [ { brand: "Intel" }, { brand: "IBM" } ] }, { tags: { $includes: "quantum" } }, { description: { $regex: "qubit|superposition" } } ] } }) ``` **15+ operators**: `$gt`, `$gte`, `$lt`, `$lte`, `$eq`, `$ne`, `$in`, `$nin`, `$regex`, `$includes`, `$all`, `$size`, `$and`, `$or`, `$not` ### ๐Ÿงช Specialized Deployment Modes ```javascript // High-speed data ingestion const writer = new BrainyData({ writeOnly: true, allowDirectReads: true // For deduplication }) // Read-only search cluster const reader = new BrainyData({ readOnly: true, frozen: true // Maximum performance }) // Custom storage backend const custom = new BrainyData({ storage: { type: 's3', s3Storage: { bucketName: 'my-brain', region: 'us-east-1' } } }) ``` ### ๐Ÿš€ Framework Integration Examples
๐Ÿ“ฆ See Framework Examples #### React ```jsx import { BrainyData } from '@soulcraft/brainy' function App() { const [brainy] = useState(() => new BrainyData()) useEffect(() => { brainy.init() }, []) const search = async (query) => { return await brainy.search(query, 10) } return } ``` #### Vue 3 ```vue ``` #### Angular ```typescript @Injectable({ providedIn: 'root' }) export class BrainyService { private brainy = new BrainyData() async init() { await this.brainy.init() } search(query: string) { return this.brainy.search(query, 10) } } ```
### ๐Ÿณ Docker & Cloud Deployment ```dockerfile FROM node:24-slim WORKDIR /app COPY . . RUN npm install RUN npm run download-models # Bundle models for offline use CMD ["node", "server.js"] ``` Deploy to AWS, GCP, Azure, Cloudflare Workers, anywhere! ## ๐Ÿ’Ž Premium Features (Optional) **Core Brainy is FREE forever. Premium augmentations for enterprise:** ### ๐Ÿ”— Enterprise Connectors (Coming Soon!) - **Notion** ($49/mo) - Bi-directional workspace sync - **Salesforce** ($99/mo) - CRM integration - **Slack** ($49/mo) - Team knowledge capture - **Asana** ($44/mo) - Project intelligence ```bash brainy augment trial notion # Start 14-day free trial ``` ## ๐ŸŽจ What You Can Build **The only limit is your imagination:** - **๐Ÿค– AI Assistants** - ChatGPT with perfect memory - **๐Ÿ” Semantic Search** - Find by meaning, not keywords - **๐ŸŽฏ Recommendation Engines** - Netflix-level suggestions - **๐Ÿงฌ Knowledge Graphs** - Wikipedia meets Neo4j - **๐Ÿ‘๏ธ Computer Vision** - Search images by content - **๐ŸŽต Music Discovery** - Spotify's algorithm in your app - **๐Ÿ“š Smart Documentation** - Self-answering docs - **๐Ÿ›ก๏ธ Fraud Detection** - Pattern recognition on steroids - **๐ŸŒ Real-time Collaboration** - Multiplayer knowledge bases - **๐Ÿฅ Medical Diagnosis** - Symptom matching with AI ## ๐Ÿ“š Complete Documentation ### Getting Started - [**Quick Start Guide**](docs/getting-started/) - Up and running in 5 minutes - [**Installation**](docs/getting-started/installation.md) - All environments covered - [**Basic Concepts**](docs/getting-started/concepts.md) - Understand the brain ### Core Features - [**API Reference**](docs/api-reference/) - Every method documented - [**Search Guide**](docs/api-reference/search.md) - Master all search types - [**Graph Operations**](docs/api-reference/graph.md) - Relationships explained - [**MongoDB Operators**](docs/api-reference/operators.md) - Query like a pro ### Advanced Topics - [**Brainy CLI**](docs/brainy-cli.md) - Command-line superpowers - [**Brainy Chat**](BRAINY-CHAT.md) - Conversational AI interface - [**Cortex AI**](CORTEX.md) - Intelligence augmentation - [**Augmentation Pipeline**](docs/augmentations/) - Plugin architecture - [**Performance Tuning**](docs/optimization-guides/) - Speed optimization - [**Deployment Guide**](docs/deployment/) - Production best practices ### Examples & Tutorials - [**Example Apps**](docs/examples/) - Full applications - [**Code Recipes**](docs/examples/recipes.md) - Common patterns - [**Video Tutorials**](docs/tutorials/) - Visual learning ## ๐Ÿ†š Why Not Just Use...? ### vs. Multiple Databases โŒ **Pinecone + Neo4j + Elasticsearch** = 3x cost, sync nightmares, 3 APIs โœ… **Brainy** = One database, always synced, one simple API ### vs. Cloud-Only Vector DBs โŒ **Pinecone/Weaviate** = Vendor lock-in, expensive, cloud-only โœ… **Brainy** = Run anywhere, own your data, pay once ### vs. Traditional Graph DBs โŒ **Neo4j + vector plugin** = Bolt-on solution, limited capabilities โœ… **Brainy** = Native vector+graph from the ground up ## ๐Ÿš€ Real-World Performance & Scale **How Brainy handles production workloads:** ### ๐Ÿ“Š Benchmark Numbers - **10M vectors**: 5-15ms search latency (p95) - **100M relationships**: 1-3ms traversal - **Metadata filtering**: O(1) field access via hybrid indexing - **Concurrent queries**: 10,000+ QPS on single instance - **Index size**: ~100 bytes per vector (384 dims) ### ๐ŸŽฏ Scaling Strategies **Scale Up (Vertical)** ```javascript // Optimize for large datasets on single machine const brainy = new BrainyData({ hnsw: { maxConnections: 32, // More connections = better recall efConstruction: 400, // Higher quality index efSearch: 100 // More accurate search } }) ``` **Scale Out (Horizontal)** ```javascript // Shard by category for distributed deployment const shards = { products: new BrainyData({ defaultService: 'products-shard' }), users: new BrainyData({ defaultService: 'users-shard' }), content: new BrainyData({ defaultService: 'content-shard' }) } // Or use read/write separation const writer = new BrainyData({ writeOnly: true }) const readers = [/* multiple read replicas */] ``` ### ๐Ÿ—๏ธ Architecture That Scales โœ… **Distributed Index** - Partition by metadata fields or ID ranges โœ… **Smart Partitioning** - Semantic clustering or hash-based sharding โœ… **Real-time Sync** - WebRTC & WebSocket for live collaboration โœ… **GPU Acceleration** - Auto-detected for embeddings when available โœ… **Metadata Index** - Separate B-tree indexes for fast filtering โœ… **Memory Mapped Files** - Handle datasets larger than RAM โœ… **Streaming Ingestion** - Process millions of items without OOM โœ… **Progressive Loading** - Start serving queries before full index load ## ๐Ÿ›ธ Recent Updates ### ๐ŸŽฏ v0.57.0 - The Cortex Revolution - Renamed CLI from "neural" to "brainy" - Cortex AI for data understanding - Augmentation pipeline system - Premium connectors framework ### โšก v0.46-v0.51 - Performance Revolution - 95% package size reduction - MongoDB query operators - Filter discovery API - Transformers.js migration - True offline operation ## ๐Ÿค Contributing We welcome contributions! See [Contributing Guidelines](CONTRIBUTING.md) ## ๐Ÿ“„ License [MIT](LICENSE) - Core Brainy is FREE forever ---
## ๐Ÿง  Ready to Give Your Data a Brain? **[Get Started โ†’](docs/getting-started/) | [Examples โ†’](docs/examples/)** *Zero-to-Smartโ„ข - Because your data deserves a brain upgrade* **Built with โค๏ธ by [Soulcraft Research](https://soulcraft.com)** *Powered by the BXL9000โ„ข Cognitive Engine*