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

Function toFloat32Array

vector/utils.js:18–41  ·  view source on GitHub ↗
(input, dimension)

Source from the content-addressed store, hash-verified

16}
17
18export function toFloat32Array(input, dimension) {
19 if (input === null || input === undefined) {
20 throw new Error('Vector is required.');
21 }
22
23 let data;
24 if (input instanceof Float32Array) {
25 data = input;
26 } else if (ArrayBuffer.isView(input)) {
27 data = Float32Array.from(input);
28 } else if (input instanceof ArrayBuffer) {
29 data = new Float32Array(input);
30 } else if (Array.isArray(input)) {
31 data = Float32Array.from(input);
32 } else {
33 throw new Error('Unsupported vector type.');
34 }
35
36 if (data.length !== dimension) {
37 throw new Error(`Vector dimension mismatch (expected ${dimension}, got ${data.length}).`);
38 }
39
40 return data;
41}
42
43export function prepareVector(input, dimension, normalize) {
44 const source = toFloat32Array(input, dimension);

Callers 1

prepareVectorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected