MCPcopy Create free account
hub / github.com/OpenAnonymity/oa-chat / decodeBase64ToFloat32

Function decodeBase64ToFloat32

embeddings/utils.js:1–16  ·  view source on GitHub ↗
(base64)

Source from the content-addressed store, hash-verified

1function 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
18function coerceEmbedding(item) {
19 if (!item) return new Float32Array();

Callers 1

coerceEmbeddingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected