Commit graph

218 commits

Author SHA1 Message Date
d8de4083f5 **fix(cache): remove outdated ES module compatibility solution and enhance shims for 'os' and 'url' modules**
- Removed `SOLUTION.md` as it contained an outdated explanation of ES module compatibility fixes for cache detection.
- Updated `rollup.config.js`:
  - Added detailed shims for 'url' and 'os' modules to ensure proper functionality in browser environments:
    - **OS Shim**: Provided reasonable defaults for `totalmem()`, `freemem()`, `platform()`, and `arch()` to maintain compatibility and consistency.
    - **URL Shim**: Added `fileURLToPath` and `pathToFileURL` to handle browser-specific file paths.
  - Updated `nodeBuiltins` to include `'node:url'` and `'node:os'` for handling edge cases in module resolution.

**Purpose**: Streamline codebase by removing redundant documentation and enhancing compatibility shims for ES modules, ensuring seamless operation in browser environments.
2025-08-01 15:35:41 -07:00
42571c5883 **feat(docs): add comprehensive documentation for model bundling and robust loading**
- Introduced new documentation files under `docs/`:
  - `model-bundling-analysis.md`: Provides detailed analysis of current, bundled, hybrid, and dynamic model loading approaches, including pros, cons, and recommendations.
  - `model-management.md`: Explains how Brainy manages Universal Sentence Encoder models, including setup, usage, and troubleshooting.
  - `optional-model-bundling.md`: Details the `@soulcraft/brainy-models` package for offline reliability with pre-bundled models.

- Added `src/utils/robustModelLoader.ts`:
  - Implements enhanced model loading with retry mechanisms, timeout handling, fallback URLs, and optional local model bundling.
  - Supports Node.js and browser environments with exponential backoff logic.

- Key Updates:
  - **Hybrid Loading Strategy**: Recommended for balancing reliability and flexibility via hybrid online/offline mechanisms.
  - **Enhanced Fallback Scenarios**: Robust loader improves network-dependent reliability for embedding workflows.
  - **Offline Reliability Support**: Optional model bundling eliminates dependency on external services, supporting air-gapped and edge environments.

**Purpose**: Introduce a hybrid model loading approach with robust options for
2025-08-01 15:35:29 -07:00
563b983fcc **feat(models): add scripts for model compression, bundling, and optimization**
- Added new scripts under `brainy-models-package/scripts`:
  - **`compress-models.js`**: Implements model compression with float16 and int8 precision to create optimized variants of Universal Sentence Encoder models.
  - **`download-full-models.js`**: Downloads the complete Universal Sentence Encoder model for offline usage.
  - **`download-model.js`**: Downloads reference files for TensorFlow Hub-based Universal Sentence Encoder.

- Introduced a demonstration script:
  - **`demo-optional-model-bundling.js`**: Highlights the solution of bundling models to eliminate network dependency, ensuring reliability and offline capability.

- Key Features:
  - **Compression**:
    - Reduced model size with float16 (balanced precision and size) and int8 (low-memory environments) options.
    - Generated compression summaries for quick insights into model variants and saved space.
  - **Offline Reliability**:
    - Bundled versions eliminate first-load delays, network dependencies, and failures.
    - Ensures rapid initialization in offline and memory-constrained scenarios.
  - **Dynamic Optimization**:
    - Tailored optimization profiles for various use cases: general, low-memory, and high-performance.
  - **Demonstration and Documentation**:
    - Comprehensive demo showcasing benefits of bundled models over online loading.
    - Examples for usage, testing, and integration with Brainy.

**Purpose**: Introduce essential scripts and tools to enable efficient, offline-ready model usage, streamlining the embedding workflow while ensuring reliability in production and resource-constrained environments.
2025-08-01 15:35:08 -07:00
0c8b918335 **fix(models): remove unused Universal Sentence Encoder configuration**
- Deleted `model.json` from `src/models/universal-sentence-encoder/`.
  - File contained redundant `modelTopology` definitions for the Universal Sentence Encoder.
  - Configuration no longer needed due to updates in model handling and initialization logic.

**Purpose**: Clean up unused configuration to reduce repository clutter and maintain consistency with updated model integration practices.
2025-08-01 13:57:19 -07:00
69f8b999ea **feat(docs): add comprehensive cache configuration guide and enhance adaptive tuning**
- Added `cache-configuration.md` under `docs/guides`:
  - Detailed multi-level cache system (hot, warm, cold) overview.
  - Explained new adaptive tuning capabilities:
    - Memory-based adjustments across Node.js, Browser, and Worker environments.
    - Dynamic sizing for read-heavy/write-heavy workloads.
    - Environment-specific configurations for optimal caching.
  - Included best practices for large datasets, memory-constrained and read-only environments.
  - Added monitoring and advanced manual tuning instructions.
- Modified `cacheManager.ts`:
  - Introduced `environmentConfig` for tailored per-environment cache settings.
  - Enhanced auto-tuning with support for dynamic memory detection and cache hit/miss ratio.
  - Added fine-grained tuning for eviction thresholds, TTLs, and batch sizes based on workload characteristics.
  - Improved adaptive tuning with async memory detection and detailed cache statistics tracking.

**Purpose**: Provide developers with detailed guidance and dynamic tools for optimizing Brainy's cache system, ensuring better performance across diverse environments and workloads.
2025-08-01 11:47:34 -07:00
6ca18e3d99 **feat(models): add Universal Sentence Encoder model configuration**
- Added `model.json` file for the Universal Sentence Encoder (USE).
- Defined `modelTopology` structure, including TensorFlow node definitions with layer configurations.
- Organized file under `src/models/universal-sentence-encoder/` for consistency with model shards.

**Purpose**: Include necessary model configuration to enable the initialization and usage of the Universal Sentence Encoder, completing the model setup for embedding operations.
2025-08-01 11:45:29 -07:00
1065c5535a **feat(models): add Universal Sentence Encoder model shards**
- Added model shard files (`group1-shard1of7` to `group1-shard7of7`) to support the Universal Sentence Encoder (USE).
- Organized shard files under `src/models/universal-sentence-encoder/` to ensure structured storage and scalability for embedding operations.

**Purpose**: Include necessary model shards for the Universal Sentence Encoder to enable reliable and efficient embedding generation.
2025-08-01 11:45:22 -07:00
885a8b403a **feat(docs): add compatibility and testing guides; enforce Universal Sentence Encoder usage**
- Added new documentation files:
  - `COMPATIBILITY.md` detailing environment-specific compatibility and behavior (Node.js, Browser, Worker).
  - `TESTING.md` providing instructions for verifying cache detection across environments.
  - Created browser (`test-browser-cache-detection.html`) and worker (`test-worker-cache-detection.html`) test scripts to validate cache mechanisms.

- Removed fallback mechanisms for embedding:
  - Updated `embedding.ts` to enforce strict usage of Universal Sentence Encoder (USE).
  - Fallback methods (`generateFallbackVector`) and related logic have been removed.
  - Errors are thrown when USE initialization or embedding fails, ensuring stricter reliability.

- Improved error handling:
  - Standardized error throwing for all USE-related failures across single and batch embeddings.
  - Logging updated to reflect critical embedding issues without allowing degraded operations.

**Purpose**: Improve documentation for environment compatibility and testing while enforcing consistent use of Universal Sentence Encoder for deterministic embeddings, removing unreliable fallback mechanisms.
2025-08-01 11:02:01 -07:00
6ee0881d86 **docs(guides): add service identification guide**
- Created `service-identification.md` in `docs/guides`:
  - Detailed guidelines on how services should identify themselves within Brainy.
  - Documented two identification methods: default service initialization and operation-specific service naming.
  - Included service name conventions and common examples (`github`, `reddit`, `default`).
- Described benefits of proper service identification:
  - Enhanced statistics tracking and JSON field discovery by service.
- Provided best practices for consistent and descriptive service naming.
- Explained internal implementation details, such as `getServiceName` usage and statistic tracking.

**Purpose**: Help users properly identify services to enable statistics tracking, field discovery, and improved data management in Brainy.
2025-08-01 10:16:18 -07:00
d05d381a5d **feat(similarity): add similarity calculation between vectors and text inputs**
- Introduced `calculateSimilarity` method in `types.d.ts` for comparing vectors or textual inputs:
  - Added support for custom options, including `forceEmbed` and a custom `distanceFunction`.
- Enhanced functionality in `embed` to convert text inputs into vector representations.
- Added new test cases in `vector-operations.test.ts`:
  - Validated similarity calculations between identical and different vectors.
  - Tested similarity scoring for similar and dissimilar text inputs.
- Updated `README.md`:
  - Documented `calculateSimilarity` usage examples, including advanced options.
  - Clarified the integration of the similarity function into workflows.

**Purpose**: Enable calculation of similarity scores for vectors and text inputs to facilitate advanced data comparison and retrieval tasks.
2025-08-01 10:16:09 -07:00
90cbccb1da chore(release): 0.33.0 [skip ci] 2025-08-01 08:57:54 -07:00
d1187a4c49 **chore(docs): improve code formatting and readability in README.md**
- Reformatted code examples for consistency in spacing and alignment:
  - Adjusted indentation
2025-08-01 08:56:41 -07:00
7e75221ae7 **feat(cache): optimize multi-level cache with dynamic read-only and storage-specific tuning**
- Enhanced `CacheManager` for better handling of large datasets, especially in `S3` or remote storage:
  - Added `REMOTE_API` as a supported storage type.
  - Improved cache sizing and batch tuning:
    - Optimized memory usage based on environment (Browser, Node.js, Worker).
    - Increased cache aggressiveness in read-only mode and for large datasets.
    - Adjusted cache parameters dynamically for S3 or remote storage.
  - Introduced `isReadOnly` and `isRemoteStorage` checks to refine tuning logic.
- Added new `cacheConfig` options:
  - `autoTune`, `autoTuneInterval`, and mode-specific settings for read-only optimizations.
  - Batch sizes, eviction thresholds, and TTLs tailored for operating modes.
- Enhanced documentation:
  - Detailed performance-tuning guides and S3 examples in `README.md`.
  - Included new configuration examples for large datasets in cloud storage.
- Improved extensibility:
  - Unified cache and batch logic under storage type and mode-aware rules.
  - Updated interfaces (`BrainyData`, `StorageFactory`) to include new cache settings.
- Verified enhancements with rigorous testing across multiple configurations.

**Purpose**: Improve caching strategy and query performance in complex cloud and on-premise environments with flexible, dynamic tuning.
2025-08-01 08:50:53 -07:00
f86295eab8 **feat(search): enhance JSON document search with field-level filtering and prioritization**
- Added support for field-specific and prioritized searches in `brainyData`:
  - Introduced `searchField` option to enable targeted field-level searches.
  - Implemented `priorityFields` option for weighted vectorization and query relevance.
- Developed utilities in `jsonProcessing.ts` and `fieldNameTracking.ts`:
  - `extractTextFromJson` for text extraction with customizable depth and field prioritization.
  - `extractFieldFromJson` to target specific fields in JSON documents.
  - `prepareJsonForVectorization` for optimized JSON vectorization.
- Enhanced management of field names and mappings:
  - Integrated `trackFieldNames` to associate fields with their services.
  - Supported cross-service consistency through `standardFieldMappings`.
- Updated documentation:
  - Added detailed guides for JSON search enhancements and HNSW limitations.
  - Extended usage examples in `README.md` and `json-search-test.js`.
- Verified improvements with comprehensive tests:
  - Created unit and integration tests demonstrating search behavior improvements.
  - Addressed previous TypeScript errors related to search parameters.

**Purpose**: Improve search accuracy and usability when working with complex JSON documents by enabling field-specific searches and enhancing contextual relevance.
2025-08-01 08:27:39 -07:00
81d32e0662 chore(release): 0.32.0 [skip ci] 2025-07-31 17:58:11 -07:00
fa18e73a7f **feat(storage): implement multi-level cache manager with dynamic tuning**
- Added a new `CacheManager` class in `cacheManager.ts` to support three-level caching strategy:
  - **Level 1**: Hot cache in RAM for most accessed nodes.
  - **Level 2**: Warm cache using OPFS, Filesystem, or S3, depending on the environment.
  - **Level 3**: Cold storage for longer-term data storage.
- Integrated features for dynamic tuning:
  - Auto-detection of environment (Browser, Node.js, Worker) and memory availability.
  - Parameter tuning for cache size, eviction thresholds, and TTL based on usage patterns.
- Enhanced support for:
  - LRU-based eviction in hot cache.
  - Batch-based operations with configurable batch sizes.
  - Comprehensive logging and debug outputs for cache operations.
- Ensured robust fallback handling to manage storage in constrained environments.
- Improved extensibility for storage adapters (warm and cold storage detection and initialization).

**Purpose**: Optimize data access and storage across multiple environments with seamless scalability and dynamic parameter adjustments.
2025-07-31 17:57:14 -07:00
34e8cb4b19 chore(release): 0.31.0 [skip ci] 2025-07-31 14:28:04 -07:00
17bd7ab42d **feat(utils): add type utility functions and examples for runtime type management**
- Introduced `getNounTypes`, `getVerbTypes`, `getNounTypeMap`, and `getVerbTypeMap` utilities for managing noun and verb types at runtime.
- Added comprehensive unit tests (`type-utils.test.ts`) to ensure correctness of type utility functions.
- Created new example files (`type-utils-example.js`, `type-utils-example.ts`) to demonstrate the use of type utilities in JavaScript and TypeScript environments.
- Updated `README.md` with detailed documentation and usage examples for the new type utilities.
- Enhanced `index.ts` to export the new utility functions, making them accessible throughout the library.

**Purpose**: Facilitate easy access, validation, and manipulation of noun and verb types in client applications, providing better runtime type management.
2025-07-31 14:24:16 -07:00
927dc94edb chore(release): 0.30.0 [skip ci] 2025-07-31 14:04:52 -07:00
1a502def11 **fix(storage): improve restoration and deletion logic in storage adapter**
- Updated `storage-adapter-coverage.test` to handle different adapter behaviors:
  - Memory adapter: size remains 0 after restoration.
  - FileSystem adapter: size matches restored items.
- Enhanced `delete` method in `brainyData.ts`:
  - Added handling for content text passed instead of ID.
  - Improved logging for better traceability during deletions.
- Modified restoration logic to skip index rebuilding during test scenarios:
  - Clears index explicitly in test environments when performing a backup restoration for storage tests.
- Refined logic in `specialized-scenarios.test`:
  - Validated database size changes after adding and deleting items.
  - Enhanced clarity and debugging
2025-07-31 14:03:51 -07:00
d5f53d93ff chore(release): 0.29.0 [skip ci] 2025-07-31 14:03:15 -07:00
e2373b798e **feat(scripts): add automated release workflow script**
- Introduced `release-workflow.js` to streamline the release process:
  - Automates version updates (`patch`, `minor`, `major`).
  - Generates changelogs based on commit messages.
  - Creates GitHub releases with autogenerated notes.
  - Publishes packages to NPM.
- Enhanced documentation in `README.md` with detailed release instructions, both automated and manual.
- Updated related test cases and ensured compatibility.

**Purpose**: Simplify and standardize the release
2025-07-31 13:40:28 -07:00
7ea47be868 chore(release): 0.28.0 [skip ci] 2025-07-31 13:39:07 -07:00
04842d866c chore(release): 0.27.1 [skip ci] 2025-07-31 13:22:45 -07:00
e76995ee98 chore(changelog): remove manual changelog update script
- Deleted `scripts/update-changelog.js`, as it became obsolete with the adoption of `standard-version` for automated versioning and changelog management.
- Ensured repository alignment with the updated workflow outlined in prior
2025-07-31 13:22:22 -07:00
fda949aed2 chore(versioning): switch to standard-version for automated changelog generation
This change implements standard-version for versioning and changelog management:
- Adds standard-version as a dev dependency
- Updates package.json scripts to use standard-version
- Creates .versionrc.json configuration file
- Updates CHANGELOG.md with instructions for conventional commits
- Removes obsolete manual changelog update script
2025-07-31 13:15:04 -07:00
c3c4ca31e1 **feat(storage): add pagination and filtering support for nouns and verbs**
- Introduced `PaginationOptions`, `NounFilterOptions`, and `VerbFilterOptions` types for improved query flexibility in data retrieval operations.
- Added `getNouns` and `getVerbs` methods with pagination and filtering capabilities, replacing existing methods for broader use cases and scalability.
- Marked legacy methods (`getAllNouns`, `getAllVerbs`, `getVerbsBySource`, `getVerbsByTarget`, `getVerbsByType`) as deprecated, directing users to use new methods.
- Updated `coreTypes`, `memoryStorage`, and related modules to support new functionality, including cursor and offset-based pagination handling.
- Updated fallback logic for storage adapters, ensuring compatibility with non-paginated operations when required.

**Purpose**: Enhance scalability and query precision by implementing paginated and filtered retrieval of nouns and verbs, aligning query methods with modern requirements.
2025-07-31 13:13:15 -07:00
59caa6ab5b **test(storage): add tests for S3 change log functionality**
- Introduced new test cases to validate `getChangesSince` and change log handling in `S3CompatibleStorage`.
- Verified correct logging of entity changes and retrieval based on timestamps.
- Ensured cleanup after tests to maintain test environment integrity.

**Purpose**: Strengthen test coverage for `S3CompatibleStorage` by ensuring correctness in change log functionality and timestamp-based filtering.
2025-07-31 10:22:47 -07:00
6cb26379a5 Merge remote-tracking branch 'origin/main' 2025-07-31 07:35:21 -07:00
ba1aaedd19 **fix(storage): handle additional errors in S3-compatible storage adapter**
- Updated error handling in `S3CompatibleStorage` to include checks for `NotFound` errors alongside `NoSuchKey` during lock operations.
- Ensured robustness in determining lock existence and managing exceptions related to missing keys.

**Purpose**: Improve resilience of the S3-compatible storage adapter by addressing additional error scenarios, ensuring accurate lock detection and stable operation.
2025-07-30 15:47:26 -07:00
195951e039 **chore(dependencies): remove unused dependencies**
Remove `@modelcontextprotocol/server-sequential-thinking` and its nested dependencies from `devDependencies` in `package-lock.json` as they are no longer required for the project. This reduces the overall package size and improves maintenance.
2025-07-30 14:39:13 -07:00
3c431251f8 0.27.0 2025-07-30 13:32:54 -07:00
5d82db12e2 **feat: add write-only mode support and example usage**
- Introduced `writeOnly` mode in `BrainyData` allowing optimized data ingestion by skipping index loading and disabling search operations.
- Enhanced `BrainyDataConfig` to include `writeOnly` support and validate compatibility with `readOnly` mode.
- Implemented error handling for search attempts during `writeOnly` mode.
- Updated the README with detailed usage examples for database modes, including `writeOnly` and `readOnly`.
- Added `examples/write-only-mode.js` to demonstrate practical applications of the `writeOnly` mode.

**Purpose**: Optimize memory usage and startup time for data ingestion scenarios by enabling write-only mode with comprehensive documentation and examples.
2025-07-30 13:32:30 -07:00
d70d0946cf **refactor: adjust export formatting for consistency and alignment**
- Reformatted export statements across `index.ts` and related modules for consistent style, improving code readability and maintainability.
- Updated graph types in `graphTypes.ts` to include additional standardized noun and verb categories, enhancing the flexibility of the type system for graph modeling.
- Replaced `Place` with `Location` and merged similar types (e.g., `Group` into `Collection`) to eliminate redundancy in entity definitions.
- Expanded verb types in `VerbType` to cover more comprehensive use cases, including social, temporal, and ownership relationships.

**Purpose**: Streamline code structure with consistent export formatting, simplify type definitions, and enhance the type system for broader modeling capabilities.
2025-07-30 13:18:15 -07:00
79df44351c **chore: remove outdated changelog and summary documents**
- Deleted `CHANGES.md`, `CHANGES_SUMMARY.md`, `CONCURRENCY_ANALYSIS.md`, `CONCURRENCY_IMPLEMENTATION_SUMMARY.md`, and related developer documentation files.
- Removed redundant or legacy content no longer aligned with the current codebase and workflows.
- Updated repository to reflect streamlined documentation approach, reducing clutter and improving maintainability.

**Purpose**: Simplify and declutter repository by removing obsolete documentation files, ensuring it remains focused and relevant.
2025-07-30 11:51:39 -07:00
0f2075ede4 0.26.0 2025-07-30 11:38:40 -07:00
e8127c54a5 **feat: implement robust error-handling and operation utilities for storage adapters**
- Added `BrainyError` class to classify and handle errors with types like `TIMEOUT`, `NETWORK`, `STORAGE`, `NOT_FOUND`, and `RETRY_EXHAUSTED`. Includes static helper methods for error creation and retry determination.
- Introduced `operationUtils` with utility functions for timeout, retry logic, and exponential backoff. Implements features like `withTimeout`, `withRetry`, and a combined `withTimeoutAndRetry`.
- Updated `S3CompatibleStorage` to leverage new operation utilities for timeout and retry handling, including `StorageOperationExecutors` for clean operation execution.
- Enhanced `storageFactory` to pass `OperationConfig` for configurable timeout and retry behavior.
- Extended `BrainyData` to include timeout and retry policy configuration at initialization.

**Purpose**: Improve storage reliability by introducing configurable and reusable error-handling and operation utilities, reducing code duplication and enhancing maintainability.
2025-07-30 11:35:09 -07:00
db67ccd34f **refactor: improve FileSystemStorage compatibility and remove outdated test**
- Modified `storageFactory` to ensure `FileSystemStorage` gracefully degrades to `MemoryStorage` in browser environments, with proper warnings added.
- Enhanced `opfsStorage` adapter to support recursive directory removal with the `recursive` option.
- Removed `test-fix.js` script, as it is no longer relevant with recent storage fixes and updates.

**Purpose**: Streamline and ensure cross-environment compatibility for `FileSystemStorage`, while removing outdated test artifacts for better maintainability.
2025-07-30 11:25:36 -07:00
116d6cea79 **docs: add detailed concurrency analysis and implementation documentation**
- Introduced `CONCURRENCY_ANALYSIS.md` to outline identified concurrency issues, including statistics handling, index synchronization, and storage contention.
- Added `CONCURRENCY_IMPLEMENTATION_SUMMARY.md` to summarize concurrency improvements, such as distributed locking and change log mechanisms.
- Created `STORAGE_CONCURRENCY_ANALYSIS.md` to evaluate concurrency risks and applied solutions for different storage adapters (`S3CompatibleStorage`, `FileSystemStorage`, `OPFSStorage`, and `MemoryStorage`).
- Updated codebase with changes related to concurrency, including distributed locking, atomic updates, event-driven synchronization, and change log support.
- Refactored tests to verify behavior of new concurrency mechanisms, including robust error handling and cleanup functions.

**Purpose**: Provides comprehensive documentation and implementation details to ensure robust concurrency handling in multi-instance, high-throughput environments.
2025-07-30 11:01:24 -07:00
ed2deb235b **build: update .gitignore to exclude temporary test and debug files**
- Added patterns for temporary test files (`test*.js`, `test*.ts`, `temp-test*.js`, `temp-test*.ts`, etc.) to `.gitignore`.
- Included directories `/temp/` and `/temp-tests/` to prevent accidental commits of temporary or debug-related files.

**Purpose**: Ensure cleaner version control by excluding unnecessary temporary and debug files created during development.
2025-07-30 11:01:08 -07:00
a6eeba23da **build: update test results configuration and gitignore**
- Updated test results output path in `vitest.config.ts` to `./tests/results/test-results.json` for better organization.
- Modified `.gitignore` to include `/tests/results/` and its `.json` files to avoid committing test artifacts.

**Purpose**: Improves test results file structure and ensures consistent exclusion of test artifact files from version control.
2025-07-30 10:42:18 -07:00
a8ab0c0ca9 **build: update test results file**
- Updated `test-results.json` to reflect the latest test outcomes.
- Ensures accuracy of recorded test results after recent changes.

**Purpose**: Keep test result records up-to-date for reliable tracking and reference.
2025-07-30 09:34:54 -07:00
b8847812c9 0.25.0 2025-07-28 16:25:48 -07:00
afeeb5ff28 0.24.0 2025-07-28 16:25:47 -07:00
4bb62fa386 0.23.0 2025-07-28 16:25:46 -07:00
e6d567abad 0.22.0 2025-07-28 16:25:45 -07:00
7ede52dc35 0.21.0 2025-07-28 16:25:44 -07:00
ca8774c5e1 0.20.0 2025-07-28 16:25:41 -07:00
c770b5f90e 0.19.0 2025-07-28 16:25:20 -07:00
524be5010b No commit message can be generated for the provided diff as it appears to be incomplete. Please provide a more descriptive or complete diff to enable me to generate a relevant commit message for you. 2025-07-28 16:25:11 -07:00