@soulcraft/brainy 0.40.0 โ 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +605 -194
- package/dist/augmentations/conduitAugmentations.js +1158 -0
- package/dist/augmentations/conduitAugmentations.js.map +1 -0
- package/dist/augmentations/memoryAugmentations.d.ts +2 -0
- package/dist/augmentations/memoryAugmentations.d.ts.map +1 -1
- package/dist/augmentations/memoryAugmentations.js +270 -0
- package/dist/augmentations/memoryAugmentations.js.map +1 -0
- package/dist/augmentations/serverSearchAugmentations.js +531 -0
- package/dist/augmentations/serverSearchAugmentations.js.map +1 -0
- package/dist/browserFramework.d.ts +15 -0
- package/dist/demo.d.ts +106 -0
- package/dist/examples/basicUsage.js +118 -0
- package/dist/examples/basicUsage.js.map +1 -0
- package/dist/hnsw/distributedSearch.js +452 -0
- package/dist/hnsw/distributedSearch.js.map +1 -0
- package/dist/hnsw/hnswIndex.js +602 -0
- package/dist/hnsw/hnswIndex.js.map +1 -0
- package/dist/hnsw/hnswIndexOptimized.js +471 -0
- package/dist/hnsw/hnswIndexOptimized.js.map +1 -0
- package/dist/hnsw/optimizedHNSWIndex.js +313 -0
- package/dist/hnsw/optimizedHNSWIndex.js.map +1 -0
- package/dist/hnsw/partitionedHNSWIndex.js +304 -0
- package/dist/hnsw/partitionedHNSWIndex.js.map +1 -0
- package/dist/hnsw/scaledHNSWSystem.js +559 -0
- package/dist/hnsw/scaledHNSWSystem.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +81 -0
- package/dist/mcp/brainyMCPAdapter.js +142 -0
- package/dist/mcp/brainyMCPAdapter.js.map +1 -0
- package/dist/mcp/brainyMCPService.js +248 -0
- package/dist/mcp/brainyMCPService.js.map +1 -0
- package/dist/mcp/index.js +17 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcpAugmentationToolset.js +180 -0
- package/dist/mcp/mcpAugmentationToolset.js.map +1 -0
- package/dist/storage/adapters/baseStorageAdapter.js +349 -0
- package/dist/storage/adapters/baseStorageAdapter.js.map +1 -0
- package/dist/storage/adapters/batchS3Operations.js +287 -0
- package/dist/storage/adapters/batchS3Operations.js.map +1 -0
- package/dist/storage/adapters/fileSystemStorage.js +846 -0
- package/dist/storage/adapters/fileSystemStorage.js.map +1 -0
- package/dist/storage/adapters/memoryStorage.js +532 -0
- package/dist/storage/adapters/memoryStorage.js.map +1 -0
- package/dist/storage/adapters/opfsStorage.d.ts.map +1 -1
- package/dist/storage/adapters/opfsStorage.js +1118 -0
- package/dist/storage/adapters/opfsStorage.js.map +1 -0
- package/dist/storage/adapters/optimizedS3Search.d.ts +79 -0
- package/dist/storage/adapters/optimizedS3Search.d.ts.map +1 -0
- package/dist/storage/adapters/optimizedS3Search.js +248 -0
- package/dist/storage/adapters/optimizedS3Search.js.map +1 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +21 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts.map +1 -1
- package/dist/storage/adapters/s3CompatibleStorage.js +2026 -0
- package/dist/storage/adapters/s3CompatibleStorage.js.map +1 -0
- package/dist/storage/baseStorage.d.ts +1 -0
- package/dist/storage/baseStorage.d.ts.map +1 -1
- package/dist/storage/baseStorage.js +603 -0
- package/dist/storage/baseStorage.js.map +1 -0
- package/dist/storage/cacheManager.js +1306 -0
- package/dist/storage/cacheManager.js.map +1 -0
- package/dist/storage/enhancedCacheManager.js +520 -0
- package/dist/storage/enhancedCacheManager.js.map +1 -0
- package/dist/storage/readOnlyOptimizations.js +425 -0
- package/dist/storage/readOnlyOptimizations.js.map +1 -0
- package/dist/storage/storageFactory.d.ts +0 -1
- package/dist/storage/storageFactory.d.ts.map +1 -1
- package/dist/storage/storageFactory.js +227 -0
- package/dist/storage/storageFactory.js.map +1 -0
- package/dist/types/augmentations.js +16 -0
- package/dist/types/augmentations.js.map +1 -0
- package/dist/types/brainyDataInterface.js +8 -0
- package/dist/types/brainyDataInterface.js.map +1 -0
- package/dist/types/distributedTypes.js +6 -0
- package/dist/types/distributedTypes.js.map +1 -0
- package/dist/types/fileSystemTypes.js +8 -0
- package/dist/types/fileSystemTypes.js.map +1 -0
- package/dist/types/graphTypes.js +247 -0
- package/dist/types/graphTypes.js.map +1 -0
- package/dist/types/mcpTypes.js +22 -0
- package/dist/types/mcpTypes.js.map +1 -0
- package/dist/types/paginationTypes.js +5 -0
- package/dist/types/paginationTypes.js.map +1 -0
- package/dist/types/pipelineTypes.js +7 -0
- package/dist/types/pipelineTypes.js.map +1 -0
- package/dist/types/tensorflowTypes.js +6 -0
- package/dist/types/tensorflowTypes.js.map +1 -0
- package/dist/unified.js +52 -128048
- package/dist/utils/autoConfiguration.js +341 -0
- package/dist/utils/autoConfiguration.js.map +1 -0
- package/dist/utils/cacheAutoConfig.js +261 -0
- package/dist/utils/cacheAutoConfig.js.map +1 -0
- package/dist/utils/crypto.js +45 -0
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/distance.js +239 -0
- package/dist/utils/distance.js.map +1 -0
- package/dist/utils/embedding.d.ts.map +1 -1
- package/dist/utils/embedding.js +702 -0
- package/dist/utils/embedding.js.map +1 -0
- package/dist/utils/environment.js +75 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/fieldNameTracking.js +90 -0
- package/dist/utils/fieldNameTracking.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/jsonProcessing.js +179 -0
- package/dist/utils/jsonProcessing.js.map +1 -0
- package/dist/utils/logger.d.ts +45 -92
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +129 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/operationUtils.js +126 -0
- package/dist/utils/operationUtils.js.map +1 -0
- package/dist/utils/robustModelLoader.d.ts +14 -0
- package/dist/utils/robustModelLoader.d.ts.map +1 -1
- package/dist/utils/robustModelLoader.js +537 -0
- package/dist/utils/robustModelLoader.js.map +1 -0
- package/dist/utils/searchCache.js +248 -0
- package/dist/utils/searchCache.js.map +1 -0
- package/dist/utils/statistics.js +25 -0
- package/dist/utils/statistics.js.map +1 -0
- package/dist/utils/statisticsCollector.js +224 -0
- package/dist/utils/statisticsCollector.js.map +1 -0
- package/dist/utils/textEncoding.js +309 -0
- package/dist/utils/textEncoding.js.map +1 -0
- package/dist/utils/typeUtils.js +40 -0
- package/dist/utils/typeUtils.js.map +1 -0
- package/dist/utils/version.d.ts +15 -3
- package/dist/utils/version.d.ts.map +1 -1
- package/dist/utils/version.js +24 -0
- package/dist/utils/version.js.map +1 -0
- package/dist/utils/workerUtils.js +458 -0
- package/dist/utils/workerUtils.js.map +1 -0
- package/package.json +23 -15
- package/dist/brainy.js +0 -90220
- package/dist/brainy.min.js +0 -12511
- package/dist/patched-platform-node.d.ts +0 -17
- package/dist/statistics/statisticsManager.d.ts +0 -121
- package/dist/storage/fileSystemStorage.d.ts +0 -73
- package/dist/storage/fileSystemStorage.d.ts.map +0 -1
- package/dist/storage/opfsStorage.d.ts +0 -236
- package/dist/storage/opfsStorage.d.ts.map +0 -1
- package/dist/storage/s3CompatibleStorage.d.ts +0 -157
- package/dist/storage/s3CompatibleStorage.d.ts.map +0 -1
- package/dist/testing/prettyReporter.d.ts +0 -23
- package/dist/testing/prettySummaryReporter.d.ts +0 -22
- package/dist/unified.min.js +0 -16153
- package/dist/utils/environmentDetection.d.ts +0 -47
- package/dist/utils/environmentDetection.d.ts.map +0 -1
- package/dist/utils/tensorflowUtils.d.ts +0 -17
- package/dist/utils/tensorflowUtils.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<div align="center
|
|
1
|
+
<div align="center>
|
|
2
2
|
<img src="./brainy.png" alt="Brainy Logo" width="200"/>
|
|
3
3
|
<br/><br/>
|
|
4
4
|
|
|
@@ -31,8 +31,8 @@ easy-to-use package.
|
|
|
31
31
|
|
|
32
32
|
- **๐ง Zero-to-Smartโข** - No config files, no tuning parameters, no DevOps headaches. Brainy auto-detects your
|
|
33
33
|
environment and optimizes itself
|
|
34
|
-
- **๐ True Write-Once, Run-Anywhere** - Same code runs in
|
|
35
|
-
workers, and
|
|
34
|
+
- **๐ True Write-Once, Run-Anywhere** - Same code runs in Angular, React, Vue, Node.js, Deno, Bun, serverless, edge
|
|
35
|
+
workers, and web workers with automatic environment detection
|
|
36
36
|
- **โก Scary Fast** - Handles millions of vectors with sub-millisecond search. Built-in GPU acceleration when available
|
|
37
37
|
- **๐ฏ Self-Learning** - Like having a database that goes to the gym. Gets faster and smarter the more you use it
|
|
38
38
|
- **๐ฎ AI-First Design** - Built for the age of embeddings, RAG, and semantic search. Your LLMs will thank you
|
|
@@ -49,75 +49,453 @@ easy-to-use package.
|
|
|
49
49
|
- **๐ Performance Monitoring** - Built-in hit rate and memory usage tracking with adaptive optimization
|
|
50
50
|
- **๐ฏ Zero Breaking Changes** - All existing code works unchanged, just faster and smarter
|
|
51
51
|
|
|
52
|
+
## ๐ฆ Get Started in 30 Seconds
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install @soulcraft/brainy
|
|
56
|
+
```
|
|
57
|
+
|
|
52
58
|
```javascript
|
|
53
|
-
|
|
54
|
-
const brainy = new BrainyData() // Auto-detects environment & optimizes
|
|
55
|
-
await brainy.init()
|
|
59
|
+
import { BrainyData } from '@soulcraft/brainy'
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const results2 = await brainy.search('query', 10) // <1ms cached hit!
|
|
61
|
+
const brainy = new BrainyData()
|
|
62
|
+
await brainy.init() // Auto-detects your environment
|
|
60
63
|
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
// Add some data
|
|
65
|
+
await brainy.add("The quick brown fox jumps over the lazy dog")
|
|
66
|
+
await brainy.add("A fast fox leaps over a sleeping dog")
|
|
67
|
+
await brainy.add("Cats are independent and mysterious animals")
|
|
68
|
+
|
|
69
|
+
// Vector search finds similar content
|
|
70
|
+
const results = await brainy.search("speedy animals jumping", 2)
|
|
71
|
+
console.log(results) // Finds the fox sentences!
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**๐ฏ That's it!** You just built semantic search in 4 lines. Works in Angular, React, Vue, Node.js, browsers,
|
|
75
|
+
serverless - everywhere.
|
|
76
|
+
|
|
77
|
+
## ๐ The Magic: Vector + Graph Database
|
|
78
|
+
|
|
79
|
+
**Most databases do one thing.** Brainy does both vector similarity AND graph relationships:
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
// Add entities with relationships
|
|
83
|
+
const companyId = await brainy.addNoun("OpenAI creates powerful AI models", "company")
|
|
84
|
+
const productId = await brainy.addNoun("GPT-4 is a large language model", "product")
|
|
85
|
+
|
|
86
|
+
// Connect them with relationships
|
|
87
|
+
await brainy.addVerb(companyId, productId, undefined, { type: "develops" })
|
|
88
|
+
|
|
89
|
+
// Now you can do BOTH:
|
|
90
|
+
const similar = await brainy.search("AI language models") // Vector similarity
|
|
91
|
+
const products = await brainy.getVerbsByType("develops") // Graph traversal
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Why this matters:** Find content by meaning AND follow relationships. It's like having PostgreSQL and Pinecone working
|
|
95
|
+
together seamlessly.
|
|
96
|
+
|
|
97
|
+
### ๐ Want More Power?
|
|
98
|
+
|
|
99
|
+
- **Advanced graph traversal** - Complex relationship queries and multi-hop searches
|
|
100
|
+
- **Distributed clustering** - Scale across multiple instances with automatic coordination
|
|
101
|
+
- **Real-time syncing** - WebSocket and WebRTC for live data updates
|
|
102
|
+
- **Custom augmentations** - Extend Brainy with your own functionality
|
|
103
|
+
|
|
104
|
+
*[See full API documentation below](#-installation) for advanced features*
|
|
105
|
+
|
|
106
|
+
## ๐จ Build Amazing Things
|
|
107
|
+
|
|
108
|
+
**๐ค AI Chat Applications** - Build ChatGPT-like apps with long-term memory and context awareness
|
|
109
|
+
**๐ Semantic Search Engines** - Search by meaning, not keywords. Find "that thing that's like a cat but bigger" โ
|
|
110
|
+
returns "tiger"
|
|
111
|
+
**๐ฏ Recommendation Engines** - "Users who liked this also liked..." but actually good
|
|
112
|
+
**๐งฌ Knowledge Graphs** - Connect everything to everything. Wikipedia meets Neo4j meets magic
|
|
113
|
+
**๐๏ธ Computer Vision Apps** - Store and search image embeddings. "Find all photos with dogs wearing hats"
|
|
114
|
+
**๐ต Music Discovery** - Find songs that "feel" similar. Spotify's Discover Weekly in your app
|
|
115
|
+
**๐ Smart Documentation** - Docs that answer questions. "How do I deploy to production?" โ relevant guides
|
|
116
|
+
**๐ก๏ธ Fraud Detection** - Find patterns humans can't see. Anomaly detection on steroids
|
|
117
|
+
**๐ Real-Time Collaboration** - Sync vector data across devices. Figma for AI data
|
|
118
|
+
**๐ฅ Medical Diagnosis Tools** - Match symptoms to conditions using embedding similarity
|
|
119
|
+
|
|
120
|
+
## ๐ Write-Once, Run-Anywhere Quick Start
|
|
121
|
+
|
|
122
|
+
Brainy uses the same code across all environments with automatic detection. **Framework-optimized** for the best
|
|
123
|
+
developer experience. Choose your environment:
|
|
124
|
+
|
|
125
|
+
### ๐
ฐ๏ธ Angular (Latest)
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npm install @soulcraft/brainy
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { Component, signal, OnInit } from '@angular/core'
|
|
133
|
+
import { BrainyData } from '@soulcraft/brainy'
|
|
134
|
+
|
|
135
|
+
@Component({
|
|
136
|
+
selector: 'app-search',
|
|
137
|
+
template: `
|
|
138
|
+
<div class="search-container">
|
|
139
|
+
<input [(ngModel)]="query"
|
|
140
|
+
(input)="search($event.target.value)"
|
|
141
|
+
placeholder="Search by meaning (try 'pets' or 'food')..."
|
|
142
|
+
class="search-input">
|
|
143
|
+
|
|
144
|
+
<div class="results">
|
|
145
|
+
@for (result of results(); track result.id) {
|
|
146
|
+
<div class="result-item">
|
|
147
|
+
<strong>{{result.metadata?.category}}</strong>: {{result.metadata?.originalData}}
|
|
148
|
+
<small>Similarity: {{result.score | number:'1.2-2'}}</small>
|
|
149
|
+
</div>
|
|
150
|
+
}
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
`
|
|
65
154
|
})
|
|
155
|
+
export class SearchComponent implements OnInit {
|
|
156
|
+
private brainy: BrainyData | null = null
|
|
157
|
+
results = signal<any[]>([])
|
|
158
|
+
query = ''
|
|
159
|
+
|
|
160
|
+
async ngOnInit() {
|
|
161
|
+
// Auto-detects environment and uses OPFS storage in browsers
|
|
162
|
+
this.brainy = new BrainyData({
|
|
163
|
+
defaultService: 'my-app'
|
|
164
|
+
})
|
|
165
|
+
await this.brainy.init()
|
|
66
166
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
167
|
+
// Add sample data
|
|
168
|
+
await this.brainy.add("Cats are amazing pets", { category: "animals" })
|
|
169
|
+
await this.brainy.add("Dogs love to play fetch", { category: "animals" })
|
|
170
|
+
await this.brainy.add("Pizza is delicious food", { category: "food" })
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async search(query: string) {
|
|
174
|
+
if (!query.trim() || !this.brainy) {
|
|
175
|
+
this.results.set([])
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const searchResults = await this.brainy.search(query, 5)
|
|
180
|
+
this.results.set(searchResults)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
70
183
|
```
|
|
71
184
|
|
|
72
|
-
|
|
185
|
+
### โ๏ธ React
|
|
73
186
|
|
|
74
|
-
|
|
187
|
+
```bash
|
|
188
|
+
npm install @soulcraft/brainy
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```jsx
|
|
192
|
+
import { BrainyData } from '@soulcraft/brainy'
|
|
193
|
+
import { useEffect, useState } from 'react'
|
|
194
|
+
|
|
195
|
+
function SemanticSearch() {
|
|
196
|
+
const [brainy, setBrainy] = useState(null)
|
|
197
|
+
const [results, setResults] = useState([])
|
|
198
|
+
const [query, setQuery] = useState('')
|
|
199
|
+
const [loading, setLoading] = useState(true)
|
|
200
|
+
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
async function initBrainy() {
|
|
203
|
+
// Auto-detects environment and uses OPFS storage in browsers
|
|
204
|
+
const db = new BrainyData({
|
|
205
|
+
defaultService: 'my-app'
|
|
206
|
+
})
|
|
207
|
+
await db.init()
|
|
208
|
+
|
|
209
|
+
// Add sample data
|
|
210
|
+
await db.add("Cats are amazing pets", { category: "animals" })
|
|
211
|
+
await db.add("Dogs love to play fetch", { category: "animals" })
|
|
212
|
+
await db.add("Pizza is delicious food", { category: "food" })
|
|
213
|
+
|
|
214
|
+
setBrainy(db)
|
|
215
|
+
setLoading(false)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
initBrainy()
|
|
219
|
+
}, [])
|
|
220
|
+
|
|
221
|
+
const search = async (searchQuery) => {
|
|
222
|
+
if (!searchQuery.trim() || !brainy) return setResults([])
|
|
223
|
+
|
|
224
|
+
const searchResults = await brainy.search(searchQuery, 5)
|
|
225
|
+
setResults(searchResults)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (loading) return <div>Initializing Brainy...</div>
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
<div className="search-container">
|
|
232
|
+
<input
|
|
233
|
+
value={query}
|
|
234
|
+
onChange={(e) => {
|
|
235
|
+
setQuery(e.target.value)
|
|
236
|
+
search(e.target.value)
|
|
237
|
+
}}
|
|
238
|
+
placeholder="Search by meaning (try 'pets' or 'food')..."
|
|
239
|
+
className="search-input"
|
|
240
|
+
/>
|
|
241
|
+
|
|
242
|
+
<div className="results">
|
|
243
|
+
{results.map((result, i) => (
|
|
244
|
+
<div key={result.id} className="result-item">
|
|
245
|
+
<strong>{result.metadata?.category}</strong>: {result.metadata?.originalData}
|
|
246
|
+
<small>Similarity: {result.score.toFixed(2)}</small>
|
|
247
|
+
</div>
|
|
248
|
+
))}
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export default SemanticSearch
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### ๐ Vue 3
|
|
75
258
|
|
|
76
259
|
```bash
|
|
77
|
-
|
|
78
|
-
|
|
260
|
+
npm install @soulcraft/brainy
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
```vue
|
|
79
264
|
|
|
80
|
-
|
|
265
|
+
<template>
|
|
266
|
+
<div class="search-container">
|
|
267
|
+
<input
|
|
268
|
+
v-model="query"
|
|
269
|
+
@input="search"
|
|
270
|
+
placeholder="Search by meaning (try 'pets' or 'food')..."
|
|
271
|
+
class="search-input"
|
|
272
|
+
/>
|
|
273
|
+
|
|
274
|
+
<div v-if="loading" class="loading">
|
|
275
|
+
Initializing Brainy...
|
|
276
|
+
</div>
|
|
277
|
+
|
|
278
|
+
<div v-else class="results">
|
|
279
|
+
<div
|
|
280
|
+
v-for="result in results"
|
|
281
|
+
:key="result.id"
|
|
282
|
+
class="result-item"
|
|
283
|
+
>
|
|
284
|
+
<strong>{{ result.metadata?.category }}</strong>: {{ result.metadata?.originalData }}
|
|
285
|
+
<small>Similarity: {{ result.score.toFixed(2) }}</small>
|
|
286
|
+
</div>
|
|
287
|
+
</div>
|
|
288
|
+
</div>
|
|
289
|
+
</template>
|
|
290
|
+
|
|
291
|
+
<script setup>
|
|
292
|
+
import { BrainyData } from '@soulcraft/brainy'
|
|
293
|
+
import { ref, onMounted } from 'vue'
|
|
294
|
+
|
|
295
|
+
const brainy = ref(null)
|
|
296
|
+
const results = ref([])
|
|
297
|
+
const query = ref('')
|
|
298
|
+
const loading = ref(true)
|
|
299
|
+
|
|
300
|
+
onMounted(async () => {
|
|
301
|
+
// Auto-detects environment and uses OPFS storage in browsers
|
|
302
|
+
const db = new BrainyData({
|
|
303
|
+
defaultService: 'my-app'
|
|
304
|
+
})
|
|
305
|
+
await db.init()
|
|
306
|
+
|
|
307
|
+
// Add sample data
|
|
308
|
+
await db.add("Cats are amazing pets", { category: "animals" })
|
|
309
|
+
await db.add("Dogs love to play fetch", { category: "animals" })
|
|
310
|
+
await db.add("Pizza is delicious food", { category: "food" })
|
|
311
|
+
|
|
312
|
+
brainy.value = db
|
|
313
|
+
loading.value = false
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
const search = async () => {
|
|
317
|
+
if (!query.value.trim() || !brainy.value) {
|
|
318
|
+
results.value = []
|
|
319
|
+
return
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const searchResults = await brainy.value.search(query.value, 5)
|
|
323
|
+
results.value = searchResults
|
|
324
|
+
}
|
|
325
|
+
</script>
|
|
326
|
+
|
|
327
|
+
<style scoped>
|
|
328
|
+
.search-container {
|
|
329
|
+
max-width: 600px;
|
|
330
|
+
margin: 0 auto;
|
|
331
|
+
padding: 20px;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.search-input {
|
|
335
|
+
width: 100%;
|
|
336
|
+
padding: 12px;
|
|
337
|
+
margin-bottom: 20px;
|
|
338
|
+
border: 2px solid #ddd;
|
|
339
|
+
border-radius: 8px;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.result-item {
|
|
343
|
+
padding: 12px;
|
|
344
|
+
border: 1px solid #eee;
|
|
345
|
+
margin-bottom: 8px;
|
|
346
|
+
border-radius: 6px;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.loading {
|
|
350
|
+
text-align: center;
|
|
351
|
+
color: #666;
|
|
352
|
+
}
|
|
353
|
+
</style>
|
|
81
354
|
```
|
|
82
355
|
|
|
83
|
-
|
|
84
|
-
import { createAutoBrainy, NounType, VerbType } from 'brainy'
|
|
356
|
+
### ๐ข Node.js Server
|
|
85
357
|
|
|
86
|
-
|
|
358
|
+
```bash
|
|
359
|
+
npm install @soulcraft/brainy
|
|
360
|
+
```
|
|
87
361
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
362
|
+
```javascript
|
|
363
|
+
import { BrainyData } from '@soulcraft/brainy'
|
|
364
|
+
|
|
365
|
+
// Auto-detects Node.js โ FileSystem (local) or S3 (production), Worker threads
|
|
366
|
+
const brainy = new BrainyData({
|
|
367
|
+
defaultService: 'my-app',
|
|
368
|
+
// Optional: Production S3 storage
|
|
369
|
+
storage: {
|
|
370
|
+
s3Storage: {
|
|
371
|
+
bucketName: process.env.S3_BUCKET,
|
|
372
|
+
region: process.env.AWS_REGION,
|
|
373
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
374
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
|
|
375
|
+
}
|
|
376
|
+
}
|
|
93
377
|
})
|
|
378
|
+
await brainy.init()
|
|
94
379
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
380
|
+
// Same API everywhere
|
|
381
|
+
await brainy.add("Cats are amazing pets", { category: "animals" })
|
|
382
|
+
const results = await brainy.search("pets", 5)
|
|
383
|
+
console.log('Search results:', results)
|
|
384
|
+
```
|
|
99
385
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
386
|
+
### โก Serverless (Vercel/Netlify)
|
|
387
|
+
|
|
388
|
+
```javascript
|
|
389
|
+
import { BrainyData } from '@soulcraft/brainy'
|
|
390
|
+
|
|
391
|
+
export default async function handler(req, res) {
|
|
392
|
+
// Auto-detects serverless โ S3/R2 storage for persistence, or Memory for temp
|
|
393
|
+
const brainy = new BrainyData({
|
|
394
|
+
defaultService: 'my-app',
|
|
395
|
+
// Optional: Explicit S3-compatible storage
|
|
396
|
+
storage: {
|
|
397
|
+
r2Storage: {
|
|
398
|
+
bucketName: process.env.R2_BUCKET,
|
|
399
|
+
accessKeyId: process.env.R2_ACCESS_KEY_ID,
|
|
400
|
+
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY,
|
|
401
|
+
accountId: process.env.R2_ACCOUNT_ID
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
})
|
|
405
|
+
await brainy.init()
|
|
406
|
+
|
|
407
|
+
// Same API everywhere
|
|
408
|
+
const results = await brainy.search(req.query.q, 5)
|
|
409
|
+
res.json({ results })
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### ๐ฅ Cloudflare Workers
|
|
414
|
+
|
|
415
|
+
```javascript
|
|
416
|
+
import { BrainyData } from '@soulcraft/brainy'
|
|
417
|
+
|
|
418
|
+
export default {
|
|
419
|
+
async fetch(request) {
|
|
420
|
+
// Auto-detects edge โ Minimal footprint, KV storage
|
|
421
|
+
const brainy = new BrainyData({
|
|
422
|
+
defaultService: 'edge-app'
|
|
423
|
+
})
|
|
424
|
+
await brainy.init()
|
|
105
425
|
|
|
106
|
-
//
|
|
107
|
-
const
|
|
426
|
+
// Same API everywhere
|
|
427
|
+
const url = new URL(request.url)
|
|
428
|
+
const results = await brainy.search(url.searchParams.get('q'), 5)
|
|
429
|
+
return Response.json({ results })
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### ๐ฆ Deno
|
|
108
435
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
436
|
+
```typescript
|
|
437
|
+
import { BrainyData } from 'https://esm.sh/@soulcraft/brainy'
|
|
438
|
+
|
|
439
|
+
// Auto-detects Deno โ Native compatibility, FileSystem storage
|
|
440
|
+
const brainy = new BrainyData({
|
|
441
|
+
defaultService: 'deno-app'
|
|
114
442
|
})
|
|
443
|
+
await brainy.init()
|
|
115
444
|
|
|
116
|
-
//
|
|
117
|
-
|
|
445
|
+
// Same API everywhere
|
|
446
|
+
await brainy.add("Deno is awesome", { category: "tech" })
|
|
447
|
+
const results = await brainy.search("technology", 5)
|
|
448
|
+
console.log(results)
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
**That's it! Same code, everywhere. Zero-to-Smartโข**
|
|
452
|
+
|
|
453
|
+
Brainy automatically detects and optimizes for:
|
|
454
|
+
|
|
455
|
+
- ๐ **Browser frameworks** โ OPFS storage, Web Workers, memory optimization
|
|
456
|
+
- ๐ข **Node.js servers** โ FileSystem or S3/R2 storage, Worker threads, cluster support
|
|
457
|
+
- โก **Serverless functions** โ S3/R2 or Memory storage, cold start optimization
|
|
458
|
+
- ๐ฅ **Edge workers** โ Memory or KV storage, minimal footprint
|
|
459
|
+
- ๐งต **Web/Worker threads** โ Shared storage, thread-safe operations
|
|
460
|
+
- ๐ฆ **Deno/Bun runtimes** โ FileSystem or S3-compatible storage, native performance
|
|
461
|
+
|
|
462
|
+
### ๐ณ NEW: Zero-Config Docker Deployment
|
|
463
|
+
|
|
464
|
+
**Deploy to any cloud with embedded models - no runtime downloads needed!**
|
|
465
|
+
|
|
466
|
+
```dockerfile
|
|
467
|
+
# One line extracts models automatically during build
|
|
468
|
+
RUN npm run extract-models
|
|
469
|
+
|
|
470
|
+
# Deploy anywhere: Google Cloud, AWS, Azure, Cloudflare, etc.
|
|
118
471
|
```
|
|
119
472
|
|
|
120
|
-
|
|
473
|
+
- **โก 7x Faster Cold Starts** - Models embedded in container, no downloads
|
|
474
|
+
- **๐ Universal Cloud Support** - Same Dockerfile works everywhere
|
|
475
|
+
- **๐ Offline Ready** - No external dependencies at runtime
|
|
476
|
+
- **๐ฆ Zero Configuration** - Automatic model detection and loading
|
|
477
|
+
|
|
478
|
+
See [Docker Deployment Guide](./docs/docker-deployment.md) for complete examples.
|
|
479
|
+
|
|
480
|
+
```javascript
|
|
481
|
+
// Zero configuration - everything optimized automatically!
|
|
482
|
+
const brainy = new BrainyData() // Auto-detects environment & optimizes
|
|
483
|
+
await brainy.init()
|
|
484
|
+
|
|
485
|
+
// Caching happens automatically - no setup needed!
|
|
486
|
+
const results1 = await brainy.search('query', 10) // ~50ms first time
|
|
487
|
+
const results2 = await brainy.search('query', 10) // <1ms cached hit!
|
|
488
|
+
|
|
489
|
+
// Advanced pagination works instantly
|
|
490
|
+
const page1 = await brainy.searchWithCursor('query', 100)
|
|
491
|
+
const page2 = await brainy.searchWithCursor('query', 100, {
|
|
492
|
+
cursor: page1.cursor // Constant time, no matter how deep!
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
// Monitor auto-optimized performance
|
|
496
|
+
const stats = brainy.getCacheStats()
|
|
497
|
+
console.log(`Auto-tuned cache hit rate: ${(stats.search.hitRate * 100).toFixed(1)}%`)
|
|
498
|
+
```
|
|
121
499
|
|
|
122
500
|
### ๐ Distributed Mode Example (NEW!)
|
|
123
501
|
|
|
@@ -161,19 +539,6 @@ console.log(`Instance ${health.instanceId}: ${health.status}`)
|
|
|
161
539
|
- **Streaming Pipeline** - Process data in real-time as it flows through
|
|
162
540
|
- **Model Control Protocol** - Let AI models access your data
|
|
163
541
|
|
|
164
|
-
### Smart Optimizations
|
|
165
|
-
|
|
166
|
-
- **๐ค Intelligent Auto-Configuration** - Detects environment, usage patterns, and optimizes everything automatically
|
|
167
|
-
- **โก Runtime Performance Adaptation** - Continuously monitors and self-tunes based on real usage
|
|
168
|
-
- **๐ Distributed Mode Detection** - Automatically enables real-time updates for shared storage scenarios
|
|
169
|
-
- **๐ Workload-Aware Optimization** - Adapts cache size and TTL based on read/write patterns
|
|
170
|
-
- **๐ง Adaptive Learning** - Gets smarter with usage, learns from your data access patterns
|
|
171
|
-
- **#๏ธโฃ Intelligent Partitioning** - Hash-based partitioning for perfect load distribution
|
|
172
|
-
- **๐ฏ Role-Based Optimization** - Readers maximize cache, writers optimize throughput
|
|
173
|
-
- **๐ท๏ธ Domain-Aware Indexing** - Automatic categorization improves search relevance
|
|
174
|
-
- **๐๏ธ Multi-Level Caching** - Hot/warm/cold caching with predictive prefetching
|
|
175
|
-
- **๐พ Memory Optimization** - 75% reduction with compression for large datasets
|
|
176
|
-
|
|
177
542
|
### Developer Experience
|
|
178
543
|
|
|
179
544
|
- **TypeScript Support** - Fully typed API with generics
|
|
@@ -183,25 +548,100 @@ console.log(`Instance ${health.instanceId}: ${health.status}`)
|
|
|
183
548
|
|
|
184
549
|
## ๐ฆ Installation
|
|
185
550
|
|
|
186
|
-
###
|
|
551
|
+
### Development: Quick Start
|
|
187
552
|
|
|
188
553
|
```bash
|
|
189
|
-
npm install brainy
|
|
554
|
+
npm install @soulcraft/brainy
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### โจ Write-Once, Run-Anywhere Architecture
|
|
558
|
+
|
|
559
|
+
**Same code, every environment.** Brainy auto-detects and optimizes for your runtime:
|
|
560
|
+
|
|
561
|
+
```javascript
|
|
562
|
+
// This exact code works in Angular, React, Vue, Node.js, Deno, Bun,
|
|
563
|
+
// serverless functions, edge workers, and web workers
|
|
564
|
+
import { BrainyData } from '@soulcraft/brainy'
|
|
565
|
+
|
|
566
|
+
const brainy = new BrainyData()
|
|
567
|
+
await brainy.init() // Auto-detects environment and chooses optimal storage
|
|
568
|
+
|
|
569
|
+
// Vector + Graph: Add entities (nouns) with relationships (verbs)
|
|
570
|
+
const companyId = await brainy.addNoun("OpenAI creates powerful AI models", "company", {
|
|
571
|
+
founded: "2015", industry: "AI"
|
|
572
|
+
})
|
|
573
|
+
const productId = await brainy.addNoun("GPT-4 is a large language model", "product", {
|
|
574
|
+
type: "LLM", parameters: "1.7T"
|
|
575
|
+
})
|
|
576
|
+
|
|
577
|
+
// Create relationships between entities
|
|
578
|
+
await brainy.addVerb(companyId, productId, undefined, { type: "develops" })
|
|
579
|
+
|
|
580
|
+
// Vector search finds semantically similar content
|
|
581
|
+
const similar = await brainy.search("AI language models", 5)
|
|
582
|
+
|
|
583
|
+
// Graph operations: explore relationships
|
|
584
|
+
const relationships = await brainy.getVerbsBySource(companyId)
|
|
585
|
+
const allProducts = await brainy.getVerbsByType("develops")
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### ๐ Advanced Graph Operations
|
|
589
|
+
|
|
590
|
+
```javascript
|
|
591
|
+
// Vector search with graph filtering
|
|
592
|
+
const results = await brainy.search("AI models", 10, {
|
|
593
|
+
searchVerbs: true, // Search relationships directly
|
|
594
|
+
verbTypes: ["develops"], // Filter by relationship types
|
|
595
|
+
searchConnectedNouns: true, // Find entities connected by relationships
|
|
596
|
+
verbDirection: "outgoing" // Direction: outgoing, incoming, or both
|
|
597
|
+
})
|
|
598
|
+
|
|
599
|
+
// Graph traversal methods
|
|
600
|
+
const outgoing = await brainy.getVerbsBySource(entityId) // What this entity relates to
|
|
601
|
+
const incoming = await brainy.getVerbsByTarget(entityId) // What relates to this entity
|
|
602
|
+
const byType = await brainy.getVerbsByType("develops") // All relationships of this type
|
|
603
|
+
|
|
604
|
+
// Combined vector + graph search
|
|
605
|
+
const connected = await brainy.searchNounsByVerbs("machine learning", 5, {
|
|
606
|
+
verbTypes: ["develops", "uses"],
|
|
607
|
+
direction: "both"
|
|
608
|
+
})
|
|
609
|
+
|
|
610
|
+
// Get related entities through specific relationships
|
|
611
|
+
const related = await brainy.getRelatedNouns(companyId, { relationType: "develops" })
|
|
190
612
|
```
|
|
191
613
|
|
|
192
|
-
|
|
614
|
+
**Universal benefits:**
|
|
615
|
+
|
|
616
|
+
- โ
**Auto-detects everything** - Environment, storage, threading, optimization
|
|
617
|
+
- โ
**Framework-optimized** - Best experience with Angular, React, Vue bundlers
|
|
618
|
+
- โ
**Runtime-agnostic** - Node.js, Deno, Bun, browsers, serverless, edge
|
|
619
|
+
- โ
**TypeScript-first** - Full types everywhere, IntelliSense support
|
|
620
|
+
- โ
**Tree-shaking ready** - Modern bundlers import only what you need
|
|
621
|
+
- โ
**ES Modules architecture** - Individual modules for better optimization by modern frameworks
|
|
622
|
+
|
|
623
|
+
### Production: Add Offline Model Reliability
|
|
193
624
|
|
|
194
625
|
```bash
|
|
195
|
-
|
|
626
|
+
# For development (online model loading)
|
|
627
|
+
npm install @soulcraft/brainy
|
|
628
|
+
|
|
629
|
+
# For production (offline reliability)
|
|
630
|
+
npm install @soulcraft/brainy @soulcraft/brainy-models
|
|
196
631
|
```
|
|
197
632
|
|
|
198
|
-
|
|
199
|
-
|
|
633
|
+
**Why use offline models in production?**
|
|
634
|
+
|
|
635
|
+
- **๐ก๏ธ 100% Reliability** - No network timeouts or blocked URLs
|
|
636
|
+
- **โก Instant Startup** - Models load in ~100ms vs 5-30 seconds
|
|
637
|
+
- **๐ณ Docker Ready** - Perfect for Cloud Run, Lambda, Kubernetes
|
|
638
|
+
- **๐ Zero Dependencies** - No external network calls required
|
|
639
|
+
- **๐ฏ Zero Configuration** - Automatic detection with graceful fallback
|
|
640
|
+
- **๐ Enhanced Security** - Complete air-gapping support for sensitive environments
|
|
641
|
+
- **๐ข Enterprise Ready** - Works behind corporate firewalls and restricted networks
|
|
200
642
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
- **Privacy-focused apps** - Keep everything local
|
|
204
|
-
- **High-reliability systems** - No external dependencies
|
|
643
|
+
The offline models provide the **same functionality** with maximum reliability. Your existing code works unchanged -
|
|
644
|
+
Brainy automatically detects and uses bundled models when available.
|
|
205
645
|
|
|
206
646
|
```javascript
|
|
207
647
|
import { createAutoBrainy } from 'brainy'
|
|
@@ -213,19 +653,77 @@ const brainy = createAutoBrainy({
|
|
|
213
653
|
})
|
|
214
654
|
```
|
|
215
655
|
|
|
216
|
-
##
|
|
656
|
+
## ๐ณ Docker & Cloud Deployment
|
|
217
657
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
658
|
+
**Deploy Brainy to any cloud provider with embedded models for maximum performance and reliability.**
|
|
659
|
+
|
|
660
|
+
### Quick Docker Setup
|
|
661
|
+
|
|
662
|
+
1. **Install models package:**
|
|
663
|
+
```bash
|
|
664
|
+
npm install @soulcraft/brainy-models
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
2. **Add to your Dockerfile:**
|
|
668
|
+
```dockerfile
|
|
669
|
+
# Extract models during build (zero configuration!)
|
|
670
|
+
RUN npm run extract-models
|
|
671
|
+
|
|
672
|
+
# Include models in final image
|
|
673
|
+
COPY --from=builder /app/models ./models
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
3. **Deploy anywhere:**
|
|
677
|
+
```bash
|
|
678
|
+
# Works on all cloud providers
|
|
679
|
+
gcloud run deploy --source . # Google Cloud Run
|
|
680
|
+
aws ecs create-service ... # AWS ECS/Fargate
|
|
681
|
+
az container create ... # Azure Container Instances
|
|
682
|
+
wrangler publish # Cloudflare Workers
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
### Universal Dockerfile Template
|
|
686
|
+
|
|
687
|
+
```dockerfile
|
|
688
|
+
FROM node:24-alpine AS builder
|
|
689
|
+
WORKDIR /app
|
|
690
|
+
COPY package*.json ./
|
|
691
|
+
RUN npm ci
|
|
692
|
+
COPY . .
|
|
693
|
+
RUN npm run extract-models # โ Automatic model extraction
|
|
694
|
+
RUN npm run build
|
|
695
|
+
|
|
696
|
+
FROM node:24-alpine AS production
|
|
697
|
+
WORKDIR /app
|
|
698
|
+
COPY package*.json ./
|
|
699
|
+
RUN npm ci --only=production --omit=optional
|
|
700
|
+
COPY --from=builder /app/dist ./dist
|
|
701
|
+
COPY --from=builder /app/models ./models # โ Models included
|
|
702
|
+
CMD ["node", "dist/server.js"]
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
### Benefits
|
|
706
|
+
|
|
707
|
+
- **โก 7x Faster Cold Starts** - No model download delays
|
|
708
|
+
- **๐ Universal Compatibility** - Same Dockerfile works on all clouds
|
|
709
|
+
- **๐ Offline Ready** - No external dependencies at runtime
|
|
710
|
+
- **๐ฆ Zero Configuration** - Automatic model detection
|
|
711
|
+
- **๐ก๏ธ Enhanced Security** - No network calls for model loading
|
|
712
|
+
|
|
713
|
+
**๐ Complete Guide:** See [docs/docker-deployment.md](./docs/docker-deployment.md) for detailed examples covering Google
|
|
714
|
+
Cloud Run, AWS Lambda/ECS, Azure Container Instances, Cloudflare Workers, and more.
|
|
715
|
+
|
|
716
|
+
### ๐ฆ Modern ES Modules Architecture
|
|
717
|
+
|
|
718
|
+
Brainy now uses individual ES modules instead of large bundles, providing better optimization for modern frameworks:
|
|
719
|
+
|
|
720
|
+
- **Better tree-shaking**: Frameworks import only the specific functions you use
|
|
721
|
+
- **Smaller final apps**: Your bundled application only includes what you actually need
|
|
722
|
+
- **Faster development builds**: No complex bundling during development
|
|
723
|
+
- **Better debugging**: Source maps point to individual files, not large bundles
|
|
724
|
+
|
|
725
|
+
This change reduced the package size significantly while improving compatibility with Angular, React, Vue, and other
|
|
726
|
+
modern framework build systems.
|
|
229
727
|
|
|
230
728
|
## ๐งฌ The Power of Nouns & Verbs
|
|
231
729
|
|
|
@@ -595,30 +1093,32 @@ const results = await brainy.searchText("JavaScript with types", 5)
|
|
|
595
1093
|
console.log(results)
|
|
596
1094
|
```
|
|
597
1095
|
|
|
598
|
-
###
|
|
1096
|
+
### ๐ Framework-First, Runs Everywhere
|
|
599
1097
|
|
|
600
|
-
|
|
601
|
-
<!DOCTYPE html>
|
|
602
|
-
<html>
|
|
603
|
-
<head>
|
|
604
|
-
<script type="module">
|
|
605
|
-
import { createAutoBrainy } from 'https://unpkg.com/brainy/dist/unified.min.js'
|
|
1098
|
+
**Brainy is designed for modern frameworks** with automatic environment detection and storage selection:
|
|
606
1099
|
|
|
607
|
-
|
|
1100
|
+
**โจ Supported environments:**
|
|
608
1101
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
1102
|
+
- โ๏ธ **React/Vue/Angular** - Framework-optimized builds with proper bundling
|
|
1103
|
+
- ๐ข **Node.js/Deno/Bun** - Full server-side capabilities
|
|
1104
|
+
- โก **Serverless/Edge** - Optimized for cold starts and minimal footprint
|
|
1105
|
+
- ๐งต **Web/Worker threads** - Thread-safe, shared storage
|
|
1106
|
+
|
|
1107
|
+
**๐๏ธ Auto-selected storage:**
|
|
1108
|
+
|
|
1109
|
+
- ๐ **OPFS** - Browser frameworks (persistent, fast)
|
|
1110
|
+
- ๐ **FileSystem** - Node.js servers (local development)
|
|
1111
|
+
- โ๏ธ **S3/R2/GCS** - Production, serverless, distributed deployments
|
|
1112
|
+
- ๐พ **Memory** - Edge workers, testing, temporary data
|
|
1113
|
+
|
|
1114
|
+
**๐ Framework benefits:**
|
|
1115
|
+
|
|
1116
|
+
- โ
**Proper bundling** - Handles dynamic imports and dependencies correctly
|
|
1117
|
+
- โ
**Type safety** - Full TypeScript integration and IntelliSense
|
|
1118
|
+
- โ
**State management** - Reactive updates and component lifecycle
|
|
1119
|
+
- โ
**Production ready** - Tree-shaking, optimization, error boundaries
|
|
1120
|
+
|
|
1121
|
+
**Note:** We focus on framework support for reliability. Vanilla JS had too many module resolution issues.
|
|
622
1122
|
|
|
623
1123
|
### Cloudflare Workers
|
|
624
1124
|
|
|
@@ -865,92 +1365,7 @@ services:
|
|
|
865
1365
|
value: persistent-disk
|
|
866
1366
|
```
|
|
867
1367
|
|
|
868
|
-
##
|
|
869
|
-
|
|
870
|
-
### Basic Usage
|
|
871
|
-
|
|
872
|
-
```javascript
|
|
873
|
-
import { BrainyData, NounType, VerbType } from 'brainy'
|
|
874
|
-
|
|
875
|
-
// Initialize
|
|
876
|
-
const db = new BrainyData()
|
|
877
|
-
await db.init()
|
|
878
|
-
|
|
879
|
-
// Add data (automatically vectorized)
|
|
880
|
-
const catId = await db.add("Cats are independent pets", {
|
|
881
|
-
noun: NounType.Thing,
|
|
882
|
-
category: 'animal'
|
|
883
|
-
})
|
|
884
|
-
|
|
885
|
-
// Search for similar items
|
|
886
|
-
const results = await db.searchText("feline pets", 5)
|
|
887
|
-
|
|
888
|
-
// Add relationships
|
|
889
|
-
await db.addVerb(catId, dogId, {
|
|
890
|
-
verb: VerbType.RelatedTo,
|
|
891
|
-
description: 'Both are pets'
|
|
892
|
-
})
|
|
893
|
-
```
|
|
894
|
-
|
|
895
|
-
### AutoBrainy (Recommended)
|
|
896
|
-
|
|
897
|
-
```javascript
|
|
898
|
-
import { createAutoBrainy } from 'brainy'
|
|
899
|
-
|
|
900
|
-
// Everything auto-configured!
|
|
901
|
-
const brainy = createAutoBrainy()
|
|
902
|
-
|
|
903
|
-
// Just start using it
|
|
904
|
-
await brainy.addVector({ id: '1', vector: [0.1, 0.2, 0.3], text: 'Hello' })
|
|
905
|
-
const results = await brainy.search([0.1, 0.2, 0.3], 10)
|
|
906
|
-
```
|
|
907
|
-
|
|
908
|
-
### Scenario-Based Setup
|
|
909
|
-
|
|
910
|
-
```javascript
|
|
911
|
-
import { createQuickBrainy } from 'brainy'
|
|
912
|
-
|
|
913
|
-
// Choose your scale: 'small', 'medium', 'large', 'enterprise'
|
|
914
|
-
const brainy = await createQuickBrainy('large', {
|
|
915
|
-
bucketName: 'my-vector-db'
|
|
916
|
-
})
|
|
917
|
-
```
|
|
918
|
-
|
|
919
|
-
### With Offline Models
|
|
920
|
-
|
|
921
|
-
```javascript
|
|
922
|
-
import { createAutoBrainy } from 'brainy'
|
|
923
|
-
import { BundledUniversalSentenceEncoder } from '@soulcraft/brainy-models'
|
|
924
|
-
|
|
925
|
-
// Use bundled model for offline operation
|
|
926
|
-
const brainy = createAutoBrainy({
|
|
927
|
-
embeddingModel: BundledUniversalSentenceEncoder,
|
|
928
|
-
// Model loads from local files, no network needed!
|
|
929
|
-
})
|
|
930
|
-
|
|
931
|
-
// Works exactly the same, but 100% offline
|
|
932
|
-
await brainy.add("This works without internet!", {
|
|
933
|
-
noun: NounType.Content
|
|
934
|
-
})
|
|
935
|
-
```
|
|
936
|
-
|
|
937
|
-
## ๐ Live Demo
|
|
938
|
-
|
|
939
|
-
**[Try the interactive demo](https://soulcraft-research.github.io/brainy/demo/index.html)** - See Brainy in action with
|
|
940
|
-
animations and examples.
|
|
941
|
-
|
|
942
|
-
## ๐ง Environment Support
|
|
943
|
-
|
|
944
|
-
| Environment | Storage | Threading | Auto-Configured |
|
|
945
|
-
|----------------|---------------|----------------|-----------------|
|
|
946
|
-
| Browser | OPFS | Web Workers | โ
|
|
|
947
|
-
| Node.js | FileSystem/S3 | Worker Threads | โ
|
|
|
948
|
-
| Serverless | Memory/S3 | Limited | โ
|
|
|
949
|
-
| Edge Functions | Memory/KV | Limited | โ
|
|
|
950
|
-
|
|
951
|
-
## ๐ Documentation
|
|
952
|
-
|
|
953
|
-
### Getting Started
|
|
1368
|
+
## Getting Started
|
|
954
1369
|
|
|
955
1370
|
- [**Quick Start Guide**](docs/getting-started/) - Get up and running in minutes
|
|
956
1371
|
- [**Installation**](docs/getting-started/installation.md) - Detailed setup instructions
|
|
@@ -999,10 +1414,6 @@ We welcome contributions! Please see:
|
|
|
999
1414
|
|
|
1000
1415
|
[MIT](LICENSE)
|
|
1001
1416
|
|
|
1002
|
-
## ๐ Related Projects
|
|
1003
|
-
|
|
1004
|
-
- [**Cartographer**](https://github.com/sodal-project/cartographer) - Standardized interfaces for Brainy
|
|
1005
|
-
|
|
1006
1417
|
---
|
|
1007
1418
|
|
|
1008
1419
|
<div align="center">
|