2025-06-24 11:41:30 -07:00
/ * *
2025-07-11 11:11:56 -07:00
* Brainy
* A vector and graph database using HNSW
2025-06-24 11:41:30 -07:00
* /
2025-07-14 11:12:51 -07:00
// CRITICAL: The TensorFlow.js environment patch is now centralized in setup.ts
// We import setup.js below which applies the necessary patches through textEncoding.js
// This ensures a consistent patching approach and avoids conflicts
2025-07-11 11:11:56 -07:00
// Import the setup file for its side-effects.
// This MUST be the very first import to ensure patches are applied
// before any other module (like TensorFlow.js) is loaded.
import './setup.js'
2025-07-04 14:42:33 -07:00
2025-06-24 11:41:30 -07:00
// Export main BrainyData class and related types
2025-07-21 13:59:33 -07:00
import { BrainyData , BrainyDataConfig } from './brainyData.js'
2025-06-24 11:41:30 -07:00
2025-07-21 13:59:33 -07:00
export { BrainyData }
export type { BrainyDataConfig }
2025-06-24 11:41:30 -07:00
// Export distance functions for convenience
import {
2025-07-21 13:59:33 -07:00
euclideanDistance ,
cosineDistance ,
manhattanDistance ,
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
dotProductDistance ,
getStatistics
2025-06-24 11:41:30 -07:00
} from './utils/index.js'
export {
2025-07-21 13:59:33 -07:00
euclideanDistance ,
cosineDistance ,
manhattanDistance ,
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
dotProductDistance ,
getStatistics
2025-06-24 11:41:30 -07:00
}
// Export embedding functionality
import {
2025-07-21 13:59:33 -07:00
UniversalSentenceEncoder ,
createEmbeddingFunction ,
createTensorFlowEmbeddingFunction ,
createThreadedEmbeddingFunction ,
defaultEmbeddingFunction
2025-06-24 11:41:30 -07:00
} from './utils/embedding.js'
2025-07-01 10:39:12 -07:00
// Export worker utilities
2025-07-21 13:59:33 -07:00
import { executeInThread , cleanupWorkerPools } from './utils/workerUtils.js'
2025-07-01 10:39:12 -07:00
2025-07-04 14:42:33 -07:00
// Export environment utilities
import {
2025-07-21 13:59:33 -07:00
isBrowser ,
isNode ,
isWebWorker ,
areWebWorkersAvailable ,
areWorkerThreadsAvailable ,
areWorkerThreadsAvailableSync ,
isThreadingAvailable ,
isThreadingAvailableAsync
2025-07-04 14:42:33 -07:00
} from './utils/environment.js'
2025-06-24 11:41:30 -07:00
export {
2025-07-21 13:59:33 -07:00
UniversalSentenceEncoder ,
createEmbeddingFunction ,
createTensorFlowEmbeddingFunction ,
createThreadedEmbeddingFunction ,
defaultEmbeddingFunction ,
// Worker utilities
executeInThread ,
cleanupWorkerPools ,
// Environment utilities
isBrowser ,
isNode ,
isWebWorker ,
areWebWorkersAvailable ,
areWorkerThreadsAvailable ,
areWorkerThreadsAvailableSync ,
isThreadingAvailable ,
isThreadingAvailableAsync
2025-06-24 11:41:30 -07:00
}
// Export storage adapters
import {
2025-07-21 13:59:33 -07:00
OPFSStorage ,
MemoryStorage ,
FileSystemStorage ,
R2Storage ,
S3CompatibleStorage ,
createStorage
2025-07-21 12:48:03 -07:00
} from './storage/storageFactory.js'
2025-06-24 11:41:30 -07:00
export {
2025-07-21 13:59:33 -07:00
OPFSStorage ,
MemoryStorage ,
FileSystemStorage ,
R2Storage ,
S3CompatibleStorage ,
createStorage
2025-06-24 11:41:30 -07:00
}
// Export unified pipeline
import {
2025-07-21 13:59:33 -07:00
Pipeline ,
pipeline ,
augmentationPipeline ,
ExecutionMode ,
PipelineOptions ,
PipelineResult ,
executeStreamlined ,
executeByType ,
executeSingle ,
processStaticData ,
processStreamingData ,
createPipeline ,
createStreamingPipeline ,
StreamlinedExecutionMode ,
StreamlinedPipelineOptions ,
StreamlinedPipelineResult
2025-06-24 11:41:30 -07:00
} from './pipeline.js'
// Export sequential pipeline (for backward compatibility)
import {
2025-07-21 13:59:33 -07:00
SequentialPipeline ,
sequentialPipeline ,
SequentialPipelineOptions
2025-06-24 11:41:30 -07:00
} from './sequentialPipeline.js'
// Export augmentation factory
import {
2025-07-21 13:59:33 -07:00
createSenseAugmentation ,
addWebSocketSupport ,
executeAugmentation ,
loadAugmentationModule ,
AugmentationOptions
2025-06-24 11:41:30 -07:00
} from './augmentationFactory.js'
export {
2025-07-21 13:59:33 -07:00
// Unified pipeline exports
Pipeline ,
pipeline ,
augmentationPipeline ,
ExecutionMode ,
SequentialPipeline ,
sequentialPipeline ,
// Streamlined pipeline exports (now part of unified pipeline)
executeStreamlined ,
executeByType ,
executeSingle ,
processStaticData ,
processStreamingData ,
createPipeline ,
createStreamingPipeline ,
StreamlinedExecutionMode ,
// Augmentation factory exports
createSenseAugmentation ,
addWebSocketSupport ,
executeAugmentation ,
loadAugmentationModule
2025-06-24 11:41:30 -07:00
}
2025-06-26 10:56:14 -07:00
export type {
2025-07-21 13:59:33 -07:00
PipelineOptions ,
PipelineResult ,
SequentialPipelineOptions ,
StreamlinedPipelineOptions ,
StreamlinedPipelineResult ,
AugmentationOptions
2025-06-24 11:41:30 -07:00
}
// Export augmentation registry for build-time loading
import {
2025-07-21 13:59:33 -07:00
availableAugmentations ,
registerAugmentation ,
initializeAugmentationPipeline ,
setAugmentationEnabled ,
getAugmentationsByType
2025-06-24 11:41:30 -07:00
} from './augmentationRegistry.js'
export {
2025-07-21 13:59:33 -07:00
availableAugmentations ,
registerAugmentation ,
initializeAugmentationPipeline ,
setAugmentationEnabled ,
getAugmentationsByType
2025-06-24 11:41:30 -07:00
}
// Export augmentation registry loader for build tools
import {
2025-07-21 13:59:33 -07:00
loadAugmentationsFromModules ,
createAugmentationRegistryPlugin ,
createAugmentationRegistryRollupPlugin
2025-06-24 11:41:30 -07:00
} from './augmentationRegistryLoader.js'
import type {
2025-07-21 13:59:33 -07:00
AugmentationRegistryLoaderOptions ,
AugmentationLoadResult
2025-06-24 11:41:30 -07:00
} from './augmentationRegistryLoader.js'
export {
2025-07-21 13:59:33 -07:00
loadAugmentationsFromModules ,
createAugmentationRegistryPlugin ,
createAugmentationRegistryRollupPlugin
2025-06-24 11:41:30 -07:00
}
2025-07-21 13:59:33 -07:00
export type { AugmentationRegistryLoaderOptions , AugmentationLoadResult }
2025-06-24 11:41:30 -07:00
// Export augmentation implementations
import {
2025-07-21 13:59:33 -07:00
MemoryStorageAugmentation ,
FileSystemStorageAugmentation ,
OPFSStorageAugmentation ,
createMemoryAugmentation
2025-06-24 11:41:30 -07:00
} from './augmentations/memoryAugmentations.js'
import {
2025-07-21 13:59:33 -07:00
WebSocketConduitAugmentation ,
WebRTCConduitAugmentation ,
createConduitAugmentation
2025-06-24 11:41:30 -07:00
} from './augmentations/conduitAugmentations.js'
import {
2025-07-21 13:59:33 -07:00
ServerSearchConduitAugmentation ,
ServerSearchActivationAugmentation ,
createServerSearchAugmentations
2025-06-24 11:41:30 -07:00
} from './augmentations/serverSearchAugmentations.js'
// Non-LLM exports
export {
2025-07-21 13:59:33 -07:00
MemoryStorageAugmentation ,
FileSystemStorageAugmentation ,
OPFSStorageAugmentation ,
createMemoryAugmentation ,
WebSocketConduitAugmentation ,
WebRTCConduitAugmentation ,
createConduitAugmentation ,
ServerSearchConduitAugmentation ,
ServerSearchActivationAugmentation ,
createServerSearchAugmentations
2025-06-24 11:41:30 -07:00
}
// LLM augmentations are optional and not imported by default
// They can be imported directly from their module if needed:
// import { LLMCognitionAugmentation, LLMActivationAugmentation, createLLMAugmentations } from './augmentations/llmAugmentations.js'
// Export types
import type {
2025-07-21 13:59:33 -07:00
Vector ,
VectorDocument ,
SearchResult ,
DistanceFunction ,
EmbeddingFunction ,
EmbeddingModel ,
HNSWNoun ,
GraphVerb ,
HNSWConfig ,
StorageAdapter
2025-06-24 11:41:30 -07:00
} from './coreTypes.js'
// Export HNSW index and optimized version
2025-07-21 13:59:33 -07:00
import { HNSWIndex } from './hnsw/hnswIndex.js'
2025-06-26 10:56:14 -07:00
import {
2025-07-21 13:59:33 -07:00
HNSWIndexOptimized ,
HNSWOptimizedConfig
2025-06-26 10:56:14 -07:00
} from './hnsw/hnswIndexOptimized.js'
2025-06-24 11:41:30 -07:00
2025-07-21 13:59:33 -07:00
export { HNSWIndex , HNSWIndexOptimized }
2025-06-24 11:41:30 -07:00
export type {
2025-07-21 13:59:33 -07:00
Vector ,
VectorDocument ,
SearchResult ,
DistanceFunction ,
EmbeddingFunction ,
EmbeddingModel ,
HNSWNoun ,
GraphVerb ,
HNSWConfig ,
HNSWOptimizedConfig ,
StorageAdapter
2025-06-24 11:41:30 -07:00
}
// Export augmentation types
import type {
2025-07-21 13:59:33 -07:00
IAugmentation ,
AugmentationResponse ,
IWebSocketSupport ,
ISenseAugmentation ,
IConduitAugmentation ,
ICognitionAugmentation ,
IMemoryAugmentation ,
IPerceptionAugmentation ,
IDialogAugmentation ,
IActivationAugmentation
2025-06-24 11:41:30 -07:00
} from './types/augmentations.js'
2025-07-21 13:59:33 -07:00
import { AugmentationType , BrainyAugmentations } from './types/augmentations.js'
2025-06-24 11:41:30 -07:00
2025-07-21 13:59:33 -07:00
export type { IAugmentation , AugmentationResponse , IWebSocketSupport }
2025-06-24 11:41:30 -07:00
export {
2025-07-21 13:59:33 -07:00
AugmentationType ,
BrainyAugmentations ,
ISenseAugmentation ,
IConduitAugmentation ,
ICognitionAugmentation ,
IMemoryAugmentation ,
IPerceptionAugmentation ,
IDialogAugmentation ,
IActivationAugmentation
2025-06-24 11:41:30 -07:00
}
// Export combined WebSocket augmentation interfaces
export type {
2025-07-21 13:59:33 -07:00
IWebSocketCognitionAugmentation ,
IWebSocketSenseAugmentation ,
IWebSocketPerceptionAugmentation ,
IWebSocketActivationAugmentation ,
IWebSocketDialogAugmentation ,
IWebSocketConduitAugmentation ,
IWebSocketMemoryAugmentation
2025-06-24 11:41:30 -07:00
} from './types/augmentations.js'
// Export graph types
import type {
2025-07-21 13:59:33 -07:00
GraphNoun ,
EmbeddedGraphVerb ,
Person ,
Place ,
Thing ,
Event ,
Concept ,
Content
2025-06-24 11:41:30 -07:00
} from './types/graphTypes.js'
2025-07-21 13:59:33 -07:00
import { NounType , VerbType } from './types/graphTypes.js'
2025-06-24 11:41:30 -07:00
export type {
2025-07-21 13:59:33 -07:00
GraphNoun ,
EmbeddedGraphVerb ,
Person ,
Place ,
Thing ,
Event ,
Concept ,
Content
2025-06-24 11:41:30 -07:00
}
2025-07-21 13:59:33 -07:00
export { NounType , VerbType }
2025-06-24 11:41:30 -07:00
// Export MCP (Model Control Protocol) components
import {
2025-07-21 13:59:33 -07:00
BrainyMCPAdapter ,
MCPAugmentationToolset ,
BrainyMCPService
2025-06-24 11:41:30 -07:00
} from './mcp/index.js' // Import from mcp/index.js
import {
2025-07-21 13:59:33 -07:00
MCPRequest ,
MCPResponse ,
MCPDataAccessRequest ,
MCPToolExecutionRequest ,
MCPSystemInfoRequest ,
MCPAuthenticationRequest ,
MCPRequestType ,
MCPServiceOptions ,
MCPTool ,
MCP_VERSION
2025-06-24 11:41:30 -07:00
} from './types/mcpTypes.js'
export {
2025-07-21 13:59:33 -07:00
// MCP classes
BrainyMCPAdapter ,
MCPAugmentationToolset ,
BrainyMCPService ,
// MCP types
MCPRequestType ,
MCP_VERSION
2025-06-24 11:41:30 -07:00
}
export type {
2025-07-21 13:59:33 -07:00
MCPRequest ,
MCPResponse ,
MCPDataAccessRequest ,
MCPToolExecutionRequest ,
MCPSystemInfoRequest ,
MCPAuthenticationRequest ,
MCPServiceOptions ,
MCPTool
2025-06-24 11:41:30 -07:00
}