| 1 | function decodeBase64ToFloat32(base64) { |
| 2 | if (typeof base64 !== 'string' || base64.length === 0) return null; |
| 3 | if (typeof globalThis.atob === 'function') { |
| 4 | const binary = globalThis.atob(base64); |
| 5 | const bytes = new Uint8Array(binary.length); |
| 6 | for (let i = 0; i < binary.length; i += 1) { |
| 7 | bytes[i] = binary.charCodeAt(i); |
| 8 | } |
| 9 | return new Float32Array(bytes.buffer, bytes.byteOffset, Math.floor(bytes.byteLength / 4)); |
| 10 | } |
| 11 | if (typeof Buffer !== 'undefined') { |
| 12 | const buffer = Buffer.from(base64, 'base64'); |
| 13 | return new Float32Array(buffer.buffer, buffer.byteOffset, Math.floor(buffer.byteLength / 4)); |
| 14 | } |
| 15 | return null; |
| 16 | } |
| 17 | |
| 18 | function coerceEmbedding(item) { |
| 19 | if (!item) return new Float32Array(); |