2025-08-05 16:09:30 -07:00
|
|
|
|
<div align="center>
|
2025-06-24 11:41:30 -07:00
|
|
|
|
<img src="./brainy.png" alt="Brainy Logo" width="200"/>
|
|
|
|
|
|
<br/><br/>
|
|
|
|
|
|
|
|
|
|
|
|
[](LICENSE)
|
**feat(tests, docs, storage): add statistics storage tests and enhance documentation**
- **Tests**: Added new `statistics-storage.test.ts` to validate statistics storage functionality across scenarios including saving, retrieving, time-based partitioning, and backward compatibility. Ensured tests dynamically handle missing environment variables by skipping S3-related tests when credentials are unavailable.
- **Docs**: Enhanced `statistics.md` with detailed explanations of scalability improvements, including adaptive flush timing, batched updates, and time-based partitioning. Improved readability and structure.
- **Storage**: Updated all storage adapters to integrate time-based partitioning and maintain backward compatibility with legacy statistics storage formats.
- **Dependencies**: Added `dotenv` to support environmental variable management for storage adapter tests.
**Purpose**: Strengthen system reliability by adding comprehensive test coverage for statistics storage, improve scalability documentation, and ensure consistency across storage adapters with robust implementations.
2025-07-24 16:24:02 -07:00
|
|
|
|
[](https://nodejs.org/)
|
2025-07-04 12:19:48 -07:00
|
|
|
|
[](https://www.typescriptlang.org/)
|
2025-06-24 11:41:30 -07:00
|
|
|
|
[](CONTRIBUTING.md)
|
|
|
|
|
|
|
2025-08-04 08:56:05 -07:00
|
|
|
|
**A powerful graph & vector data platform for AI applications across any environment**
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-08-05 19:29:59 -07:00
|
|
|
|
## 🔥 MAJOR UPDATE: TensorFlow.js → Transformers.js Migration (v0.46+)
|
|
|
|
|
|
|
|
|
|
|
|
**We've completely replaced TensorFlow.js with Transformers.js for better performance and true offline operation!**
|
|
|
|
|
|
|
|
|
|
|
|
### Why We Made This Change
|
|
|
|
|
|
|
|
|
|
|
|
**The Honest Truth About TensorFlow.js:**
|
|
|
|
|
|
|
|
|
|
|
|
- 📦 **Massive Package Size**: 12.5MB+ packages with complex dependency trees
|
|
|
|
|
|
- 🌐 **Hidden Network Calls**: Even "local" models triggered fetch() calls internally
|
|
|
|
|
|
- 🐛 **Dependency Hell**: Constant `--legacy-peer-deps` issues with Node.js updates
|
|
|
|
|
|
- 🔧 **Maintenance Burden**: 47+ dependencies to keep compatible across environments
|
|
|
|
|
|
- 💾 **Huge Models**: 525MB Universal Sentence Encoder models
|
|
|
|
|
|
|
|
|
|
|
|
### What You Get Now
|
|
|
|
|
|
|
|
|
|
|
|
- ✅ **95% Smaller Package**: 643 kB vs 12.5 MB (and it actually works better!)
|
|
|
|
|
|
- ✅ **84% Smaller Models**: 87 MB vs 525 MB all-MiniLM-L6-v2 vs USE
|
|
|
|
|
|
- ✅ **True Offline Operation**: Zero network calls after initial model download
|
|
|
|
|
|
- ✅ **5x Fewer Dependencies**: Clean dependency tree, no more peer dep issues
|
|
|
|
|
|
- ✅ **Same API**: Drop-in replacement - your existing code just works
|
|
|
|
|
|
- ✅ **Better Performance**: ONNX Runtime is faster than TensorFlow.js in most cases
|
|
|
|
|
|
|
|
|
|
|
|
### Migration (It's Automatic!)
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
// Your existing code works unchanged!
|
|
|
|
|
|
import { BrainyData } from '@soulcraft/brainy'
|
|
|
|
|
|
|
|
|
|
|
|
const db = new BrainyData({
|
|
|
|
|
|
embedding: { type: 'transformer' } // Now uses Transformers.js automatically
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Dimensions changed from 512 → 384 (handled automatically)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**For Docker/Production or No Egress:**
|
|
|
|
|
|
|
|
|
|
|
|
```dockerfile
|
|
|
|
|
|
RUN npm install @soulcraft/brainy
|
|
|
|
|
|
RUN npm run download-models # Download during build for offline production
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
## ✨ What is Brainy?
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
Imagine a database that thinks like you do - connecting ideas, finding patterns, and getting smarter over time. Brainy
|
|
|
|
|
|
is the **AI-native database** that brings vector search and knowledge graphs together in one powerful, ridiculously
|
|
|
|
|
|
easy-to-use package.
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
### 🆕 NEW: Distributed Mode (v0.38+)
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
**Scale horizontally with zero configuration!** Brainy now supports distributed deployments with automatic coordination:
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
- **🌐 Multi-Instance Coordination** - Multiple readers and writers working in harmony
|
|
|
|
|
|
- **🏷️ Smart Domain Detection** - Automatically categorizes data (medical, legal, product, etc.)
|
|
|
|
|
|
- **📊 Real-Time Health Monitoring** - Track performance across all instances
|
|
|
|
|
|
- **🔄 Automatic Role Optimization** - Readers optimize for cache, writers for throughput
|
|
|
|
|
|
- **🗂️ Intelligent Partitioning** - Hash-based partitioning for perfect load distribution
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### 🚀 Why Developers Love Brainy
|
**feat(web-service): add new web service package and deployment scripts**
- **New Web Service Package**:
- Introduced `@soulcraft/brainy-web-service`, a REST API wrapper for the Brainy vector graph database.
- Added documentation and features to support secure, read-only search and retrieval operations.
- **Deployment Support**:
- Included comprehensive deployment instructions in the `web-service-package/README.md`:
- Options for Docker, serverless platforms, and cloud providers (AWS, GCP, Azure, Cloudflare).
- Example configurations for systemd, Nginx, and Docker Compose.
- **Scripts and Documentation Updates**:
- Added `deploy:web-service` script to `package.json` for streamlined build and publishing.
- Enhanced `README.md` to reflect the introduction of the web service package and its capabilities.
- **Purpose**:
- This update extends Brainy’s functionality by providing a production-ready, easy-to-deploy REST API for search operations. It ensures flexibility for diverse deployment scenarios while maintaining security and high performance.
2025-07-22 10:22:38 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
- **🧠 Zero-to-Smart™** - No config files, no tuning parameters, no DevOps headaches. Brainy auto-detects your
|
|
|
|
|
|
environment and optimizes itself
|
2025-08-05 16:09:30 -07:00
|
|
|
|
- **🌍 True Write-Once, Run-Anywhere** - Same code runs in Angular, React, Vue, Node.js, Deno, Bun, serverless, edge
|
|
|
|
|
|
workers, and web workers with automatic environment detection
|
2025-08-05 20:00:04 -07:00
|
|
|
|
- **⚡ Scary Fast** - Handles millions of vectors with sub-millisecond search. GPU acceleration for embeddings, optimized CPU for distance calculations
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- **🎯 Self-Learning** - Like having a database that goes to the gym. Gets faster and smarter the more you use it
|
|
|
|
|
|
- **🔮 AI-First Design** - Built for the age of embeddings, RAG, and semantic search. Your LLMs will thank you
|
|
|
|
|
|
- **🎮 Actually Fun to Use** - Clean API, great DX, and it does the heavy lifting so you can build cool stuff
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
### 🚀 NEW: Ultra-Fast Search Performance + Auto-Configuration
|
|
|
|
|
|
|
|
|
|
|
|
**Your searches just got 100x faster AND Brainy now configures itself!** Advanced performance with zero setup:
|
|
|
|
|
|
|
|
|
|
|
|
- **🤖 Intelligent Auto-Configuration** - Detects environment and usage patterns, optimizes automatically
|
|
|
|
|
|
- **⚡ Smart Result Caching** - Repeated queries return in <1ms with automatic cache invalidation
|
|
|
|
|
|
- **📄 Cursor-Based Pagination** - Navigate millions of results with constant O(k) performance
|
|
|
|
|
|
- **🔄 Real-Time Data Sync** - Cache automatically updates when data changes, even in distributed scenarios
|
|
|
|
|
|
- **📊 Performance Monitoring** - Built-in hit rate and memory usage tracking with adaptive optimization
|
|
|
|
|
|
- **🎯 Zero Breaking Changes** - All existing code works unchanged, just faster and smarter
|
|
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
## 📦 Get Started in 30 Seconds
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
npm install @soulcraft/brainy
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
```javascript
|
2025-08-05 15:34:39 -07:00
|
|
|
|
import { BrainyData } from '@soulcraft/brainy'
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
const brainy = new BrainyData()
|
|
|
|
|
|
await brainy.init() // Auto-detects your environment
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
// Add some data
|
|
|
|
|
|
await brainy.add("The quick brown fox jumps over the lazy dog")
|
2025-08-05 16:09:30 -07:00
|
|
|
|
await brainy.add("A fast fox leaps over a sleeping dog")
|
2025-08-05 15:34:39 -07:00
|
|
|
|
await brainy.add("Cats are independent and mysterious animals")
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
// Vector search finds similar content
|
|
|
|
|
|
const results = await brainy.search("speedy animals jumping", 2)
|
|
|
|
|
|
console.log(results) // Finds the fox sentences!
|
2025-08-04 14:33:39 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
**🎯 That's it!** You just built semantic search in 4 lines. Works in Angular, React, Vue, Node.js, browsers,
|
|
|
|
|
|
serverless - everywhere.
|
2025-07-24 11:13:03 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
## 🚀 The Magic: Vector + Graph Database
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
**Most databases do one thing.** Brainy does both vector similarity AND graph relationships:
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
// Add entities with relationships
|
|
|
|
|
|
const companyId = await brainy.addNoun("OpenAI creates powerful AI models", "company")
|
|
|
|
|
|
const productId = await brainy.addNoun("GPT-4 is a large language model", "product")
|
|
|
|
|
|
|
|
|
|
|
|
// Connect them with relationships
|
|
|
|
|
|
await brainy.addVerb(companyId, productId, undefined, { type: "develops" })
|
|
|
|
|
|
|
|
|
|
|
|
// Now you can do BOTH:
|
|
|
|
|
|
const similar = await brainy.search("AI language models") // Vector similarity
|
|
|
|
|
|
const products = await brainy.getVerbsByType("develops") // Graph traversal
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
**Why this matters:** Find content by meaning AND follow relationships. It's like having PostgreSQL and Pinecone working
|
|
|
|
|
|
together seamlessly.
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
### 🔍 Want More Power?
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- **Advanced graph traversal** - Complex relationship queries and multi-hop searches
|
2025-08-05 16:09:30 -07:00
|
|
|
|
- **Distributed clustering** - Scale across multiple instances with automatic coordination
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- **Real-time syncing** - WebSocket and WebRTC for live data updates
|
|
|
|
|
|
- **Custom augmentations** - Extend Brainy with your own functionality
|
2025-08-03 17:22:32 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
*[See full API documentation below](#-installation) for advanced features*
|
|
|
|
|
|
|
|
|
|
|
|
## 🎨 Build Amazing Things
|
|
|
|
|
|
|
|
|
|
|
|
**🤖 AI Chat Applications** - Build ChatGPT-like apps with long-term memory and context awareness
|
|
|
|
|
|
**🔍 Semantic Search Engines** - Search by meaning, not keywords. Find "that thing that's like a cat but bigger" →
|
|
|
|
|
|
returns "tiger"
|
|
|
|
|
|
**🎯 Recommendation Engines** - "Users who liked this also liked..." but actually good
|
|
|
|
|
|
**🧬 Knowledge Graphs** - Connect everything to everything. Wikipedia meets Neo4j meets magic
|
|
|
|
|
|
**👁️ Computer Vision Apps** - Store and search image embeddings. "Find all photos with dogs wearing hats"
|
|
|
|
|
|
**🎵 Music Discovery** - Find songs that "feel" similar. Spotify's Discover Weekly in your app
|
|
|
|
|
|
**📚 Smart Documentation** - Docs that answer questions. "How do I deploy to production?" → relevant guides
|
|
|
|
|
|
**🛡️ Fraud Detection** - Find patterns humans can't see. Anomaly detection on steroids
|
|
|
|
|
|
**🌐 Real-Time Collaboration** - Sync vector data across devices. Figma for AI data
|
|
|
|
|
|
**🏥 Medical Diagnosis Tools** - Match symptoms to conditions using embedding similarity
|
|
|
|
|
|
|
|
|
|
|
|
## 🚀 Write-Once, Run-Anywhere Quick Start
|
|
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
Brainy uses the same code across all environments with automatic detection. **Framework-optimized** for the best
|
|
|
|
|
|
developer experience. Choose your environment:
|
2025-08-05 15:34:39 -07:00
|
|
|
|
|
|
|
|
|
|
### 🅰️ Angular (Latest)
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
npm install @soulcraft/brainy
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
|
import { Component, signal, OnInit } from '@angular/core'
|
|
|
|
|
|
import { BrainyData } from '@soulcraft/brainy'
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
|
selector: 'app-search',
|
|
|
|
|
|
template: `
|
|
|
|
|
|
<div class="search-container">
|
|
|
|
|
|
<input [(ngModel)]="query"
|
|
|
|
|
|
(input)="search($event.target.value)"
|
|
|
|
|
|
placeholder="Search by meaning (try 'pets' or 'food')..."
|
|
|
|
|
|
class="search-input">
|
|
|
|
|
|
|
|
|
|
|
|
<div class="results">
|
|
|
|
|
|
@for (result of results(); track result.id) {
|
|
|
|
|
|
<div class="result-item">
|
|
|
|
|
|
<strong>{{result.metadata?.category}}</strong>: {{result.metadata?.originalData}}
|
|
|
|
|
|
<small>Similarity: {{result.score | number:'1.2-2'}}</small>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
`
|
2025-06-24 11:41:30 -07:00
|
|
|
|
})
|
2025-08-05 15:34:39 -07:00
|
|
|
|
export class SearchComponent implements OnInit {
|
|
|
|
|
|
private brainy: BrainyData | null = null
|
|
|
|
|
|
results = signal<any[]>([])
|
|
|
|
|
|
query = ''
|
|
|
|
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
|
|
// Auto-detects environment and uses OPFS storage in browsers
|
|
|
|
|
|
this.brainy = new BrainyData({
|
|
|
|
|
|
defaultService: 'my-app'
|
|
|
|
|
|
})
|
|
|
|
|
|
await this.brainy.init()
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
// Add sample data
|
|
|
|
|
|
await this.brainy.add("Cats are amazing pets", { category: "animals" })
|
2025-08-05 16:09:30 -07:00
|
|
|
|
await this.brainy.add("Dogs love to play fetch", { category: "animals" })
|
2025-08-05 15:34:39 -07:00
|
|
|
|
await this.brainy.add("Pizza is delicious food", { category: "food" })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async search(query: string) {
|
|
|
|
|
|
if (!query.trim() || !this.brainy) {
|
|
|
|
|
|
this.results.set([])
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
const searchResults = await this.brainy.search(query, 5)
|
|
|
|
|
|
this.results.set(searchResults)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### ⚛️ React
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
npm install @soulcraft/brainy
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
```jsx
|
|
|
|
|
|
import { BrainyData } from '@soulcraft/brainy'
|
|
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
|
|
|
|
|
|
|
function SemanticSearch() {
|
|
|
|
|
|
const [brainy, setBrainy] = useState(null)
|
|
|
|
|
|
const [results, setResults] = useState([])
|
|
|
|
|
|
const [query, setQuery] = useState('')
|
|
|
|
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
async function initBrainy() {
|
|
|
|
|
|
// Auto-detects environment and uses OPFS storage in browsers
|
|
|
|
|
|
const db = new BrainyData({
|
|
|
|
|
|
defaultService: 'my-app'
|
|
|
|
|
|
})
|
|
|
|
|
|
await db.init()
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
// Add sample data
|
|
|
|
|
|
await db.add("Cats are amazing pets", { category: "animals" })
|
|
|
|
|
|
await db.add("Dogs love to play fetch", { category: "animals" })
|
|
|
|
|
|
await db.add("Pizza is delicious food", { category: "food" })
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
setBrainy(db)
|
|
|
|
|
|
setLoading(false)
|
|
|
|
|
|
}
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
initBrainy()
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
const search = async (searchQuery) => {
|
|
|
|
|
|
if (!searchQuery.trim() || !brainy) return setResults([])
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
const searchResults = await brainy.search(searchQuery, 5)
|
|
|
|
|
|
setResults(searchResults)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (loading) return <div>Initializing Brainy...</div>
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="search-container">
|
2025-08-05 16:09:30 -07:00
|
|
|
|
<input
|
2025-08-05 15:34:39 -07:00
|
|
|
|
value={query}
|
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
|
setQuery(e.target.value)
|
|
|
|
|
|
search(e.target.value)
|
|
|
|
|
|
}}
|
|
|
|
|
|
placeholder="Search by meaning (try 'pets' or 'food')..."
|
|
|
|
|
|
className="search-input"
|
|
|
|
|
|
/>
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
<div className="results">
|
|
|
|
|
|
{results.map((result, i) => (
|
|
|
|
|
|
<div key={result.id} className="result-item">
|
|
|
|
|
|
<strong>{result.metadata?.category}</strong>: {result.metadata?.originalData}
|
|
|
|
|
|
<small>Similarity: {result.score.toFixed(2)}</small>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
export default SemanticSearch
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 🌟 Vue 3
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
npm install @soulcraft/brainy
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
```vue
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="search-container">
|
2025-08-05 16:09:30 -07:00
|
|
|
|
<input
|
2025-08-05 15:34:39 -07:00
|
|
|
|
v-model="query"
|
|
|
|
|
|
@input="search"
|
|
|
|
|
|
placeholder="Search by meaning (try 'pets' or 'food')..."
|
|
|
|
|
|
class="search-input"
|
|
|
|
|
|
/>
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
<div v-if="loading" class="loading">
|
|
|
|
|
|
Initializing Brainy...
|
|
|
|
|
|
</div>
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
<div v-else class="results">
|
2025-08-05 16:09:30 -07:00
|
|
|
|
<div
|
|
|
|
|
|
v-for="result in results"
|
|
|
|
|
|
:key="result.id"
|
2025-08-05 15:34:39 -07:00
|
|
|
|
class="result-item"
|
|
|
|
|
|
>
|
|
|
|
|
|
<strong>{{ result.metadata?.category }}</strong>: {{ result.metadata?.originalData }}
|
|
|
|
|
|
<small>Similarity: {{ result.score.toFixed(2) }}</small>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-08-05 16:09:30 -07:00
|
|
|
|
import { BrainyData } from '@soulcraft/brainy'
|
|
|
|
|
|
import { ref, onMounted } from 'vue'
|
|
|
|
|
|
|
|
|
|
|
|
const brainy = ref(null)
|
|
|
|
|
|
const results = ref([])
|
|
|
|
|
|
const query = ref('')
|
|
|
|
|
|
const loading = ref(true)
|
2025-08-05 15:34:39 -07:00
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
// Auto-detects environment and uses OPFS storage in browsers
|
|
|
|
|
|
const db = new BrainyData({
|
|
|
|
|
|
defaultService: 'my-app'
|
|
|
|
|
|
})
|
|
|
|
|
|
await db.init()
|
2025-08-05 15:34:39 -07:00
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
// Add sample data
|
|
|
|
|
|
await db.add("Cats are amazing pets", { category: "animals" })
|
|
|
|
|
|
await db.add("Dogs love to play fetch", { category: "animals" })
|
|
|
|
|
|
await db.add("Pizza is delicious food", { category: "food" })
|
|
|
|
|
|
|
|
|
|
|
|
brainy.value = db
|
|
|
|
|
|
loading.value = false
|
2025-08-05 15:34:39 -07:00
|
|
|
|
})
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
const search = async () => {
|
|
|
|
|
|
if (!query.value.trim() || !brainy.value) {
|
|
|
|
|
|
results.value = []
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const searchResults = await brainy.value.search(query.value, 5)
|
|
|
|
|
|
results.value = searchResults
|
2025-08-05 15:34:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2025-08-05 16:09:30 -07:00
|
|
|
|
.search-container {
|
|
|
|
|
|
max-width: 600px;
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
padding: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.search-input {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
border: 2px solid #ddd;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.result-item {
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
border: 1px solid #eee;
|
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
color: #666;
|
|
|
|
|
|
}
|
2025-08-05 15:34:39 -07:00
|
|
|
|
</style>
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 🟢 Node.js Server
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
npm install @soulcraft/brainy
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
import { BrainyData } from '@soulcraft/brainy'
|
|
|
|
|
|
|
|
|
|
|
|
// Auto-detects Node.js → FileSystem (local) or S3 (production), Worker threads
|
|
|
|
|
|
const brainy = new BrainyData({
|
|
|
|
|
|
defaultService: 'my-app',
|
|
|
|
|
|
// Optional: Production S3 storage
|
|
|
|
|
|
storage: {
|
|
|
|
|
|
s3Storage: {
|
|
|
|
|
|
bucketName: process.env.S3_BUCKET,
|
|
|
|
|
|
region: process.env.AWS_REGION,
|
|
|
|
|
|
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
|
|
|
|
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-24 11:41:30 -07:00
|
|
|
|
})
|
2025-08-05 15:34:39 -07:00
|
|
|
|
await brainy.init()
|
|
|
|
|
|
|
|
|
|
|
|
// Same API everywhere
|
|
|
|
|
|
await brainy.add("Cats are amazing pets", { category: "animals" })
|
|
|
|
|
|
const results = await brainy.search("pets", 5)
|
|
|
|
|
|
console.log('Search results:', results)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### ⚡ Serverless (Vercel/Netlify)
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
import { BrainyData } from '@soulcraft/brainy'
|
|
|
|
|
|
|
|
|
|
|
|
export default async function handler(req, res) {
|
|
|
|
|
|
// Auto-detects serverless → S3/R2 storage for persistence, or Memory for temp
|
|
|
|
|
|
const brainy = new BrainyData({
|
|
|
|
|
|
defaultService: 'my-app',
|
|
|
|
|
|
// Optional: Explicit S3-compatible storage
|
|
|
|
|
|
storage: {
|
|
|
|
|
|
r2Storage: {
|
|
|
|
|
|
bucketName: process.env.R2_BUCKET,
|
|
|
|
|
|
accessKeyId: process.env.R2_ACCESS_KEY_ID,
|
|
|
|
|
|
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY,
|
|
|
|
|
|
accountId: process.env.R2_ACCOUNT_ID
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
await brainy.init()
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
// Same API everywhere
|
|
|
|
|
|
const results = await brainy.search(req.query.q, 5)
|
|
|
|
|
|
res.json({ results })
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 🔥 Cloudflare Workers
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
import { BrainyData } from '@soulcraft/brainy'
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
async fetch(request) {
|
|
|
|
|
|
// Auto-detects edge → Minimal footprint, KV storage
|
|
|
|
|
|
const brainy = new BrainyData({
|
|
|
|
|
|
defaultService: 'edge-app'
|
|
|
|
|
|
})
|
|
|
|
|
|
await brainy.init()
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
// Same API everywhere
|
|
|
|
|
|
const url = new URL(request.url)
|
|
|
|
|
|
const results = await brainy.search(url.searchParams.get('q'), 5)
|
|
|
|
|
|
return Response.json({ results })
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
### 🦕 Deno
|
|
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
|
import { BrainyData } from 'https://esm.sh/@soulcraft/brainy'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
// Auto-detects Deno → Native compatibility, FileSystem storage
|
|
|
|
|
|
const brainy = new BrainyData({
|
|
|
|
|
|
defaultService: 'deno-app'
|
2025-08-01 08:27:39 -07:00
|
|
|
|
})
|
2025-08-05 15:34:39 -07:00
|
|
|
|
await brainy.init()
|
2025-08-01 08:27:39 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
// Same API everywhere
|
|
|
|
|
|
await brainy.add("Deno is awesome", { category: "tech" })
|
|
|
|
|
|
const results = await brainy.search("technology", 5)
|
|
|
|
|
|
console.log(results)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**That's it! Same code, everywhere. Zero-to-Smart™**
|
|
|
|
|
|
|
|
|
|
|
|
Brainy automatically detects and optimizes for:
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- 🌐 **Browser frameworks** → OPFS storage, Web Workers, memory optimization
|
2025-08-05 16:09:30 -07:00
|
|
|
|
- 🟢 **Node.js servers** → FileSystem or S3/R2 storage, Worker threads, cluster support
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- ⚡ **Serverless functions** → S3/R2 or Memory storage, cold start optimization
|
|
|
|
|
|
- 🔥 **Edge workers** → Memory or KV storage, minimal footprint
|
|
|
|
|
|
- 🧵 **Web/Worker threads** → Shared storage, thread-safe operations
|
|
|
|
|
|
- 🦕 **Deno/Bun runtimes** → FileSystem or S3-compatible storage, native performance
|
|
|
|
|
|
|
|
|
|
|
|
### 🐳 NEW: Zero-Config Docker Deployment
|
|
|
|
|
|
|
|
|
|
|
|
**Deploy to any cloud with embedded models - no runtime downloads needed!**
|
|
|
|
|
|
|
|
|
|
|
|
```dockerfile
|
|
|
|
|
|
# One line extracts models automatically during build
|
2025-08-05 20:39:39 -07:00
|
|
|
|
RUN npm run download-models
|
2025-08-05 15:34:39 -07:00
|
|
|
|
|
|
|
|
|
|
# Deploy anywhere: Google Cloud, AWS, Azure, Cloudflare, etc.
|
2025-06-24 11:41:30 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- **⚡ 7x Faster Cold Starts** - Models embedded in container, no downloads
|
|
|
|
|
|
- **🌐 Universal Cloud Support** - Same Dockerfile works everywhere
|
|
|
|
|
|
- **🔒 Offline Ready** - No external dependencies at runtime
|
|
|
|
|
|
- **📦 Zero Configuration** - Automatic model detection and loading
|
|
|
|
|
|
|
|
|
|
|
|
See [Docker Deployment Guide](./docs/docker-deployment.md) for complete examples.
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
// Zero configuration - everything optimized automatically!
|
|
|
|
|
|
const brainy = new BrainyData() // Auto-detects environment & optimizes
|
|
|
|
|
|
await brainy.init()
|
|
|
|
|
|
|
|
|
|
|
|
// Caching happens automatically - no setup needed!
|
|
|
|
|
|
const results1 = await brainy.search('query', 10) // ~50ms first time
|
|
|
|
|
|
const results2 = await brainy.search('query', 10) // <1ms cached hit!
|
|
|
|
|
|
|
|
|
|
|
|
// Advanced pagination works instantly
|
|
|
|
|
|
const page1 = await brainy.searchWithCursor('query', 100)
|
|
|
|
|
|
const page2 = await brainy.searchWithCursor('query', 100, {
|
|
|
|
|
|
cursor: page1.cursor // Constant time, no matter how deep!
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Monitor auto-optimized performance
|
|
|
|
|
|
const stats = brainy.getCacheStats()
|
|
|
|
|
|
console.log(`Auto-tuned cache hit rate: ${(stats.search.hitRate * 100).toFixed(1)}%`)
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
### 🌐 Distributed Mode Example (NEW!)
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
// Writer Instance - Ingests data from multiple sources
|
|
|
|
|
|
const writer = createAutoBrainy({
|
2025-08-04 14:33:39 -07:00
|
|
|
|
storage: { s3Storage: { bucketName: 'my-bucket' } },
|
2025-08-04 12:18:58 -07:00
|
|
|
|
distributed: { role: 'writer' } // Explicit role for safety
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Reader Instance - Optimized for search queries
|
|
|
|
|
|
const reader = createAutoBrainy({
|
2025-08-04 14:33:39 -07:00
|
|
|
|
storage: { s3Storage: { bucketName: 'my-bucket' } },
|
2025-08-04 12:18:58 -07:00
|
|
|
|
distributed: { role: 'reader' } // 80% memory for cache
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Data automatically gets domain tags
|
2025-08-04 14:33:39 -07:00
|
|
|
|
await writer.add("Patient shows symptoms of...", {
|
2025-08-04 12:18:58 -07:00
|
|
|
|
diagnosis: "flu" // Auto-tagged as 'medical' domain
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Domain-aware search across all partitions
|
|
|
|
|
|
const results = await reader.search("medical symptoms", 10, {
|
|
|
|
|
|
filter: { domain: 'medical' } // Only search medical data
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Monitor health across all instances
|
|
|
|
|
|
const health = reader.getHealthStatus()
|
|
|
|
|
|
console.log(`Instance ${health.instanceId}: ${health.status}`)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
## 🎭 Key Features
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Core Capabilities
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- **Vector Search** - Find semantically similar content using embeddings
|
|
|
|
|
|
- **Graph Relationships** - Connect data with meaningful relationships
|
|
|
|
|
|
- **JSON Document Search** - Search within specific fields with prioritization
|
2025-08-04 12:18:58 -07:00
|
|
|
|
- **Distributed Mode** - Scale horizontally with automatic coordination between instances
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- **Real-Time Syncing** - WebSocket and WebRTC for distributed instances
|
|
|
|
|
|
- **Streaming Pipeline** - Process data in real-time as it flows through
|
|
|
|
|
|
- **Model Control Protocol** - Let AI models access your data
|
|
|
|
|
|
|
|
|
|
|
|
### Developer Experience
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- **TypeScript Support** - Fully typed API with generics
|
|
|
|
|
|
- **Extensible Augmentations** - Customize and extend functionality
|
|
|
|
|
|
- **REST API** - Web service wrapper for HTTP endpoints
|
|
|
|
|
|
- **Auto-Complete** - IntelliSense for all APIs and types
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
## 📦 Installation
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-05 09:32:15 -07:00
|
|
|
|
### Development: Quick Start
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```bash
|
2025-08-05 09:32:15 -07:00
|
|
|
|
npm install @soulcraft/brainy
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
### ✨ Write-Once, Run-Anywhere Architecture
|
|
|
|
|
|
|
|
|
|
|
|
**Same code, every environment.** Brainy auto-detects and optimizes for your runtime:
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
// This exact code works in Angular, React, Vue, Node.js, Deno, Bun,
|
|
|
|
|
|
// serverless functions, edge workers, and web workers
|
|
|
|
|
|
import { BrainyData } from '@soulcraft/brainy'
|
|
|
|
|
|
|
|
|
|
|
|
const brainy = new BrainyData()
|
|
|
|
|
|
await brainy.init() // Auto-detects environment and chooses optimal storage
|
|
|
|
|
|
|
|
|
|
|
|
// Vector + Graph: Add entities (nouns) with relationships (verbs)
|
2025-08-05 16:09:30 -07:00
|
|
|
|
const companyId = await brainy.addNoun("OpenAI creates powerful AI models", "company", {
|
|
|
|
|
|
founded: "2015", industry: "AI"
|
2025-08-05 15:34:39 -07:00
|
|
|
|
})
|
2025-08-05 16:09:30 -07:00
|
|
|
|
const productId = await brainy.addNoun("GPT-4 is a large language model", "product", {
|
|
|
|
|
|
type: "LLM", parameters: "1.7T"
|
2025-08-05 15:34:39 -07:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Create relationships between entities
|
|
|
|
|
|
await brainy.addVerb(companyId, productId, undefined, { type: "develops" })
|
|
|
|
|
|
|
|
|
|
|
|
// Vector search finds semantically similar content
|
|
|
|
|
|
const similar = await brainy.search("AI language models", 5)
|
|
|
|
|
|
|
|
|
|
|
|
// Graph operations: explore relationships
|
|
|
|
|
|
const relationships = await brainy.getVerbsBySource(companyId)
|
|
|
|
|
|
const allProducts = await brainy.getVerbsByType("develops")
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 🔍 Advanced Graph Operations
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
// Vector search with graph filtering
|
|
|
|
|
|
const results = await brainy.search("AI models", 10, {
|
|
|
|
|
|
searchVerbs: true, // Search relationships directly
|
|
|
|
|
|
verbTypes: ["develops"], // Filter by relationship types
|
|
|
|
|
|
searchConnectedNouns: true, // Find entities connected by relationships
|
|
|
|
|
|
verbDirection: "outgoing" // Direction: outgoing, incoming, or both
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Graph traversal methods
|
|
|
|
|
|
const outgoing = await brainy.getVerbsBySource(entityId) // What this entity relates to
|
|
|
|
|
|
const incoming = await brainy.getVerbsByTarget(entityId) // What relates to this entity
|
|
|
|
|
|
const byType = await brainy.getVerbsByType("develops") // All relationships of this type
|
|
|
|
|
|
|
|
|
|
|
|
// Combined vector + graph search
|
|
|
|
|
|
const connected = await brainy.searchNounsByVerbs("machine learning", 5, {
|
|
|
|
|
|
verbTypes: ["develops", "uses"],
|
|
|
|
|
|
direction: "both"
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Get related entities through specific relationships
|
|
|
|
|
|
const related = await brainy.getRelatedNouns(companyId, { relationType: "develops" })
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**Universal benefits:**
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- ✅ **Auto-detects everything** - Environment, storage, threading, optimization
|
2025-08-05 16:09:30 -07:00
|
|
|
|
- ✅ **Framework-optimized** - Best experience with Angular, React, Vue bundlers
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- ✅ **Runtime-agnostic** - Node.js, Deno, Bun, browsers, serverless, edge
|
|
|
|
|
|
- ✅ **TypeScript-first** - Full types everywhere, IntelliSense support
|
|
|
|
|
|
- ✅ **Tree-shaking ready** - Modern bundlers import only what you need
|
|
|
|
|
|
- ✅ **ES Modules architecture** - Individual modules for better optimization by modern frameworks
|
|
|
|
|
|
|
2025-08-05 09:32:15 -07:00
|
|
|
|
### Production: Add Offline Model Reliability
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```bash
|
2025-08-05 09:32:15 -07:00
|
|
|
|
# For development (online model loading)
|
|
|
|
|
|
npm install @soulcraft/brainy
|
|
|
|
|
|
|
|
|
|
|
|
# For production (offline reliability)
|
|
|
|
|
|
npm install @soulcraft/brainy @soulcraft/brainy-models
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-05 09:32:15 -07:00
|
|
|
|
**Why use offline models in production?**
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
|
|
|
|
|
- **🛡️ 100% Reliability** - No network timeouts or blocked URLs
|
2025-08-05 09:32:15 -07:00
|
|
|
|
- **⚡ Instant Startup** - Models load in ~100ms vs 5-30 seconds
|
|
|
|
|
|
- **🐳 Docker Ready** - Perfect for Cloud Run, Lambda, Kubernetes
|
|
|
|
|
|
- **🔒 Zero Dependencies** - No external network calls required
|
|
|
|
|
|
- **🎯 Zero Configuration** - Automatic detection with graceful fallback
|
2025-08-05 09:38:16 -07:00
|
|
|
|
- **🔐 Enhanced Security** - Complete air-gapping support for sensitive environments
|
|
|
|
|
|
- **🏢 Enterprise Ready** - Works behind corporate firewalls and restricted networks
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
The offline models provide the **same functionality** with maximum reliability. Your existing code works unchanged -
|
|
|
|
|
|
Brainy automatically detects and uses bundled models when available.
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
import { BundledUniversalSentenceEncoder } from '@soulcraft/brainy-models'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
// Use the bundled model for offline operation
|
|
|
|
|
|
const brainy = createAutoBrainy({
|
|
|
|
|
|
embeddingModel: BundledUniversalSentenceEncoder
|
|
|
|
|
|
})
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
## 🐳 Docker & Cloud Deployment
|
|
|
|
|
|
|
|
|
|
|
|
**Deploy Brainy to any cloud provider with embedded models for maximum performance and reliability.**
|
|
|
|
|
|
|
|
|
|
|
|
### Quick Docker Setup
|
|
|
|
|
|
|
|
|
|
|
|
1. **Install models package:**
|
|
|
|
|
|
```bash
|
|
|
|
|
|
npm install @soulcraft/brainy-models
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
2. **Add to your Dockerfile:**
|
|
|
|
|
|
```dockerfile
|
|
|
|
|
|
# Extract models during build (zero configuration!)
|
2025-08-05 20:39:39 -07:00
|
|
|
|
RUN npm run download-models
|
2025-08-05 15:34:39 -07:00
|
|
|
|
|
|
|
|
|
|
# Include models in final image
|
|
|
|
|
|
COPY --from=builder /app/models ./models
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
3. **Deploy anywhere:**
|
|
|
|
|
|
```bash
|
|
|
|
|
|
# Works on all cloud providers
|
|
|
|
|
|
gcloud run deploy --source . # Google Cloud Run
|
|
|
|
|
|
aws ecs create-service ... # AWS ECS/Fargate
|
|
|
|
|
|
az container create ... # Azure Container Instances
|
|
|
|
|
|
wrangler publish # Cloudflare Workers
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Universal Dockerfile Template
|
|
|
|
|
|
|
|
|
|
|
|
```dockerfile
|
2025-08-05 20:39:39 -07:00
|
|
|
|
FROM node:24-slim AS builder
|
2025-08-05 15:34:39 -07:00
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
COPY package*.json ./
|
|
|
|
|
|
RUN npm ci
|
|
|
|
|
|
COPY . .
|
2025-08-05 20:39:39 -07:00
|
|
|
|
RUN npm run download-models # ← Automatic model download
|
2025-08-05 15:34:39 -07:00
|
|
|
|
RUN npm run build
|
|
|
|
|
|
|
2025-08-05 20:39:39 -07:00
|
|
|
|
FROM node:24-slim AS production
|
2025-08-05 15:34:39 -07:00
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
COPY package*.json ./
|
|
|
|
|
|
RUN npm ci --only=production --omit=optional
|
|
|
|
|
|
COPY --from=builder /app/dist ./dist
|
|
|
|
|
|
COPY --from=builder /app/models ./models # ← Models included
|
|
|
|
|
|
CMD ["node", "dist/server.js"]
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
### Benefits
|
|
|
|
|
|
|
|
|
|
|
|
- **⚡ 7x Faster Cold Starts** - No model download delays
|
|
|
|
|
|
- **🌐 Universal Compatibility** - Same Dockerfile works on all clouds
|
|
|
|
|
|
- **🔒 Offline Ready** - No external dependencies at runtime
|
|
|
|
|
|
- **📦 Zero Configuration** - Automatic model detection
|
|
|
|
|
|
- **🛡️ Enhanced Security** - No network calls for model loading
|
|
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
**📖 Complete Guide:** See [docs/docker-deployment.md](./docs/docker-deployment.md) for detailed examples covering Google
|
|
|
|
|
|
Cloud Run, AWS Lambda/ECS, Azure Container Instances, Cloudflare Workers, and more.
|
2025-08-05 15:34:39 -07:00
|
|
|
|
|
|
|
|
|
|
### 📦 Modern ES Modules Architecture
|
|
|
|
|
|
|
|
|
|
|
|
Brainy now uses individual ES modules instead of large bundles, providing better optimization for modern frameworks:
|
|
|
|
|
|
|
|
|
|
|
|
- **Better tree-shaking**: Frameworks import only the specific functions you use
|
2025-08-05 16:09:30 -07:00
|
|
|
|
- **Smaller final apps**: Your bundled application only includes what you actually need
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- **Faster development builds**: No complex bundling during development
|
|
|
|
|
|
- **Better debugging**: Source maps point to individual files, not large bundles
|
|
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
This change reduced the package size significantly while improving compatibility with Angular, React, Vue, and other
|
|
|
|
|
|
modern framework build systems.
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
## 🧬 The Power of Nouns & Verbs
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
Brainy uses a **graph-based data model** that mirrors how humans think - with **Nouns** (entities) connected by **Verbs
|
|
|
|
|
|
** (relationships). This isn't just vectors in a void; it's structured, meaningful data.
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### 📝 Nouns (What Things Are)
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
Nouns are your entities - the "things" in your data. Each noun has:
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- A unique ID
|
|
|
|
|
|
- A vector representation (for similarity search)
|
|
|
|
|
|
- A type (Person, Document, Concept, etc.)
|
|
|
|
|
|
- Custom metadata
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
**Available Noun Types:**
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
| Category | Types | Use For |
|
|
|
|
|
|
|---------------------|-------------------------------------------------------------------|-------------------------------------------------------|
|
|
|
|
|
|
| **Core Entities** | `Person`, `Organization`, `Location`, `Thing`, `Concept`, `Event` | People, companies, places, objects, ideas, happenings |
|
|
|
|
|
|
| **Digital Content** | `Document`, `Media`, `File`, `Message`, `Content` | PDFs, images, videos, emails, posts, generic content |
|
|
|
|
|
|
| **Collections** | `Collection`, `Dataset` | Groups of items, structured data sets |
|
|
|
|
|
|
| **Business** | `Product`, `Service`, `User`, `Task`, `Project` | E-commerce, SaaS, project management |
|
|
|
|
|
|
| **Descriptive** | `Process`, `State`, `Role` | Workflows, conditions, responsibilities |
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### 🔗 Verbs (How Things Connect)
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
Verbs are your relationships - they give meaning to connections. Not just "these vectors are similar" but "this OWNS
|
|
|
|
|
|
that" or "this CAUSES that".
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
**Available Verb Types:**
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
| Category | Types | Examples |
|
|
|
|
|
|
|----------------|----------------------------------------------------------------------|------------------------------------------|
|
|
|
|
|
|
| **Core** | `RelatedTo`, `Contains`, `PartOf`, `LocatedAt`, `References` | Generic relations, containment, location |
|
|
|
|
|
|
| **Temporal** | `Precedes`, `Succeeds`, `Causes`, `DependsOn`, `Requires` | Time sequences, causality, dependencies |
|
|
|
|
|
|
| **Creation** | `Creates`, `Transforms`, `Becomes`, `Modifies`, `Consumes` | Creation, change, consumption |
|
|
|
|
|
|
| **Ownership** | `Owns`, `AttributedTo`, `CreatedBy`, `BelongsTo` | Ownership, authorship, belonging |
|
|
|
|
|
|
| **Social** | `MemberOf`, `WorksWith`, `FriendOf`, `Follows`, `Likes`, `ReportsTo` | Social networks, organizations |
|
|
|
|
|
|
| **Functional** | `Describes`, `Implements`, `Validates`, `Triggers`, `Serves` | Functions, implementations, services |
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### 💡 Why This Matters
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
// Traditional vector DB: Just similarity
|
|
|
|
|
|
const similar = await vectorDB.search(embedding, 10)
|
|
|
|
|
|
// Result: [vector1, vector2, ...] - What do these mean? 🤷
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
// Brainy: Similarity + Meaning + Relationships
|
2025-08-04 14:33:39 -07:00
|
|
|
|
const catId = await brainy.add("Siamese cat", {
|
2025-08-04 08:56:05 -07:00
|
|
|
|
noun: NounType.Thing,
|
2025-08-04 14:33:39 -07:00
|
|
|
|
breed: "Siamese"
|
2025-08-04 08:56:05 -07:00
|
|
|
|
})
|
2025-08-04 14:33:39 -07:00
|
|
|
|
const ownerId = await brainy.add("John Smith", {
|
|
|
|
|
|
noun: NounType.Person
|
2025-08-04 08:56:05 -07:00
|
|
|
|
})
|
2025-08-04 14:33:39 -07:00
|
|
|
|
await brainy.addVerb(ownerId, catId, {
|
2025-08-04 10:14:33 -07:00
|
|
|
|
verb: VerbType.Owns,
|
2025-08-04 14:33:39 -07:00
|
|
|
|
since: "2020-01-01"
|
2025-08-04 08:56:05 -07:00
|
|
|
|
})
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
// Now you can search with context!
|
|
|
|
|
|
const johnsPets = await brainy.getVerbsBySource(ownerId, VerbType.Owns)
|
|
|
|
|
|
const catOwners = await brainy.getVerbsByTarget(catId, VerbType.Owns)
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
## 🌍 Distributed Mode (New!)
|
|
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
Brainy now supports **distributed deployments** with multiple specialized instances sharing the same data. Perfect for
|
|
|
|
|
|
scaling your AI applications across multiple servers.
|
2025-08-04 12:18:58 -07:00
|
|
|
|
|
|
|
|
|
|
### Distributed Setup
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
// Single instance (no change needed!)
|
|
|
|
|
|
const brainy = createAutoBrainy({
|
2025-08-04 14:33:39 -07:00
|
|
|
|
storage: { s3Storage: { bucketName: 'my-bucket' } }
|
2025-08-04 12:18:58 -07:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Distributed mode requires explicit role configuration
|
|
|
|
|
|
// Option 1: Via environment variable
|
|
|
|
|
|
process.env.BRAINY_ROLE = 'writer' // or 'reader' or 'hybrid'
|
|
|
|
|
|
const brainy = createAutoBrainy({
|
2025-08-04 14:33:39 -07:00
|
|
|
|
storage: { s3Storage: { bucketName: 'my-bucket' } },
|
2025-08-04 12:18:58 -07:00
|
|
|
|
distributed: true
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Option 2: Via configuration
|
|
|
|
|
|
const writer = createAutoBrainy({
|
2025-08-04 14:33:39 -07:00
|
|
|
|
storage: { s3Storage: { bucketName: 'my-bucket' } },
|
2025-08-04 12:18:58 -07:00
|
|
|
|
distributed: { role: 'writer' } // Handles data ingestion
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const reader = createAutoBrainy({
|
2025-08-04 14:33:39 -07:00
|
|
|
|
storage: { s3Storage: { bucketName: 'my-bucket' } },
|
2025-08-04 12:18:58 -07:00
|
|
|
|
distributed: { role: 'reader' } // Optimized for queries
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Option 3: Via read/write mode (role auto-inferred)
|
|
|
|
|
|
const writer = createAutoBrainy({
|
2025-08-04 14:33:39 -07:00
|
|
|
|
storage: { s3Storage: { bucketName: 'my-bucket' } },
|
2025-08-04 12:18:58 -07:00
|
|
|
|
writeOnly: true, // Automatically becomes 'writer' role
|
|
|
|
|
|
distributed: true
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const reader = createAutoBrainy({
|
2025-08-04 14:33:39 -07:00
|
|
|
|
storage: { s3Storage: { bucketName: 'my-bucket' } },
|
2025-08-04 12:18:58 -07:00
|
|
|
|
readOnly: true, // Automatically becomes 'reader' role
|
|
|
|
|
|
distributed: true
|
|
|
|
|
|
})
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Key Distributed Features
|
|
|
|
|
|
|
|
|
|
|
|
**🎯 Explicit Role Configuration**
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
- Roles must be explicitly set (no dangerous auto-assignment)
|
|
|
|
|
|
- Can use environment variables, config, or read/write modes
|
|
|
|
|
|
- Clear separation between writers and readers
|
|
|
|
|
|
|
|
|
|
|
|
**#️⃣ Hash-Based Partitioning**
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
- Handles multiple writers with different data types
|
|
|
|
|
|
- Even distribution across partitions
|
|
|
|
|
|
- No semantic conflicts with mixed data
|
|
|
|
|
|
|
|
|
|
|
|
**🏷️ Domain Tagging**
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
- Automatic domain detection (medical, legal, product, etc.)
|
|
|
|
|
|
- Filter searches by domain
|
|
|
|
|
|
- Logical separation without complexity
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
// Data is automatically tagged with domains
|
2025-08-04 14:33:39 -07:00
|
|
|
|
await brainy.add({
|
|
|
|
|
|
symptoms: "fever",
|
|
|
|
|
|
diagnosis: "flu"
|
2025-08-04 12:18:58 -07:00
|
|
|
|
}, metadata) // Auto-tagged as 'medical'
|
|
|
|
|
|
|
|
|
|
|
|
// Search within specific domains
|
|
|
|
|
|
const medicalResults = await brainy.search(query, 10, {
|
|
|
|
|
|
filter: { domain: 'medical' }
|
|
|
|
|
|
})
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**📊 Health Monitoring**
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
- Real-time health metrics
|
|
|
|
|
|
- Automatic dead instance cleanup
|
|
|
|
|
|
- Performance tracking
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
|
// Get health status
|
|
|
|
|
|
const health = brainy.getHealthStatus()
|
|
|
|
|
|
// {
|
|
|
|
|
|
// status: 'healthy',
|
|
|
|
|
|
// role: 'reader',
|
|
|
|
|
|
// vectorCount: 1000000,
|
|
|
|
|
|
// cacheHitRate: 0.95,
|
|
|
|
|
|
// requestsPerSecond: 150
|
|
|
|
|
|
// }
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**⚡ Role-Optimized Performance**
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
- **Readers**: 80% memory for cache, aggressive prefetching
|
|
|
|
|
|
- **Writers**: Optimized write batching, minimal cache
|
|
|
|
|
|
- **Hybrid**: Adaptive based on workload
|
|
|
|
|
|
|
|
|
|
|
|
### Deployment Examples
|
|
|
|
|
|
|
|
|
|
|
|
**Docker Compose**
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
```yaml
|
|
|
|
|
|
services:
|
|
|
|
|
|
writer:
|
|
|
|
|
|
image: myapp
|
|
|
|
|
|
environment:
|
|
|
|
|
|
BRAINY_ROLE: writer # Optional - auto-detects
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
reader:
|
|
|
|
|
|
image: myapp
|
|
|
|
|
|
environment:
|
|
|
|
|
|
BRAINY_ROLE: reader # Optional - auto-detects
|
|
|
|
|
|
scale: 5
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**Kubernetes**
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
```yaml
|
|
|
|
|
|
# Automatically detects role from deployment type
|
|
|
|
|
|
apiVersion: apps/v1
|
|
|
|
|
|
kind: Deployment
|
|
|
|
|
|
metadata:
|
|
|
|
|
|
name: brainy-readers
|
|
|
|
|
|
spec:
|
|
|
|
|
|
replicas: 10 # Multiple readers
|
|
|
|
|
|
template:
|
|
|
|
|
|
spec:
|
|
|
|
|
|
containers:
|
2025-08-04 14:33:39 -07:00
|
|
|
|
- name: app
|
|
|
|
|
|
image: myapp
|
|
|
|
|
|
# Role auto-detected as 'reader' (multiple replicas)
|
2025-08-04 12:18:58 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**Benefits**
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 12:18:58 -07:00
|
|
|
|
- ✅ **50-70% faster searches** with parallel readers
|
|
|
|
|
|
- ✅ **No coordination complexity** - Shared JSON config in S3
|
|
|
|
|
|
- ✅ **Zero downtime scaling** - Add/remove instances anytime
|
|
|
|
|
|
- ✅ **Automatic failover** - Dead instances cleaned up automatically
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
## 🤔 Why Choose Brainy?
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### vs. Traditional Databases
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
❌ **PostgreSQL with pgvector** - Requires complex setup, tuning, and DevOps expertise
|
|
|
|
|
|
✅ **Brainy** - Zero config, auto-optimizes, works everywhere from browser to cloud
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### vs. Vector Databases
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
❌ **Pinecone/Weaviate/Qdrant** - Cloud-only, expensive, vendor lock-in
|
|
|
|
|
|
✅ **Brainy** - Run locally, in browser, or cloud. Your choice, your data
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### vs. Graph Databases
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
❌ **Neo4j** - Great for graphs, no vector support
|
|
|
|
|
|
✅ **Brainy** - Vectors + graphs in one. Best of both worlds
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### vs. DIY Solutions
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
❌ **Building your own** - Months of work, optimization nightmares
|
|
|
|
|
|
✅ **Brainy** - Production-ready in 30 seconds
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
## 🚀 Getting Started in 30 Seconds
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### React
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```jsx
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
import { useEffect, useState } from 'react'
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
function SemanticSearch() {
|
|
|
|
|
|
const [brainy] = useState(() => createAutoBrainy())
|
|
|
|
|
|
const [results, setResults] = useState([])
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const search = async (query) => {
|
|
|
|
|
|
const items = await brainy.searchText(query, 10)
|
|
|
|
|
|
setResults(items)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2025-08-04 14:33:39 -07:00
|
|
|
|
<input onChange={(e) => search(e.target.value)}
|
2025-08-04 10:14:33 -07:00
|
|
|
|
placeholder="Search by meaning..." />
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Angular
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
|
|
|
|
|
```typescript
|
2025-08-04 10:14:33 -07:00
|
|
|
|
import { Component, OnInit } from '@angular/core'
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
|
selector: 'app-search',
|
|
|
|
|
|
template: `
|
|
|
|
|
|
<input (input)="search($event.target.value)"
|
|
|
|
|
|
placeholder="Semantic search...">
|
|
|
|
|
|
<div *ngFor="let result of results">
|
|
|
|
|
|
{{ result.text }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
`
|
2025-08-04 08:56:05 -07:00
|
|
|
|
})
|
2025-08-04 10:14:33 -07:00
|
|
|
|
export class SearchComponent implements OnInit {
|
|
|
|
|
|
brainy = createAutoBrainy()
|
|
|
|
|
|
results = []
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
async search(query: string) {
|
|
|
|
|
|
this.results = await this.brainy.searchText(query, 10)
|
2025-08-01 08:56:41 -07:00
|
|
|
|
}
|
2025-08-04 10:14:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
```
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Vue 3
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```vue
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
<script setup>
|
2025-08-04 14:33:39 -07:00
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
import { ref } from 'vue'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
const brainy = createAutoBrainy()
|
|
|
|
|
|
const results = ref([])
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
const search = async (query) => {
|
|
|
|
|
|
results.value = await brainy.searchText(query, 10)
|
|
|
|
|
|
}
|
2025-08-04 10:14:33 -07:00
|
|
|
|
</script>
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
<template>
|
2025-08-04 14:33:39 -07:00
|
|
|
|
<input @input="search($event.target.value)"
|
2025-08-04 10:14:33 -07:00
|
|
|
|
placeholder="Find similar content...">
|
|
|
|
|
|
<div v-for="result in results" :key="result.id">
|
|
|
|
|
|
{{ result.text }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Svelte
|
|
|
|
|
|
|
|
|
|
|
|
```svelte
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
|
|
|
|
|
|
const brainy = createAutoBrainy()
|
|
|
|
|
|
let results = []
|
|
|
|
|
|
|
|
|
|
|
|
async function search(e) {
|
|
|
|
|
|
results = await brainy.searchText(e.target.value, 10)
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
<input on:input={search} placeholder="AI-powered search...">
|
|
|
|
|
|
{#each results as result}
|
|
|
|
|
|
<div>{result.text}</div>
|
|
|
|
|
|
{/each}
|
2025-06-24 11:41:30 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Next.js (App Router)
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```jsx
|
|
|
|
|
|
// app/search/page.js
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
export default function SearchPage() {
|
|
|
|
|
|
async function search(formData) {
|
|
|
|
|
|
'use server'
|
|
|
|
|
|
const brainy = createAutoBrainy({ bucketName: 'vectors' })
|
|
|
|
|
|
const query = formData.get('query')
|
|
|
|
|
|
return await brainy.searchText(query, 10)
|
|
|
|
|
|
}
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
return (
|
|
|
|
|
|
<form action={search}>
|
|
|
|
|
|
<input name="query" placeholder="Search..." />
|
|
|
|
|
|
<button type="submit">Search</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Node.js / Bun / Deno
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const brainy = createAutoBrainy()
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
// Add some data
|
|
|
|
|
|
await brainy.add("TypeScript is a typed superset of JavaScript", {
|
|
|
|
|
|
category: 'programming'
|
|
|
|
|
|
})
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
// Search for similar content
|
|
|
|
|
|
const results = await brainy.searchText("JavaScript with types", 5)
|
|
|
|
|
|
console.log(results)
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
### 🌍 Framework-First, Runs Everywhere
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
**Brainy is designed for modern frameworks** with automatic environment detection and storage selection:
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
**✨ Supported environments:**
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- ⚛️ **React/Vue/Angular** - Framework-optimized builds with proper bundling
|
2025-08-05 16:09:30 -07:00
|
|
|
|
- 🟢 **Node.js/Deno/Bun** - Full server-side capabilities
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- ⚡ **Serverless/Edge** - Optimized for cold starts and minimal footprint
|
|
|
|
|
|
- 🧵 **Web/Worker threads** - Thread-safe, shared storage
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
**🗄️ Auto-selected storage:**
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- 🌐 **OPFS** - Browser frameworks (persistent, fast)
|
|
|
|
|
|
- 📁 **FileSystem** - Node.js servers (local development)
|
|
|
|
|
|
- ☁️ **S3/R2/GCS** - Production, serverless, distributed deployments
|
|
|
|
|
|
- 💾 **Memory** - Edge workers, testing, temporary data
|
|
|
|
|
|
|
|
|
|
|
|
**🚀 Framework benefits:**
|
2025-08-05 16:09:30 -07:00
|
|
|
|
|
2025-08-05 15:34:39 -07:00
|
|
|
|
- ✅ **Proper bundling** - Handles dynamic imports and dependencies correctly
|
|
|
|
|
|
- ✅ **Type safety** - Full TypeScript integration and IntelliSense
|
|
|
|
|
|
- ✅ **State management** - Reactive updates and component lifecycle
|
|
|
|
|
|
- ✅ **Production ready** - Tree-shaking, optimization, error boundaries
|
|
|
|
|
|
|
|
|
|
|
|
**Note:** We focus on framework support for reliability. Vanilla JS had too many module resolution issues.
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Cloudflare Workers
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
async fetch(request, env) {
|
2025-08-04 14:33:39 -07:00
|
|
|
|
const brainy = createAutoBrainy({
|
|
|
|
|
|
bucketName: env.R2_BUCKET
|
2025-08-04 10:14:33 -07:00
|
|
|
|
})
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const url = new URL(request.url)
|
|
|
|
|
|
const query = url.searchParams.get('q')
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const results = await brainy.searchText(query, 10)
|
|
|
|
|
|
return Response.json(results)
|
2025-08-04 08:56:05 -07:00
|
|
|
|
}
|
2025-08-04 10:14:33 -07:00
|
|
|
|
}
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### AWS Lambda
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
export const handler = async (event) => {
|
2025-08-04 14:33:39 -07:00
|
|
|
|
const brainy = createAutoBrainy({
|
|
|
|
|
|
bucketName: process.env.S3_BUCKET
|
2025-08-04 10:14:33 -07:00
|
|
|
|
})
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const results = await brainy.searchText(event.query, 10)
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
return {
|
|
|
|
|
|
statusCode: 200,
|
|
|
|
|
|
body: JSON.stringify(results)
|
2025-08-04 08:56:05 -07:00
|
|
|
|
}
|
2025-08-04 10:14:33 -07:00
|
|
|
|
}
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Azure Functions
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 14:33:39 -07:00
|
|
|
|
module.exports = async function(context, req) {
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const brainy = createAutoBrainy({
|
|
|
|
|
|
bucketName: process.env.AZURE_STORAGE_CONTAINER
|
|
|
|
|
|
})
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const results = await brainy.searchText(req.query.q, 10)
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
context.res = {
|
|
|
|
|
|
body: results
|
2025-08-04 08:56:05 -07:00
|
|
|
|
}
|
2025-08-04 10:14:33 -07:00
|
|
|
|
}
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
2025-06-24 11:41:30 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Google Cloud Functions
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
export const searchHandler = async (req, res) => {
|
|
|
|
|
|
const brainy = createAutoBrainy({
|
|
|
|
|
|
bucketName: process.env.GCS_BUCKET
|
|
|
|
|
|
})
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const results = await brainy.searchText(req.query.q, 10)
|
|
|
|
|
|
res.json(results)
|
|
|
|
|
|
}
|
2025-06-24 11:41:30 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Google Cloud Run
|
2025-08-01 08:56:41 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```dockerfile
|
|
|
|
|
|
# Dockerfile
|
2025-08-05 20:39:39 -07:00
|
|
|
|
FROM node:24-slim
|
2025-08-04 10:14:33 -07:00
|
|
|
|
USER node
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
COPY package*.json ./
|
|
|
|
|
|
RUN npm install brainy
|
|
|
|
|
|
COPY . .
|
|
|
|
|
|
CMD ["node", "server.js"]
|
|
|
|
|
|
```
|
2025-07-31 17:57:14 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
// server.js
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
import express from 'express'
|
2025-07-31 17:57:14 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const app = express()
|
|
|
|
|
|
const brainy = createAutoBrainy({
|
|
|
|
|
|
bucketName: process.env.GCS_BUCKET
|
2025-08-04 08:56:05 -07:00
|
|
|
|
})
|
2025-07-31 17:57:14 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
app.get('/search', async (req, res) => {
|
|
|
|
|
|
const results = await brainy.searchText(req.query.q, 10)
|
|
|
|
|
|
res.json(results)
|
|
|
|
|
|
})
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const port = process.env.PORT || 8080
|
|
|
|
|
|
app.listen(port, () => console.log(`Brainy on Cloud Run: ${port}`))
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
2025-07-31 17:57:14 -07:00
|
|
|
|
|
2025-07-28 10:04:45 -07:00
|
|
|
|
```bash
|
2025-08-04 10:14:33 -07:00
|
|
|
|
# Deploy to Cloud Run
|
|
|
|
|
|
gcloud run deploy brainy-api \
|
|
|
|
|
|
--source . \
|
|
|
|
|
|
--platform managed \
|
|
|
|
|
|
--region us-central1 \
|
|
|
|
|
|
--allow-unauthenticated
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Vercel Edge Functions
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
2025-07-31 13:40:28 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
export const config = {
|
|
|
|
|
|
runtime: 'edge'
|
|
|
|
|
|
}
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
export default async function handler(request) {
|
|
|
|
|
|
const brainy = createAutoBrainy()
|
|
|
|
|
|
const { searchParams } = new URL(request.url)
|
|
|
|
|
|
const query = searchParams.get('q')
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const results = await brainy.searchText(query, 10)
|
|
|
|
|
|
return Response.json(results)
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Netlify Functions
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
|
|
|
|
|
|
export async function handler(event, context) {
|
|
|
|
|
|
const brainy = createAutoBrainy()
|
|
|
|
|
|
const query = event.queryStringParameters.q
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const results = await brainy.searchText(query, 10)
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
return {
|
|
|
|
|
|
statusCode: 200,
|
|
|
|
|
|
body: JSON.stringify(results)
|
2025-08-04 08:56:05 -07:00
|
|
|
|
}
|
2025-08-04 10:14:33 -07:00
|
|
|
|
}
|
2025-07-31 13:40:28 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Supabase Edge Functions
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
|
|
|
|
|
```typescript
|
2025-08-04 10:14:33 -07:00
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
|
|
|
|
|
|
|
|
|
|
|
|
serve(async (req) => {
|
|
|
|
|
|
const brainy = createAutoBrainy()
|
|
|
|
|
|
const url = new URL(req.url)
|
|
|
|
|
|
const query = url.searchParams.get('q')
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const results = await brainy.searchText(query, 10)
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
return new Response(JSON.stringify(results), {
|
|
|
|
|
|
headers: { 'Content-Type': 'application/json' }
|
|
|
|
|
|
})
|
2025-08-04 08:56:05 -07:00
|
|
|
|
})
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Docker Container
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```dockerfile
|
2025-08-05 20:39:39 -07:00
|
|
|
|
FROM node:24-slim
|
2025-08-04 10:14:33 -07:00
|
|
|
|
USER node
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
COPY package*.json ./
|
|
|
|
|
|
RUN npm install brainy
|
|
|
|
|
|
COPY . .
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
CMD ["node", "server.js"]
|
2025-08-04 08:56:05 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
// server.js
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
|
|
|
|
|
import express from 'express'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const app = express()
|
|
|
|
|
|
const brainy = createAutoBrainy()
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
app.get('/search', async (req, res) => {
|
|
|
|
|
|
const results = await brainy.searchText(req.query.q, 10)
|
|
|
|
|
|
res.json(results)
|
|
|
|
|
|
})
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
app.listen(3000, () => console.log('Brainy running on port 3000'))
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Kubernetes
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```yaml
|
|
|
|
|
|
apiVersion: apps/v1
|
|
|
|
|
|
kind: Deployment
|
|
|
|
|
|
metadata:
|
|
|
|
|
|
name: brainy-api
|
|
|
|
|
|
spec:
|
|
|
|
|
|
replicas: 3
|
|
|
|
|
|
template:
|
|
|
|
|
|
spec:
|
|
|
|
|
|
containers:
|
2025-08-04 14:33:39 -07:00
|
|
|
|
- name: brainy
|
|
|
|
|
|
image: your-registry/brainy-api:latest
|
|
|
|
|
|
env:
|
|
|
|
|
|
- name: S3_BUCKET
|
|
|
|
|
|
value: "your-vector-bucket"
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Railway.app
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```javascript
|
|
|
|
|
|
// server.js
|
|
|
|
|
|
import { createAutoBrainy } from 'brainy'
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
const brainy = createAutoBrainy({
|
|
|
|
|
|
bucketName: process.env.RAILWAY_VOLUME_NAME
|
|
|
|
|
|
})
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
// Railway automatically handles the rest!
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Render.com
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
```yaml
|
|
|
|
|
|
# render.yaml
|
|
|
|
|
|
services:
|
|
|
|
|
|
- type: web
|
|
|
|
|
|
name: brainy-api
|
|
|
|
|
|
env: node
|
|
|
|
|
|
buildCommand: npm install brainy
|
|
|
|
|
|
startCommand: node server.js
|
|
|
|
|
|
envVars:
|
|
|
|
|
|
- key: BRAINY_STORAGE
|
|
|
|
|
|
value: persistent-disk
|
|
|
|
|
|
```
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-05 16:09:30 -07:00
|
|
|
|
## Getting Started
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- [**Quick Start Guide**](docs/getting-started/) - Get up and running in minutes
|
|
|
|
|
|
- [**Installation**](docs/getting-started/installation.md) - Detailed setup instructions
|
|
|
|
|
|
- [**Environment Setup**](docs/getting-started/environment-setup.md) - Platform-specific configuration
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### User Guides
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- [**Search and Metadata**](docs/user-guides/) - Advanced search techniques
|
|
|
|
|
|
- [**JSON Document Search**](docs/guides/json-document-search.md) - Field-based searching
|
|
|
|
|
|
- [**Production Migration**](docs/guides/production-migration-guide.md) - Deployment best practices
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### API Reference
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- [**Core API**](docs/api-reference/) - Complete method reference
|
|
|
|
|
|
- [**Configuration Options**](docs/api-reference/configuration.md) - All configuration parameters
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Optimization & Scaling
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
|
|
|
|
|
- [**Performance Features Guide**](docs/PERFORMANCE_FEATURES.md) - Advanced caching, auto-configuration, and
|
|
|
|
|
|
optimization
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- [**Large-Scale Optimizations**](docs/optimization-guides/) - Handle millions of vectors
|
|
|
|
|
|
- [**Memory Management**](docs/optimization-guides/memory-optimization.md) - Efficient resource usage
|
|
|
|
|
|
- [**S3 Migration Guide**](docs/optimization-guides/s3-migration-guide.md) - Cloud storage setup
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Examples & Patterns
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- [**Code Examples**](docs/examples/) - Real-world usage patterns
|
|
|
|
|
|
- [**Integrations**](docs/examples/integrations.md) - Third-party services
|
|
|
|
|
|
- [**Performance Patterns**](docs/examples/performance.md) - Optimization techniques
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
### Technical Documentation
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- [**Architecture Overview**](docs/technical/) - System design and internals
|
|
|
|
|
|
- [**Testing Guide**](docs/technical/TESTING.md) - Testing strategies
|
|
|
|
|
|
- [**Statistics & Monitoring**](docs/technical/STATISTICS.md) - Performance tracking
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
## 🤝 Contributing
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
We welcome contributions! Please see:
|
2025-08-04 14:33:39 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
- [Contributing Guidelines](CONTRIBUTING.md)
|
|
|
|
|
|
- [Developer Documentation](docs/development/DEVELOPERS.md)
|
|
|
|
|
|
- [Code of Conduct](CODE_OF_CONDUCT.md)
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
## 📄 License
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
[MIT](LICENSE)
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
---
|
2025-08-04 08:56:05 -07:00
|
|
|
|
|
2025-08-04 10:14:33 -07:00
|
|
|
|
<div align="center">
|
|
|
|
|
|
<strong>Ready to build something amazing? Get started with Brainy today!</strong>
|
|
|
|
|
|
</div>
|