2025-06-24 11:41:30 -07:00
< div align = "center" >
< 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 07:50:00 -07:00
**A lightning-fast vector database that runs everywhere - from browsers to servers to edge functions**
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
[Live Demo ](https://soulcraft-research.github.io/brainy/demo/index.html ) | [Quick Start ](#-quick-start ) | [Documentation ](docs/ ) | [Examples ](examples/ )
2025-06-24 11:41:30 -07:00
< / div >
2025-08-04 07:50:00 -07:00
## ✨ Why Brainy?
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
Brainy is a production-ready vector database that **automatically adapts** to your environment. Whether you're building AI applications, recommendation systems, or knowledge graphs, Brainy provides blazing-fast semantic search with zero configuration.
2025-06-24 11:41:30 -07:00
### 🚀 Key Features
2025-08-04 07:50:00 -07:00
- **⚡ Lightning Fast** - Sub-second search across millions of vectors
- **🌍 Runs Everywhere** - Browser, Node.js, Deno, Bun, Edge Workers, Containers
2025-08-03 17:22:32 -07:00
- **🧠 Zero Configuration** - Auto-detects environment and optimizes automatically
2025-08-04 07:50:00 -07:00
- **📈 Self-Optimizing** - Gets faster the more you use it through adaptive learning
- **🔄 Graph Relationships** - Connect data with semantic relationships, not just vectors
- **💾 75% Memory Reduction** - Advanced compression and intelligent caching
- **🎯 Production Ready** - Battle-tested with comprehensive optimizations
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
### 📊 Performance at Scale
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
| Dataset Size | Search Time | Memory Usage |
|-------------|-------------|--------------|
| 10k vectors | ~50ms | Standard |
| 100k vectors | ~200ms | 30% reduction |
| 1M+ vectors | ~500ms | 75% reduction |
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
## 🎯 Quick Start
**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 07:50:00 -07:00
### Installation
2025-07-24 11:13:03 -07:00
**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
```bash
2025-08-04 07:50:00 -07:00
npm install @soulcraft/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-07-24 11:13:03 -07:00
2025-08-04 07:50:00 -07:00
### Zero Configuration Setup
2025-08-03 17:22:32 -07:00
```typescript
import { createAutoBrainy } from '@soulcraft/brainy '
// That's it! Everything is auto-configured
const brainy = createAutoBrainy()
2025-08-04 07:50:00 -07:00
// Add data (automatically converted to vectors)
await brainy.add("Cats are independent pets", {
category: 'animal',
type: 'domestic'
2025-08-03 17:22:32 -07:00
})
2025-08-04 07:50:00 -07:00
// Search semantically
const results = await brainy.searchText("feline companions", 5)
console.log(results) // Returns similar items with scores
2025-08-03 17:22:32 -07:00
```
2025-08-04 07:50:00 -07:00
### Choose Your Scale
2025-08-03 17:22:32 -07:00
```typescript
import { createQuickBrainy } from '@soulcraft/brainy '
2025-08-04 07:50:00 -07:00
// Pick your scale: 'small', 'medium', 'large', 'enterprise'
2025-08-03 17:22:32 -07:00
const brainy = await createQuickBrainy('large', {
2025-08-04 07:50:00 -07:00
bucketName: 'my-vector-storage' // Optional S3 storage
2025-08-03 17:22:32 -07:00
})
```
2025-08-04 07:50:00 -07:00
| Scale | Dataset Size | Best For |
|-------|-------------|----------|
| `small` | ≤10k vectors | Development, prototypes |
| `medium` | ≤100k vectors | Production apps |
| `large` | ≤1M vectors | Large applications |
| `enterprise` | ≤10M vectors | Enterprise systems |
2025-08-03 17:22:32 -07:00
2025-08-04 07:50:00 -07:00
## 🔥 Core Concepts
2025-08-03 17:22:32 -07:00
2025-08-04 07:50:00 -07:00
### Vector + Graph = Knowledge
2025-08-03 17:22:32 -07:00
2025-08-04 07:50:00 -07:00
Brainy combines vector similarity with graph relationships:
2025-06-24 11:41:30 -07:00
```typescript
2025-08-04 07:50:00 -07:00
// Add entities (automatically vectorized)
2025-06-24 11:41:30 -07:00
const catId = await db.add("Cats are independent pets", {
2025-08-01 08:56:41 -07:00
noun: NounType.Thing,
category: 'animal'
2025-06-24 11:41:30 -07:00
})
const dogId = await db.add("Dogs are loyal companions", {
2025-08-01 08:56:41 -07:00
noun: NounType.Thing,
category: 'animal'
2025-06-24 11:41:30 -07:00
})
2025-08-04 07:50:00 -07:00
// Create relationships
2025-06-24 11:41:30 -07:00
await db.addVerb(catId, dogId, {
2025-08-01 08:56:41 -07:00
verb: VerbType.RelatedTo,
2025-08-04 07:50:00 -07:00
relationship: 'both are pets'
2025-06-24 11:41:30 -07:00
})
2025-08-04 07:50:00 -07:00
// Search returns both similar vectors AND related entities
const results = await db.searchText("household pets", 5)
2025-06-24 11:41:30 -07:00
```
2025-08-04 07:50:00 -07:00
### Advanced Search Capabilities
feat(core, tests): add standalone getStatistics function and improve storage configuration
- **Core**: Introduced a new `getStatistics` utility function in `statistics.ts` for fetching database statistics at the root level of the library. Enhanced `BrainyData` methods to ensure metadata includes `id` field and refined statistics calculations, excluding verbs from the noun count.
- **Tests**: Added comprehensive test coverage in `statistics.test.ts` for the new utility function, validating proper error handling, statistics accuracy, and consistent results between instance methods and standalone function.
- **Storage Config**: Enabled dynamic support for AWS S3, Cloudflare R2, and Google Cloud Storage in web service configuration, utilizing environment variables for adapter setup. Addressed a race condition in `FileSystemStorage` initialization by deferring path module imports.
**Purpose**: Enhance database analytics by introducing a reusable `getStatistics` function, improve flexibility in storage configuration, and ensure robust testing for reliability and accuracy.
2025-07-23 16:26:59 -07:00
```typescript
2025-08-04 07:50:00 -07:00
// Search within JSON document fields
const results = await db.search("Acme Corp", 10, {
2025-08-01 08:27:39 -07:00
searchField: "company"
})
2025-08-04 07:50:00 -07:00
// Search by entity type
const people = await db.searchByNounTypes([NounType.Person], 10)
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
// Batch operations for performance
const ids = await db.addBatch([
{ vectorOrData: "First item", metadata: { category: 'A' }},
{ vectorOrData: "Second item", metadata: { category: 'B' }}
], { concurrency: 4, batchSize: 50 })
2025-06-24 11:41:30 -07:00
```
2025-08-04 07:50:00 -07:00
## 🏗️ Architecture
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
Brainy uses cutting-edge technologies to deliver exceptional performance:
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
- **HNSW Algorithm** - Hierarchical Navigable Small World for O(log n) search
- **TensorFlow.js** - Hardware-accelerated embeddings using GPU/WebGL
- **Multi-tier Storage** - Hot (RAM) → Warm (Fast Storage) → Cold (S3/Disk)
- **Semantic Partitioning** - Auto-clusters similar vectors for faster retrieval
- **Adaptive Caching** - Learns your access patterns and optimizes accordingly
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
## 📚 Documentation
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
- **[Getting Started Guide ](docs/getting-started/ )** - Installation and first steps
- **[User Guides ](docs/user-guides/ )** - Advanced usage and best practices
- **[API Reference ](docs/api-reference/ )** - Complete method documentation
- **[Optimization Guide ](docs/optimization-guides/large-scale-optimizations.md )** - Scale to millions of vectors
- **[Examples ](examples/ )** - Real-world usage examples
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
## 🛠️ Advanced Features
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
### Augmentation Pipeline
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
Extend Brainy with custom data processing:
2025-06-24 11:41:30 -07:00
```typescript
2025-08-04 07:50:00 -07:00
import { createSenseAugmentation, pipeline } from '@soulcraft/brainy '
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
// Create custom augmentation
const customProcessor = createSenseAugmentation({
name: 'my-processor',
processRawData: async (data, type) => {
// Your custom logic
return { nouns: [], verbs: [] }
2025-08-01 08:56:41 -07:00
}
2025-06-24 11:41:30 -07:00
})
2025-08-04 07:50:00 -07:00
// Register and use
pipeline.register(customProcessor)
2025-06-24 11:41:30 -07:00
```
### Model Control Protocol (MCP)
2025-08-04 07:50:00 -07:00
Let AI models interact with your Brainy database:
2025-06-24 11:41:30 -07:00
```typescript
2025-08-04 07:50:00 -07:00
import { BrainyMCPAdapter } from '@soulcraft/brainy '
2025-07-22 16:01:48 -07:00
2025-08-04 07:50:00 -07:00
const adapter = new BrainyMCPAdapter(brainy)
// Now AI models can query and update your database
2025-06-24 11:41:30 -07:00
```
2025-08-04 07:50:00 -07:00
## 🎮 Live Demo
2025-08-01 08:56:41 -07:00
2025-08-04 07:50:00 -07:00
**[Try it now! ](https://soulcraft-research.github.io/brainy/demo/index.html )**
2025-07-31 17:57:14 -07:00
2025-08-04 07:50:00 -07:00
See Brainy in action with our interactive demo showcasing vector search, graph relationships, and cross-environment compatibility.
2025-07-31 17:57:14 -07:00
2025-08-04 07:50:00 -07:00
## 🤝 Contributing
2025-07-31 17:57:14 -07:00
2025-08-04 07:50:00 -07:00
We welcome contributions! Please see our [Contributing Guide ](CONTRIBUTING.md ) and [Code of Conduct ](CODE_OF_CONDUCT.md ).
2025-07-31 17:57:14 -07:00
2025-08-04 07:50:00 -07:00
### Development
2025-07-28 10:04:45 -07:00
```bash
2025-08-04 07:50:00 -07:00
# Install dependencies
npm install
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
# Run tests
npm test
2025-07-31 13:40:28 -07:00
2025-08-04 07:50:00 -07:00
# Build project
npm run build
2025-07-31 13:40:28 -07:00
2025-08-04 07:50:00 -07:00
# Run demo locally
npm run demo
2025-07-31 13:40:28 -07:00
```
2025-08-04 07:50:00 -07:00
## 📄 License
2025-07-31 13:40:28 -07:00
2025-08-04 07:50:00 -07:00
[MIT ](LICENSE ) - Use it freely in your projects!
2025-07-31 13:40:28 -07:00
2025-08-04 07:50:00 -07:00
## 🙏 Acknowledgments
2025-07-31 13:40:28 -07:00
2025-08-04 07:50:00 -07:00
Built with ❤️ using:
- [TensorFlow.js ](https://www.tensorflow.org/js ) for embeddings
- [Universal Sentence Encoder ](https://tfhub.dev/google/universal-sentence-encoder/4 ) for text vectorization
2025-07-31 13:40:28 -07:00
2025-08-04 07:50:00 -07:00
---
2025-06-24 11:41:30 -07:00
2025-08-04 07:50:00 -07:00
< div align = "center" >
< b > Ready to build something amazing?< / b > < br >
< a href = "docs/getting-started/quick-start.md" > Get Started →< / a >
< / div >