- **Removed Files**:
- Deleted outdated statistics documentation files (`statistics.md`, `statistics-flush-solution.md`, `statistics-summary.md`) to clean up the repository and avoid confusion.
- **Added Standards**:
- Introduced `DOCUMENTATION_STANDARDS.md` to outline naming conventions and troubleshooting practices for more consistent and maintainable project documentation.
- **Tests**:
- Added a new test file `edge-cases.test.ts` to verify handling of edge cases, ensuring robust behavior against boundary values and invalid inputs.
**Purpose**: Cleans up deprecated documentation while introducing concrete standards for maintaining and updating documentation. Enhances test coverage for unusual or boundary inputs, improving overall system resilience.
- **Integration Tests**:
- Introduced `api-integration.test.ts` to validate API functionality:
- Verifies text insertion, vector embedding generation, and search operations.
- Confirms HNSW index correctness for vector similarity search.
- Ensures no dimensional mismatches in embeddings.
- **Test Server**:
- Added test server utilizing Express for endpoint simulation (`/insert` and `/search/text`).
- **Dependencies**:
- Introduced `express` and `node-fetch` as new dependencies for testing purposes.
- **Vitest Fix**:
- Updated `vitest.config.ts` to resolve the `process.memoryUsage` error by setting `logHeapUsage: false`.
- **Package Updates**:
- Modified `package-lock.json` to include newly added dependencies and updates.
**Purpose**: Guarantees the stability of core API endpoints and vector-related functionality, ensuring reliable behavior for end-to-end scenarios.
- **Core**:
- Removed the `dimensions` property from `BrainyData` initialization in `server.ts` as it was unused and redundant.
- Simplified code structure and reduced potential confusion by avoiding unnecessary arguments in object initialization.
**Purpose**: Improve code clarity and maintainability by removing unused properties from the `BrainyData` setup, aligning with standardized dimension handling approaches.
- **Tests**:
- Introduced `database-operations.test.ts` to validate core database functionalities, including initialization, CRUD operations, statistics retrieval, and search capabilities.
- Added `dimension-standardization.test.ts` to ensure vector dimension consistency (fixed at 512) throughout operations like embedding, configuration, and validation.
- Enhanced test cases to include scenarios for adding, retrieving, and handling errors for incorrect vector dimensions.
- **Documentation**:
- Created `VECTOR_DIMENSION_STANDARDIZATION.md` to detail the transition to standardizing vectors to 512 dimensions, rationale for the change, potential impacts, and migration steps.
- Includes best practices for handling vectors and utilizing the built-in embedding functions.
**Purpose**: Improve system robustness with comprehensive test coverage focusing on critical database and vector operations while providing clear documentation for developers to adapt to the standardized vector dimensions.
- **Core**:
- Added `check-database.js` to verify database status and validate search functionality.
- Created `fix-dimension-mismatch.js` to handle re-embedding of existing data to resolve dimension mismatch from 3 to 512.
- Improved test cases by updating vector operations to support 512 dimensions, replacing previously hardcoded dimensions.
- **Migration**:
- Developed `DIMENSION_MISMATCH_SUMMARY.md`, detailing the root cause, solution, and preventive strategies for dimension mismatch issues.
- Added `production-migration-guide.md` for structured production migration with detailed steps on re-embedding strategies, batching, and error handling.
- **Tests**:
- Enhanced test coverage with 512-dimensional vector validation.
- Introduced helper functions for consistent vector testing behavior and streamlined search test cases.
- **Documentation**:
- Updated project documentation to highlight the resolution process for dimension mismatches, emphasizing preventive mechanisms such as auto-migration and version tracking.
**Purpose**: Address critical dimension mismatch issues caused by embedding changes, restore functionality, and provide a roadmap for robust prevention strategies and migration processes.
- **Storage**: Replaced all instances of `HNSWNoun_internal` and `Verb` type aliases with their original equivalents (`HNSWNoun` and `GraphVerb`) in `MemoryStorage` adapter. Simplified method definitions and internal logic by directly using the original types.
- **Code Cleanup**:
- Removed unused type alias declarations to reduce code clutter and improve readability.
- Adjusted method parameters and return types accordingly to maintain consistency.
**Purpose**: Simplify the codebase by removing redundant type aliasing, ensuring consistency and better readability across storage adapter logic. Reduces potential confusion and streamlines type usage.
- **Examples**: Added a new `flush-statistics-example.js` script to demonstrate the usage of the `flushStatistics` method for ensuring updated statistics after data insertion.
- **Core**:
- Implemented `flushStatistics` in the `BrainyData` class to allow immediate flushing of statistics to storage.
- Updated `BaseStorageAdapter` with `flushStatisticsToStorage` to support flushing cached statistics.
- Modified the `shutDown` method to ensure statistics are flushed before database shutdown.
- **Documentation**: Added `statistics-flush-solution.md` to explain the batch update mechanism, the issue with delayed statistics updates, and how to manually flush statistics in storage.
**Purpose**: Provide users with the ability to manually flush statistics for real-time accuracy, particularly useful for systems relying on immediate updates. Improved documentation and examples to guide developers in implementing and using this functionality effectively.
- **Documentation**: Added a new `statistics-summary.md` file detailing how statistics are tracked, updated, and stored within the system. Includes examples of API usage, implementation details, and consumer use cases.
- **Purpose**: Provide clear guidance for developers and stakeholders on the statistics system's functionality, including real-time updates, service-specific breakdowns, and persistent storage mechanisms. Aids in understanding and leveraging the system effectively.
- **Core**: Improved verb creation logic by adding `createdAt`, `updatedAt`, and `createdBy` attributes. These fields include timestamped metadata (`seconds`, `nanoseconds`) and source augmentation/service information for better tracking.
- **Storage**: Refactored `BaseStorage` methods to utilize internal variants (e.g., `saveVerb_internal`, `getNoun_internal`). Added support for new verb attributes while maintaining backward compatibility with existing data structures.
- **Tests**:
- Updated `s3-storage.test.ts` and `opfs-storage.test.ts` to validate changes in verb attributes such as timestamps and augmentation metadata.
- Added assertions for `createdAt`, `updatedAt`, and `createdBy` fields in test cases.
- **Cleanup**: Replaced ambiguous type aliases like `Edge` and `HNSWNode` with clearer equivalents (`Verb` and `HNSWNoun_internal`) for consistency across storage adapters.
**Purpose**: Enhance metadata tracking and standardize attribute handling across storage and core modules to ensure accurate and consistent data throughout the system.
- **Code Cleanup**: Removed unnecessary trailing whitespaces across `src/brainyData.ts`. Adjusted formatting for inline object spreads to maintain a consistent coding style.
- **Purpose**: Enhance code readability and ensure adherence to formatting standards without altering functionality.
- **Tests**: Added new `statistics-storage.test.ts` to validate statistics storage functionality across scenarios including saving, retrieving, time-based partitioning, and backward compatibility. Ensured tests dynamically handle missing environment variables by skipping S3-related tests when credentials are unavailable.
- **Docs**: Enhanced `statistics.md` with detailed explanations of scalability improvements, including adaptive flush timing, batched updates, and time-based partitioning. Improved readability and structure.
- **Storage**: Updated all storage adapters to integrate time-based partitioning and maintain backward compatibility with legacy statistics storage formats.
- **Dependencies**: Added `dotenv` to support environmental variable management for storage adapter tests.
**Purpose**: Strengthen system reliability by adding comprehensive test coverage for statistics storage, improve scalability documentation, and ensure consistency across storage adapters with robust implementations.
- **Core**: Introduced a `getCurrentAugmentation` method for detecting active augmentation names. Updated metadata handling to include `createdBy`, `createdAt`, and `updatedAt` attributes for improved tracking.
- **Storage**: Added support for service-based statistics tracking with new methods such as `incrementStatistic`, `decrementStatistic`, and `updateHnswIndexSize`. Implemented persistence for statistics in storage adapters.
- **Statistics**: Enhanced `getStatistics` functionality to provide service-specific breakdowns and support filtering by services. Improved noun, verb, and metadata tracking mechanisms.
- **Search**: Added `service` option to filter results during searches for nouns, verbs, and metadata, ensuring accurate service-based query results.
- **Refactor**: Simplified search logic by integrating HNSW index filtering for better performance when retrieving service-specific results.
- **Tests**: Added comprehensive test coverage for service-level statistics and filtering by service.
**Purpose**: Improve service-level data tracking and analytics while enhancing functionality for filtering and maintaining metadata accuracy to support detailed insights for diverse use cases.
- **Removal**: Deleted `FileSystemStorage` and `OPFSStorage` adapters from the `/storage` directory.
- **Refactor**: Simplifies the codebase by eliminating unused, redundant, or outdated storage implementations.
- **Impact**: Ensures maintainability by focusing on actively supported storage solutions.
**Purpose**: Streamline the project by removing deprecated or unused storage adapters, reducing complexity and maintenance overhead.
- **Core**: Enhanced `getStatistics` function to support `service` and `service[]` filters, enabling statistics breakdown by service. Modified return structure to include `serviceBreakdown` for detailed insights.
- **Storage**: Implemented a new `BaseStorageAdapter` abstract class to centralize statistics-related functionality, such as incrementing/decrementing counters and updating HNSW index size. Refactored all storage adapters (`FileSystemStorage`, `S3CompatibleStorage`, `MemoryStorage`, `OPFSStorage`) to extend `BaseStorageAdapter`, ensuring consistent statistics tracking.
- **Tests**: Added new test cases in `statistics.test.ts` to validate service-level statistics tracking, breakdown accuracy, and multi-service filtering.
**Purpose**: Improve insight into data trends by tracking service-specific usage in statistics. Enhance maintainability and consistency through storage adapter centralization and robust testing.
- Updated `tsconfig.unified.json`, `tsconfig.browser.json`, and `tsconfig.json` to include `"DOM.Asynciterable"` in the `lib` option.
- Ensured compatibility with asynchronous iteration patterns in DOM APIs.
**Purpose**: Enable support for DOM asynchronous iterable utilities, improving compatibility with modern TypeScript and DOM usage scenarios.
- **Storage**: Removed redundant storage implementation files from `/storage` directory while retaining necessary `baseStorage.ts`. Verified no impact on functionality with passing tests.
- **Documentation**: Consolidated multiple overlapping `.md` files into a single `statistics.md` file. Added structured sections for easier reference. Applied markdown naming conventions for clarity.
- **Project**: Introduced `CHANGES_SUMMARY.md` and `MARKDOWN_CONVENTIONS.md` to document changes and naming guidelines, improving project organization. Updated `demo.md` file naming for consistency.
**Purpose**: Simplify the codebase by removing duplicates, enhance maintainability through consolidated and structured documentation, and improve developer experience with clear guidelines and better organization.
- **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.
- **New Method**:
- Introduced a new `getStatistics` method in `brainyData.ts` to retrieve key database metrics:
- Counts for nouns, verbs, metadata entries, and HNSW index size.
- **Error Handling**:
- Added try-catch blocks to ensure robust error management when fetching metadata or logging failures.
- **Purpose**:
- Enhances observability of the database state, providing valuable insights for diagnostics and monitoring.
- Updated version to `0.18.0` in `cli-package/package.json` and `package-lock.json`.
- Upgraded `@soulcraft/brainy` dependency to `^0.17.0` for compatibility with recent changes.
- Synced package dependencies and resolved lockfile integrity for deployment.
**Purpose**: Prepare for release by synchronizing versioning across the CLI package and updating dependencies for compatibility.
- Added `autoCreateMissingNouns` and `missingNounMetadata` options to the `addVerb` method in `brainyData.ts`, enabling automatic creation of missing source or target nouns.
- Improved error handling and logging for auto-creation failures, ensuring better feedback during runtime.
- Reformatted existing code for storage options validation to improve readability and maintain consistency.
**Purpose**: Simplify the addition of relationships by automating the process for non-existing nouns and enhance developer experience with better error handling and logging.
- **Version Updates**:
- Updated `web-service-package/package.json` and `package-lock.json` from `0.15.0` to `0.16.0`.
- Updated `cli-package/package.json` and `package-lock.json` from `0.16.0` to `0.17.0`.
- **Purpose**:
- Prepares both packages for their respective new releases, ensuring version consistency across project dependencies.
- **Changes**:
- Eliminated the redundant `@ts-expect-error` comment for the `omelette` import in `cli.ts`.
- **Purpose**:
- Simplifies the code by removing an outdated comment that is no longer needed, ensuring cleaner and more readable source files.
- **Version Updates**:
- Updated `cli-package/package.json` and `package-lock.json` from `0.15.0` to `0.16.0`.
- **NPM Script Enhancements**:
- Added version-related scripts (`version`, `version:patch`, `version:minor`, `version:major`) to `web-service-package` and `cli-package`.
- Introduced `deploy` and `dry-run` scripts to streamline build and deployment workflows.
- **Script Cleanup**:
- Removed redundant `build:cli`, `deploy:cli`, and `deploy:web-service` scripts from the root `package.json`.
**Purpose**: Prepares for release 0.16.0 while introducing reusable and optimized build/release scripts, improving the development and deployment experience.
- **Removal of `generate-version.js`**:
- Deleted `scripts/generate-version.js` as it is no longer required for version handling.
- Removed associated output files, including `src/utils/version.ts`.
- **Prebuild and Version Process Updates**:
- Updated `prebuild` and `version` scripts in `package.json` to reflect the new workflow:
- Replaced `generate-version.js` with simplified echo commands for version updates and build steps.
- Adjusted deployment scripts (`deploy:cli` and `deploy:web-service`) to align with the removal of the script.
- **Documentation and Config Updates**:
- Cleaned up `README.md` by removing unused version badge references.
- Updated `cli-package/package.json` to specify a version range (`^0.15.0`) for `@soulcraft/brainy`.
**Purpose**: This refactor simplifies the version handling process by removing outdated scripts, reducing maintenance overhead, and aligning workflows with project conventions. Improves clarity and consistency in both configuration and documentation.
- **Cloud Storage Integration Testing**:
- Added `cloud-storage.test.ts` to validate cloud storage configurations (AWS S3, Cloudflare R2, Google Cloud Storage) and local storage fallback behavior:
- Includes tests for environment variable priority and configuration detection.
- Ensures proper override with `FORCE_LOCAL_STORAGE` when specified.
- **Package Settings Updates**:
- Introduced `web-service-package/package.json` with configurations for building, running, testing, and deployment:
- Added NPM scripts for building (`npm run build`), development (`npm run dev`), and testing (`npm run test:cloud`).
- Configured dependencies and devDependencies for web service functionality and cloud integration.
- **Purpose**:
- This update ensures comprehensive cloud storage testing and provides structured project configurations for seamless development and deployment workflows.
- **New Web Service Package**:
- Introduced `@soulcraft/brainy-web-service`, a REST API wrapper for the Brainy vector graph database.
- Added documentation and features to support secure, read-only search and retrieval operations.
- **Deployment Support**:
- Included comprehensive deployment instructions in the `web-service-package/README.md`:
- Options for Docker, serverless platforms, and cloud providers (AWS, GCP, Azure, Cloudflare).
- Example configurations for systemd, Nginx, and Docker Compose.
- **Scripts and Documentation Updates**:
- Added `deploy:web-service` script to `package.json` for streamlined build and publishing.
- Enhanced `README.md` to reflect the introduction of the web service package and its capabilities.
- **Purpose**:
- This update extends Brainy’s functionality by providing a production-ready, easy-to-deploy REST API for search operations. It ensures flexibility for diverse deployment scenarios while maintaining security and high performance.
- Updated `VERSION` in `version.ts` to `0.15.0`.
- Updated `npm` badge in `README.md` to reflect version `0.15.0`.
- Updated `version` field and dependency reference in `cli-package/package.json` to `0.15.0`.
**Purpose**: Prepare for release by synchronizing version across source files, documentation, and package dependencies.
- Updated all imports and exports in `src/index.ts` and `src/storage/storageFactory.ts` to use a consistent formatting style.
- Enhanced readability by standardizing spacing, alignment, and indentation across the codebase.
- Applied consistent import/export styling for structured comments and multi-line objects.
**Purpose**: Improve code maintainability and readability by enforcing uniform formatting, aligning imports and exports for better clarity.
- Introduced comprehensive mock for the Origin Private File System (OPFS) in `tests/mocks/opfs-mock.ts`, simulating environment for detailed storage testing.
- Added `tests/opfs-storage.test.ts`, containing extensive test cases for `OPFSStorage` operations including metadata, nouns, verbs, and storage status.
- Improved S3 mock implementation in `tests/mocks/s3-mock.ts` with better object persistence, validation, and logging to emulate real S3 behavior.
- Resolved issues related to metadata, nouns, verbs, and storage usage inconsistencies in mock storage adapters.
- Enhanced logging and error handling to aid in debugging and test reliability.
Purpose: Improve test completeness and reliability by introducing detailed mocks and extended test cases for S3 and OPFS storage systems.
- Added `getFile` method to `FileSystemHandle` interface for enhanced TypeScript compatibility with File System Access API.
- Improved maintainability by reformatting and aligning imports in `brainyData.ts`.
- Standardized spacing and indentation across structured comments and interface fields.
Purpose: Improve TypeScript support for file system operations and enhance code readability with consistent formatting and import management.
- Documented the use of a simplified, unified storage structure for all noun types.
- Enhanced storage system explanation to reflect recent architectural improvements.
Purpose: Improve developer understanding of the storage system by updating documentation with the latest features and design changes.
- Removed outdated test files: `test-tensorflow-import.cjs`, `test-tensorflow-import.js`, and `verify-package-size.js`.
- Introduced `tests/package-size-breakdown.test.ts` to analyze included npm package files and validate their sizes.
- Added comprehensive tests for storage adapters (`MemoryStorage`, `FileSystemStorage`, `OPFSStorage`, etc.) in `tests/storage-adapters.test.ts`.
- Improved OPFS storage mocking and test coverage for browser and Node.js environments.
- Introduced environment detection tests to ensure correct storage adapter selection.
- Created `STORAGE_TESTING.md` to document storage architecture, test coverage, and guidelines for further improvements.
Purpose: Modernize testing infrastructure and enhance storage system reliability through better test coverage and documentation.
- Added `BaseStorage` abstract class to provide common functionality for storage adapters.
- Implemented `FileSystemStorage` adapter for Node.js environments, supporting persistent file-based storage.
- Added directory structure management methods to `FileSystemStorage` (`ensureDirectoryExists`, `clear`, etc.).
- Implemented `MemoryStorage` adapter for in-memory storage suitable for non-persistent environments.
- Supported CRUD operations for nouns, verbs, and metadata in both `FileSystemStorage` and `MemoryStorage`.
- Included utility methods like `mapToObject` for serialization and deserialization of complex data structures.
Purpose: Provide extensible, reusable storage solutions with both persistent and non-persistent options for diverse application needs.
- Documented various WebSocket augmentation types (`IWebSocketSupport`, `IWebSocketSenseAugmentation`, etc.) to guide developers in extending augmentations with WebSocket capabilities.
- Added code example showcasing the creation of a WebSocket-enabled sense augmentation (`mySenseAug`) using `addWebSocketSupport`.
- Explained the purpose of combining base augmentation interfaces with `IWebSocketSupport` for type safety and autocompletion.
Purpose: Enhance developer documentation by providing clear guidance and examples for integrating WebSocket capabilities into augmentations.