Hi @nukely. Thank you for reaching out!
I am able to repro the error that you have mentioned and we will be investigating the cloudflare-ts package. I initially suspected that formatting the request body as an ndjson string would suffice, but it did not.
In the meantime, you could insert vectors by calling the HTTP APIs directly from your ts project using logic that looks like:
const embeddings = [
{
id: "med1",
values: [
0.12, 0.45, 0.67, 0.89, 0.23, 0.56, 0.34, 0.78, 0.12, 0.9, 0.24, 0.67, 0.89, 0.35, 0.48, 0.7, 0.22, 0.58, 0.74, 0.33, 0.88, 0.27, 0.81, 0.54, 0.39, 0.76, 0.41, 0.29, 0.83, 0.55, 0.56, 0.6,
],
metadata: {
userId: "rakesh",
data: "Likes going to hikes",
hash: "4478e7d1c435ece797e7a17b82c5d776",
},
},
{
id: "med2",
values: [
-0.12, 0.45, 0.67, 0.89, 0.23, 0.56, 0.34, 0.78, 0.12, 0.9, 0.24, 0.67, 0.89, 0.35, 0.48, 0.7, 0.22, 0.58, 0.74, 0.33, 0.88, 0.27, 0.81, 0.54, 0.39, 0.76, 0.41, 0.29, 0.83, 0.55, 0.56, -0.6,
],
metadata: {
userId: "rakesh2",
data: "Likes going to treks",
hash: "4478e7d1c435ece797e7a17b82c5d3932",
},
},
];
const ndjsonBody = embeddings.map((ojs) => JSON.stringify(ojs)).join("\n");
const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${account_id}/vectorize/v2/indexes/${index_name}/insert`,
{
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/x-ndjson",
},
body: ndjsonBody,
}
);
const text = await response.text();
if (!response.ok) {
console.error(`Failed with ${response.status}:`, text);
throw new Error(text);
}
console.log(`Success:`, text);
const embeddings = [
{
id: "med1",
values: [
0.12, 0.45, 0.67, 0.89, 0.23, 0.56, 0.34, 0.78, 0.12, 0.9, 0.24, 0.67, 0.89, 0.35, 0.48, 0.7, 0.22, 0.58, 0.74, 0.33, 0.88, 0.27, 0.81, 0.54, 0.39, 0.76, 0.41, 0.29, 0.83, 0.55, 0.56, 0.6,
],
metadata: {
userId: "rakesh",
data: "Likes going to hikes",
hash: "4478e7d1c435ece797e7a17b82c5d776",
},
},
{
id: "med2",
values: [
-0.12, 0.45, 0.67, 0.89, 0.23, 0.56, 0.34, 0.78, 0.12, 0.9, 0.24, 0.67, 0.89, 0.35, 0.48, 0.7, 0.22, 0.58, 0.74, 0.33, 0.88, 0.27, 0.81, 0.54, 0.39, 0.76, 0.41, 0.29, 0.83, 0.55, 0.56, -0.6,
],
metadata: {
userId: "rakesh2",
data: "Likes going to treks",
hash: "4478e7d1c435ece797e7a17b82c5d3932",
},
},
];
const ndjsonBody = embeddings.map((ojs) => JSON.stringify(ojs)).join("\n");
const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${account_id}/vectorize/v2/indexes/${index_name}/insert`,
{
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/x-ndjson",
},
body: ndjsonBody,
}
);
const text = await response.text();
if (!response.ok) {
console.error(`Failed with ${response.status}:`, text);
throw new Error(text);
}
console.log(`Success:`, text);