2026-01-27 15:38:21 -08:00
# 🔌 Brainy Augmentations Complete Reference
2025-08-26 12:32:21 -07:00
2025-10-17 12:29:27 -07:00
> **All augmentations that power Brainy's extensibility - with locations, usage, and examples**
>
2026-01-27 15:38:21 -08:00
> **⚠️ Update**: Updated for metadata structure changes and billion-scale optimizations
2025-08-26 12:32:21 -07:00
## Quick Start
```typescript
2025-09-30 17:09:15 -07:00
import { Brainy } from '@soulcraft/brainy '
2025-08-26 12:32:21 -07:00
2025-09-30 17:09:15 -07:00
const brain = new Brainy({
docs(8.0): Phase F — deep clean across 21 docs
Aligned every public doc to the 8.0 contract: filesystem + memory adapters
only, vector index provider terminology (config.vector with recall +
quantization + persistMode knobs), no cloud storage adapters, no closed-
source product names.
Tier 1 — heavier rewrites:
- docs/architecture/storage-architecture.md
- docs/architecture/data-storage-architecture.md
- docs/architecture/distributed-storage.md DELETED — content was 100%
cloud-coordination examples with no 8.0 substance.
- docs/guides/distributed-system.md DELETED — same reason; no inbound refs.
- docs/SCALING.md rewritten for single-node guidance.
- docs/PLUGINS.md, docs/augmentations/{COMPLETE-REFERENCE,README}.md:
HnswProvider→VectorIndexProvider, hnsw→vector key.
- docs/PERFORMANCE.md, docs/BATCHING.md cloud-detection + sharding
sections replaced with single-node vector tuning + filesystem framing.
Tier 2 — surgical renames + cloud-section deletions:
- architecture/{index,initialization-and-rebuild,overview}.md
- transactions.md, DEVELOPER_LEARNING_PATH.md
- vfs/{VFS_API_GUIDE,COMMON_PATTERNS}.md
- api/README.md, guides/{inspection,import-flow}.md
Tier 3 — light edits:
- docs/README.md, architecture/augmentation-system-audit.md
MIGRATION-V3-TO-V4.md untouched (internal migration doc, no stale terms).
2026-06-09 16:13:35 -07:00
// Augmentations auto-configure based on environment
storage: { type: 'auto', rootDirectory: './brainy-data' }, // Storage augmentation
cache: true, // Cache augmentation
index: true // Index augmentation
2025-08-26 12:32:21 -07:00
})
2026-01-27 15:38:21 -08:00
await brain.init() // Augmentations initialize automatically
2025-08-26 12:32:21 -07:00
```
2026-01-27 15:38:21 -08:00
## Augmentation Architecture
2025-10-17 12:29:27 -07:00
### Key Improvements for Billion-Scale Performance
1. **Metadata/Vector Separation** : Augmentations now work with separated metadata and vectors
2026-01-27 15:38:21 -08:00
- Metadata stored separately from vector data
- 99.2% memory reduction for type tracking
- Two-file storage pattern for optimal I/O
2025-10-17 12:29:27 -07:00
2. **Type System Enforcement** : All metadata requires type fields
2026-01-27 15:38:21 -08:00
- `NounMetadata` requires `noun: NounType`
- `VerbMetadata` requires `verb: VerbType`
- Type inference system available as public API
2025-10-17 12:29:27 -07:00
3. **Storage Adapter Pattern** : Internal vs public method distinction
2026-01-27 15:38:21 -08:00
- `_methods` : Return pure structures (HNSWNoun, HNSWVerb)
- Public methods: Return WithMetadata types
- MetadataEnforcer Proxy ensures proper access
2025-10-17 12:29:27 -07:00
### What This Means for Augmentation Users
2026-01-27 15:38:21 -08:00
**✅ If you use built-in augmentations**: No changes needed! They're all updated.
2025-10-17 12:29:27 -07:00
**⚠️ If you created custom storage augmentations**: Update your storage adapter to:
- Wrap metadata with required `noun` /`verb` fields
- Follow the internal/public method pattern
- Use two-file storage approach
**⚠️ If you access relationship data**: Change `verb.type` to `verb.verb`
2025-08-26 12:32:21 -07:00
## Core Concepts
### What are Augmentations?
Augmentations are modular extensions that add functionality to Brainy without cluttering the core API. They follow a unified interface and can be:
- **Auto-enabled**: Based on configuration (cache, index, storage)
- **Manually registered**: For custom functionality
- **Chained**: Multiple augmentations work together seamlessly
2025-10-17 12:29:27 -07:00
- **Billion-scale ready**: Optimized for datasets with billions of nouns and verbs
2025-08-26 12:32:21 -07:00
### Augmentation Lifecycle
1. **Registration** : Augmentations register before init()
2. **Initialization** : Two-phase init (storage first, then others)
3. **Execution** : Hook into operations (before/after/both)
4. **Shutdown** : Clean teardown on brain.shutdown()
---
docs(8.0): Phase F — deep clean across 21 docs
Aligned every public doc to the 8.0 contract: filesystem + memory adapters
only, vector index provider terminology (config.vector with recall +
quantization + persistMode knobs), no cloud storage adapters, no closed-
source product names.
Tier 1 — heavier rewrites:
- docs/architecture/storage-architecture.md
- docs/architecture/data-storage-architecture.md
- docs/architecture/distributed-storage.md DELETED — content was 100%
cloud-coordination examples with no 8.0 substance.
- docs/guides/distributed-system.md DELETED — same reason; no inbound refs.
- docs/SCALING.md rewritten for single-node guidance.
- docs/PLUGINS.md, docs/augmentations/{COMPLETE-REFERENCE,README}.md:
HnswProvider→VectorIndexProvider, hnsw→vector key.
- docs/PERFORMANCE.md, docs/BATCHING.md cloud-detection + sharding
sections replaced with single-node vector tuning + filesystem framing.
Tier 2 — surgical renames + cloud-section deletions:
- architecture/{index,initialization-and-rebuild,overview}.md
- transactions.md, DEVELOPER_LEARNING_PATH.md
- vfs/{VFS_API_GUIDE,COMMON_PATTERNS}.md
- api/README.md, guides/{inspection,import-flow}.md
Tier 3 — light edits:
- docs/README.md, architecture/augmentation-system-audit.md
MIGRATION-V3-TO-V4.md untouched (internal migration doc, no stale terms).
2026-06-09 16:13:35 -07:00
## Storage Augmentations
2025-08-26 12:32:21 -07:00
### MemoryStorageAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/storageAugmentations.ts`
docs(8.0): Phase F — deep clean across 21 docs
Aligned every public doc to the 8.0 contract: filesystem + memory adapters
only, vector index provider terminology (config.vector with recall +
quantization + persistMode knobs), no cloud storage adapters, no closed-
source product names.
Tier 1 — heavier rewrites:
- docs/architecture/storage-architecture.md
- docs/architecture/data-storage-architecture.md
- docs/architecture/distributed-storage.md DELETED — content was 100%
cloud-coordination examples with no 8.0 substance.
- docs/guides/distributed-system.md DELETED — same reason; no inbound refs.
- docs/SCALING.md rewritten for single-node guidance.
- docs/PLUGINS.md, docs/augmentations/{COMPLETE-REFERENCE,README}.md:
HnswProvider→VectorIndexProvider, hnsw→vector key.
- docs/PERFORMANCE.md, docs/BATCHING.md cloud-detection + sharding
sections replaced with single-node vector tuning + filesystem framing.
Tier 2 — surgical renames + cloud-section deletions:
- architecture/{index,initialization-and-rebuild,overview}.md
- transactions.md, DEVELOPER_LEARNING_PATH.md
- vfs/{VFS_API_GUIDE,COMMON_PATTERNS}.md
- api/README.md, guides/{inspection,import-flow}.md
Tier 3 — light edits:
- docs/README.md, architecture/augmentation-system-audit.md
MIGRATION-V3-TO-V4.md untouched (internal migration doc, no stale terms).
2026-06-09 16:13:35 -07:00
**Auto-enabled**: When `storage: { type: 'memory' }` or in test environments
2025-08-26 12:32:21 -07:00
**Purpose**: In-memory storage for testing and temporary data
```typescript
docs(8.0): Phase F — deep clean across 21 docs
Aligned every public doc to the 8.0 contract: filesystem + memory adapters
only, vector index provider terminology (config.vector with recall +
quantization + persistMode knobs), no cloud storage adapters, no closed-
source product names.
Tier 1 — heavier rewrites:
- docs/architecture/storage-architecture.md
- docs/architecture/data-storage-architecture.md
- docs/architecture/distributed-storage.md DELETED — content was 100%
cloud-coordination examples with no 8.0 substance.
- docs/guides/distributed-system.md DELETED — same reason; no inbound refs.
- docs/SCALING.md rewritten for single-node guidance.
- docs/PLUGINS.md, docs/augmentations/{COMPLETE-REFERENCE,README}.md:
HnswProvider→VectorIndexProvider, hnsw→vector key.
- docs/PERFORMANCE.md, docs/BATCHING.md cloud-detection + sharding
sections replaced with single-node vector tuning + filesystem framing.
Tier 2 — surgical renames + cloud-section deletions:
- architecture/{index,initialization-and-rebuild,overview}.md
- transactions.md, DEVELOPER_LEARNING_PATH.md
- vfs/{VFS_API_GUIDE,COMMON_PATTERNS}.md
- api/README.md, guides/{inspection,import-flow}.md
Tier 3 — light edits:
- docs/README.md, architecture/augmentation-system-audit.md
MIGRATION-V3-TO-V4.md untouched (internal migration doc, no stale terms).
2026-06-09 16:13:35 -07:00
const brain = new Brainy({ storage: { type: 'memory' } })
2025-08-26 12:32:21 -07:00
```
2026-01-27 15:38:21 -08:00
### FileSystemStorageAugmentation
**Location**: `src/augmentations/storageAugmentations.ts`
docs(8.0): Phase F — deep clean across 21 docs
Aligned every public doc to the 8.0 contract: filesystem + memory adapters
only, vector index provider terminology (config.vector with recall +
quantization + persistMode knobs), no cloud storage adapters, no closed-
source product names.
Tier 1 — heavier rewrites:
- docs/architecture/storage-architecture.md
- docs/architecture/data-storage-architecture.md
- docs/architecture/distributed-storage.md DELETED — content was 100%
cloud-coordination examples with no 8.0 substance.
- docs/guides/distributed-system.md DELETED — same reason; no inbound refs.
- docs/SCALING.md rewritten for single-node guidance.
- docs/PLUGINS.md, docs/augmentations/{COMPLETE-REFERENCE,README}.md:
HnswProvider→VectorIndexProvider, hnsw→vector key.
- docs/PERFORMANCE.md, docs/BATCHING.md cloud-detection + sharding
sections replaced with single-node vector tuning + filesystem framing.
Tier 2 — surgical renames + cloud-section deletions:
- architecture/{index,initialization-and-rebuild,overview}.md
- transactions.md, DEVELOPER_LEARNING_PATH.md
- vfs/{VFS_API_GUIDE,COMMON_PATTERNS}.md
- api/README.md, guides/{inspection,import-flow}.md
Tier 3 — light edits:
- docs/README.md, architecture/augmentation-system-audit.md
MIGRATION-V3-TO-V4.md untouched (internal migration doc, no stale terms).
2026-06-09 16:13:35 -07:00
**Auto-enabled**: When `storage: { type: 'filesystem' }` or Node.js detected
2025-08-26 12:32:21 -07:00
**Purpose**: Persistent file-based storage for Node.js applications
```typescript
2026-01-27 15:38:21 -08:00
const brain = new Brainy({
docs(8.0): Phase F — deep clean across 21 docs
Aligned every public doc to the 8.0 contract: filesystem + memory adapters
only, vector index provider terminology (config.vector with recall +
quantization + persistMode knobs), no cloud storage adapters, no closed-
source product names.
Tier 1 — heavier rewrites:
- docs/architecture/storage-architecture.md
- docs/architecture/data-storage-architecture.md
- docs/architecture/distributed-storage.md DELETED — content was 100%
cloud-coordination examples with no 8.0 substance.
- docs/guides/distributed-system.md DELETED — same reason; no inbound refs.
- docs/SCALING.md rewritten for single-node guidance.
- docs/PLUGINS.md, docs/augmentations/{COMPLETE-REFERENCE,README}.md:
HnswProvider→VectorIndexProvider, hnsw→vector key.
- docs/PERFORMANCE.md, docs/BATCHING.md cloud-detection + sharding
sections replaced with single-node vector tuning + filesystem framing.
Tier 2 — surgical renames + cloud-section deletions:
- architecture/{index,initialization-and-rebuild,overview}.md
- transactions.md, DEVELOPER_LEARNING_PATH.md
- vfs/{VFS_API_GUIDE,COMMON_PATTERNS}.md
- api/README.md, guides/{inspection,import-flow}.md
Tier 3 — light edits:
- docs/README.md, architecture/augmentation-system-audit.md
MIGRATION-V3-TO-V4.md untouched (internal migration doc, no stale terms).
2026-06-09 16:13:35 -07:00
storage: { type: 'filesystem', rootDirectory: './data' }
2025-08-26 12:32:21 -07:00
})
```
docs(8.0): Phase F — deep clean across 21 docs
Aligned every public doc to the 8.0 contract: filesystem + memory adapters
only, vector index provider terminology (config.vector with recall +
quantization + persistMode knobs), no cloud storage adapters, no closed-
source product names.
Tier 1 — heavier rewrites:
- docs/architecture/storage-architecture.md
- docs/architecture/data-storage-architecture.md
- docs/architecture/distributed-storage.md DELETED — content was 100%
cloud-coordination examples with no 8.0 substance.
- docs/guides/distributed-system.md DELETED — same reason; no inbound refs.
- docs/SCALING.md rewritten for single-node guidance.
- docs/PLUGINS.md, docs/augmentations/{COMPLETE-REFERENCE,README}.md:
HnswProvider→VectorIndexProvider, hnsw→vector key.
- docs/PERFORMANCE.md, docs/BATCHING.md cloud-detection + sharding
sections replaced with single-node vector tuning + filesystem framing.
Tier 2 — surgical renames + cloud-section deletions:
- architecture/{index,initialization-and-rebuild,overview}.md
- transactions.md, DEVELOPER_LEARNING_PATH.md
- vfs/{VFS_API_GUIDE,COMMON_PATTERNS}.md
- api/README.md, guides/{inspection,import-flow}.md
Tier 3 — light edits:
- docs/README.md, architecture/augmentation-system-audit.md
MIGRATION-V3-TO-V4.md untouched (internal migration doc, no stale terms).
2026-06-09 16:13:35 -07:00
For off-site backup, snapshot `rootDirectory` from your scheduler using `gsutil rsync` , `aws s3 sync` , `rclone` , or `tar` — there are no cloud storage augmentations.
2025-08-26 12:32:21 -07:00
### StorageAugmentation (base)
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/storageAugmentation.ts`
2025-08-26 12:32:21 -07:00
**Purpose**: Base class for custom storage implementations
### DynamicStorageAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/storageAugmentation.ts`
2025-08-26 12:32:21 -07:00
**Purpose**: Runtime storage adapter switching
---
## Performance Augmentations (7 total)
### CacheAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/cacheAugmentation.ts`
**Auto-enabled**: When `cache: true` (default)
2025-08-26 12:32:21 -07:00
**Purpose**: LRU cache for search results and frequent queries
```typescript
2026-01-27 15:38:21 -08:00
brain.clearCache() // Exposed via API
brain.getCacheStats() // Cache hit/miss statistics
2025-08-26 12:32:21 -07:00
```
### IndexAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/indexAugmentation.ts`
**Auto-enabled**: When `index: true` (default)
2025-08-26 12:32:21 -07:00
**Purpose**: Metadata indexing for O(1) field lookups
```typescript
brain.rebuildMetadataIndex() // Exposed via API
// Enables fast where queries:
brain.find({ where: { category: 'tech' } })
```
### MetricsAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/metricsAugmentation.ts`
**Auto-enabled**: Always active
2025-08-26 12:32:21 -07:00
**Purpose**: Performance metrics and statistics collection
```typescript
2026-01-27 15:38:21 -08:00
brain.getStats() // Comprehensive metrics
2025-08-26 12:32:21 -07:00
```
### MonitoringAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/monitoringAugmentation.ts`
**Manual**: Register for detailed monitoring
2025-08-26 12:32:21 -07:00
**Purpose**: Real-time performance monitoring and alerts
### BatchProcessingAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/batchProcessingAugmentation.ts`
**Auto-enabled**: For batch operations
2025-08-26 12:32:21 -07:00
**Purpose**: Optimizes bulk add/update/delete operations
```typescript
2026-01-27 15:38:21 -08:00
brain.addNouns([...]) // Automatically batched
2025-08-26 12:32:21 -07:00
```
### RequestDeduplicatorAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/requestDeduplicatorAugmentation.ts`
**Auto-enabled**: Always active
2025-08-26 12:32:21 -07:00
**Purpose**: Prevents duplicate concurrent operations
---
## Data Integrity Augmentations (3 total)
2026-01-27 15:38:21 -08:00
**Auto-enabled**: When `wal: true`
2025-08-26 12:32:21 -07:00
**Purpose**: Write-ahead logging for crash recovery
```typescript
2025-09-30 17:09:15 -07:00
const brain = new Brainy({ wal: true })
2025-08-26 12:32:21 -07:00
// Automatic recovery on restart after crash
```
### EntityRegistryAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/entityRegistryAugmentation.ts`
**Auto-enabled**: For streaming operations
2025-08-26 12:32:21 -07:00
**Purpose**: High-speed deduplication for real-time data
```typescript
// Prevents duplicate entities in streaming scenarios
docs: add deprecation warnings for addNoun and addVerb methods
- Add @deprecated JSDoc tags to TypeScript definitions
- Update all documentation examples to use modern add() and relate() API
- Preserve batch operations (addNouns, addVerbs) as they remain current
- Mark deprecated methods in both source and compiled definitions
Migration guide:
- addNoun(data, type, metadata) → add(data, { nounType: type, ...metadata })
- addVerb(source, target, type, metadata) → relate(source, target, type, metadata)
2025-09-17 10:48:41 -07:00
brain.add(data) // Automatically deduplicated
2025-08-26 12:32:21 -07:00
```
### AutoRegisterEntitiesAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/entityRegistryAugmentation.ts`
**Manual**: For automatic entity discovery
2025-08-26 12:32:21 -07:00
**Purpose**: Auto-discovers and registers entities from data
---
## Intelligence Augmentations (2 total)
### NeuralImportAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/neuralImport.ts`
**Manual**: Via `brain.neuralImport()`
2025-08-26 12:32:21 -07:00
**Purpose**: AI-powered smart data import
```typescript
const result = await brain.neuralImport(data, {
2026-01-27 15:38:21 -08:00
confidenceThreshold: 0.7,
autoApply: true
2025-08-26 12:32:21 -07:00
})
// Automatically detects entities and relationships
```
### IntelligentVerbScoringAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/intelligentVerbScoringAugmentation.ts`
**Auto-enabled**: When verbs are used
2025-08-26 12:32:21 -07:00
**Purpose**: ML-based relationship strength scoring
```typescript
brain.verbScoring.train(feedback)
brain.verbScoring.getScore(verbId)
```
---
## Communication Augmentations (4 total)
### APIServerAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/apiServerAugmentation.ts`
**Manual**: For server deployments
2025-08-26 12:32:21 -07:00
**Purpose**: REST/WebSocket/MCP API server
```typescript
const augmentation = new APIServerAugmentation()
await brain.registerAugmentation(augmentation)
// Exposes full Brainy API over network
```
### WebSocketConduitAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/conduitAugmentations.ts`
**Manual**: For Brainy-to-Brainy sync
2025-08-26 12:32:21 -07:00
**Purpose**: Real-time sync between Brainy instances
```typescript
const conduit = new WebSocketConduitAugmentation()
await conduit.establishConnection('ws://other-brain')
```
### ServerSearchConduitAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/serverSearchAugmentations.ts`
**Manual**: For client-server search
2025-08-26 12:32:21 -07:00
**Purpose**: Search remote Brainy instance, cache locally
### ServerSearchActivationAugmentation
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/serverSearchAugmentations.ts`
**Manual**: Works with ServerSearchConduit
2025-08-26 12:32:21 -07:00
**Purpose**: Triggers and manages server search operations
---
## External Integration (2 total)
### SynapseAugmentation (base)
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/synapseAugmentation.ts`
2025-08-26 12:32:21 -07:00
**Purpose**: Base class for external platform integrations
```typescript
// Example: NotionSynapse, SlackSynapse, etc.
class NotionSynapse extends SynapseAugmentation {
2026-01-27 15:38:21 -08:00
async fetchData() { /* Notion API calls */ }
async pushData() { /* Sync to Notion */ }
2025-08-26 12:32:21 -07:00
}
```
### ExampleFileSystemSynapse
2026-01-27 15:38:21 -08:00
**Location**: `src/augmentations/synapseAugmentation.ts`
2025-08-26 12:32:21 -07:00
**Purpose**: Example implementation for file system sync
---
## Augmentation Configuration
### Auto-Configuration
```typescript
2025-09-30 17:09:15 -07:00
const brain = new Brainy({
docs(8.0): Phase F — deep clean across 21 docs
Aligned every public doc to the 8.0 contract: filesystem + memory adapters
only, vector index provider terminology (config.vector with recall +
quantization + persistMode knobs), no cloud storage adapters, no closed-
source product names.
Tier 1 — heavier rewrites:
- docs/architecture/storage-architecture.md
- docs/architecture/data-storage-architecture.md
- docs/architecture/distributed-storage.md DELETED — content was 100%
cloud-coordination examples with no 8.0 substance.
- docs/guides/distributed-system.md DELETED — same reason; no inbound refs.
- docs/SCALING.md rewritten for single-node guidance.
- docs/PLUGINS.md, docs/augmentations/{COMPLETE-REFERENCE,README}.md:
HnswProvider→VectorIndexProvider, hnsw→vector key.
- docs/PERFORMANCE.md, docs/BATCHING.md cloud-detection + sharding
sections replaced with single-node vector tuning + filesystem framing.
Tier 2 — surgical renames + cloud-section deletions:
- architecture/{index,initialization-and-rebuild,overview}.md
- transactions.md, DEVELOPER_LEARNING_PATH.md
- vfs/{VFS_API_GUIDE,COMMON_PATTERNS}.md
- api/README.md, guides/{inspection,import-flow}.md
Tier 3 — light edits:
- docs/README.md, architecture/augmentation-system-audit.md
MIGRATION-V3-TO-V4.md untouched (internal migration doc, no stale terms).
2026-06-09 16:13:35 -07:00
// These auto-register augmentations:
storage: { type: 'auto', rootDirectory: './brainy-data' }, // Storage augmentation
cache: true, // Cache augmentation
index: true, // Index augmentation
metrics: true // Metrics augmentation
2025-08-26 12:32:21 -07:00
})
```
### Manual Registration
```typescript
2025-09-30 17:09:15 -07:00
const brain = new Brainy()
2025-08-26 12:32:21 -07:00
// Register before init()
const customAug = new MyCustomAugmentation()
await brain.registerAugmentation(customAug)
await brain.init()
```
### Creating Custom Augmentations
```typescript
import { BaseAugmentation } from '@soulcraft/brainy '
class MyAugmentation extends BaseAugmentation {
2026-01-27 15:38:21 -08:00
readonly name = 'my-augmentation'
readonly timing = 'after' // before | after | both
readonly operations = ['addNoun', 'search'] // Which ops to hook
readonly priority = 10 // Execution order (lower = earlier)
protected async onInit(): Promise< void > {
// Initialize your augmentation
}
async execute< T > (
operation: string,
params: any,
context?: AugmentationContext
): Promise< T | void > {
// Your augmentation logic
if (operation === 'addNoun') {
console.log('Noun added:', params)
}
}
protected async onShutdown(): Promise< void > {
// Cleanup
}
2025-08-26 12:32:21 -07:00
}
```
---
## Augmentation Timing & Priority
### Timing Options
- **`before` **: Runs before the operation (can modify params)
- **`after` **: Runs after the operation (can see results)
- **`both` **: Runs before AND after
### Priority (lower = earlier)
1. Storage augmentations (priority: 0)
2. Cache/Index augmentations (priority: 5-10)
3. Monitoring/Metrics (priority: 15-20)
4. Conduits/Synapses (priority: 20-30)
---
## Key Integration Points
### Where Augmentations Hook In
2025-09-30 17:09:15 -07:00
**Brainy Constructor**:
2025-08-26 12:32:21 -07:00
- Storage augmentations register based on config
- Cache/Index augmentations auto-register if enabled
**brain.init()**:
- Two-phase initialization (storage first, then others)
- Augmentations can access brain instance via context
**Operations** (addNoun, search, etc.):
- Augmentations execute based on timing and operations filter
- Can modify params (before) or see results (after)
**brain.shutdown()**:
- All augmentations cleaned up in reverse order
---
## Performance Impact
Most augmentations have minimal overhead:
- **Cache**: ~1ms per search (saves 10-100ms on hits)
- **Index**: ~1ms per operation (saves 100ms+ on queries)
- **Metrics**: < 1ms per operation
docs(8.0): Phase F — deep clean across 21 docs
Aligned every public doc to the 8.0 contract: filesystem + memory adapters
only, vector index provider terminology (config.vector with recall +
quantization + persistMode knobs), no cloud storage adapters, no closed-
source product names.
Tier 1 — heavier rewrites:
- docs/architecture/storage-architecture.md
- docs/architecture/data-storage-architecture.md
- docs/architecture/distributed-storage.md DELETED — content was 100%
cloud-coordination examples with no 8.0 substance.
- docs/guides/distributed-system.md DELETED — same reason; no inbound refs.
- docs/SCALING.md rewritten for single-node guidance.
- docs/PLUGINS.md, docs/augmentations/{COMPLETE-REFERENCE,README}.md:
HnswProvider→VectorIndexProvider, hnsw→vector key.
- docs/PERFORMANCE.md, docs/BATCHING.md cloud-detection + sharding
sections replaced with single-node vector tuning + filesystem framing.
Tier 2 — surgical renames + cloud-section deletions:
- architecture/{index,initialization-and-rebuild,overview}.md
- transactions.md, DEVELOPER_LEARNING_PATH.md
- vfs/{VFS_API_GUIDE,COMMON_PATTERNS}.md
- api/README.md, guides/{inspection,import-flow}.md
Tier 3 — light edits:
- docs/README.md, architecture/augmentation-system-audit.md
MIGRATION-V3-TO-V4.md untouched (internal migration doc, no stale terms).
2026-06-09 16:13:35 -07:00
- **Storage**: Varies by adapter (memory: 0ms, filesystem: 1-10ms)
2025-08-26 12:32:21 -07:00
---
## Best Practices
1. **Let auto-configuration work** : Most apps need zero manual config
2. **Storage first** : Always configure storage before other augmentations
3. **Use built-in augmentations** : They're optimized and battle-tested
4. **Custom augmentations** : Extend BaseAugmentation for consistency
5. **Respect timing** : Use 'before' to modify, 'after' to observe
6. **Mind priority** : Lower numbers execute first
---
## Troubleshooting
### Augmentation not working?
```typescript
// Check if registered
brain.listAugmentations()
// Check if enabled
brain.isAugmentationEnabled('cache')
// Enable/disable at runtime
brain.enableAugmentation('cache')
brain.disableAugmentation('cache')
```
### Performance issues?
```typescript
// Check augmentation overhead
2025-10-09 11:40:31 -07:00
const stats = brain.getStats()
2025-08-26 12:32:21 -07:00
console.log(stats.augmentations)
// Disable non-critical augmentations
brain.disableAugmentation('monitoring')
```
---
---
*Augmentations make Brainy infinitely extensible while keeping the core API clean and simple!*