**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.
This commit is contained in:
parent
8c5251e4dd
commit
8e7cc6af3a
6 changed files with 585 additions and 106 deletions
97
TESTING.md
Normal file
97
TESTING.md
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
# Testing Brainy Across Different Environments
|
||||
|
||||
This document provides instructions for testing Brainy's cache detection functionality across different environments.
|
||||
|
||||
## Testing in Node.js Environment
|
||||
|
||||
To test Brainy in a Node.js environment:
|
||||
|
||||
1. Build the project:
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
2. Run the Node.js test script:
|
||||
```bash
|
||||
node test-cache-detection.js
|
||||
```
|
||||
|
||||
3. Expected output:
|
||||
```
|
||||
Brainy: Successfully patched TensorFlow.js PlatformNode at module load time
|
||||
Applied TensorFlow.js patch via ES modules in setup.ts
|
||||
Brainy running in Node.js environment
|
||||
Creating BrainyData instance...
|
||||
BrainyData instance created successfully!
|
||||
Test completed successfully!
|
||||
```
|
||||
|
||||
## Testing in Browser Environment
|
||||
|
||||
To test Brainy in a browser environment:
|
||||
|
||||
1. Build the project:
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
2. Start a local web server:
|
||||
```bash
|
||||
npx http-server -p 8080
|
||||
```
|
||||
|
||||
3. Open the browser test page:
|
||||
```
|
||||
http://localhost:8080/test-browser-cache-detection.html
|
||||
```
|
||||
|
||||
4. Click the "Run Test" button on the page.
|
||||
|
||||
5. Expected results:
|
||||
- The page should display success messages
|
||||
- No errors should appear in the browser console
|
||||
- You should see "BrainyData instance created successfully!" and "Test completed successfully!"
|
||||
|
||||
## Testing in Web Worker Environment
|
||||
|
||||
To test Brainy in a Web Worker environment:
|
||||
|
||||
1. Build the project:
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
2. Start a local web server:
|
||||
```bash
|
||||
npx http-server -p 8080
|
||||
```
|
||||
|
||||
3. Open the worker test page:
|
||||
```
|
||||
http://localhost:8080/test-worker-cache-detection.html
|
||||
```
|
||||
|
||||
4. Click the "Run Test" button on the page.
|
||||
|
||||
5. Expected results:
|
||||
- The page should display success messages from the worker
|
||||
- No errors should appear in the browser console
|
||||
- You should see "BrainyData instance created successfully!" and "Test completed successfully!"
|
||||
|
||||
## Compatibility Notes
|
||||
|
||||
Brainy's cache detection has been designed to work across all environments:
|
||||
|
||||
1. **Node.js Environment**:
|
||||
- Uses fixed default memory values (8GB total, 4GB free) for cache size calculation
|
||||
- This approach ensures compatibility with ES modules
|
||||
|
||||
2. **Browser Environment**:
|
||||
- Uses navigator.deviceMemory API when available
|
||||
- Falls back to conservative defaults when the API is not available
|
||||
|
||||
3. **Worker Environment**:
|
||||
- Uses a more conservative approach to cache sizing
|
||||
- Automatically detects the worker environment and adjusts accordingly
|
||||
|
||||
The cache manager automatically detects the environment and adjusts its behavior to ensure optimal performance in each context.
|
||||
Loading…
Add table
Add a link
Reference in a new issue