feat(src/utils): add GPU acceleration and improve threading for embeddings and distance calculations
- Integrated GPU acceleration via WebGL in `embedding.ts` and `distance.ts` for optimized performance. - Enhanced fallback mechanisms for CPU processing when GPU is unavailable or fails to initialize. - Added threading support for embedding and distance calculations in `embedding.ts` and `distance.ts` to improve performance and avoid blocking the main thread. - Refactored TensorFlow.js imports to dynamically load modules (`@tensorflow/tfjs-core`, `@tensorflow/tfjs-backend-webgl`, `@tensorflow/tfjs-backend-cpu`) for modular dependency usage. - Introduced GPU-accelerated batch distance calculations in `distance.ts` with appropriate error handling. - Applied consistent formatting to improve code readability and maintainability while adhering to project style guidelines.
This commit is contained in:
parent
bd123c4bb9
commit
6a8d044970
3 changed files with 348 additions and 65 deletions
|
|
@ -20,6 +20,18 @@ export function executeInWebWorker<T>(fnString: string, args: any): Promise<T> {
|
|||
self.index = {}
|
||||
self.index$1 = {}
|
||||
self.index$2 = {}
|
||||
self.universalSentenceEncoder_esm = {}
|
||||
self.universalSentenceEncoder = {}
|
||||
self.tfjs = {}
|
||||
self.tfjs_core = {}
|
||||
self.tfjs_backend_cpu = {}
|
||||
self.tfjs_backend_webgl = {}
|
||||
|
||||
// Additional variables that might be generated by bundlers
|
||||
self.use = {}
|
||||
self.tf = {}
|
||||
self.sentenceEncoder = {}
|
||||
self.sentenceEncoderModule = {}
|
||||
|
||||
self.onmessage = async function(e) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue