Hi. I just started using Vectorize this

Hi. I just started using Vectorize this week. Really liking it so far. Nice and simple. For inserting/upserting vectors using the REST API (or Typescript SDK), it would be nice if the request body could also accept an array of vector objects. When using the TS package, if I set the body value to be the ndjson string, I was getting a "failed to parse" error. I found I had to wrap the ndjson in a Buffer.from() to get it to work, but had to ignore a TS error since body is typed as a string.
1 Reply
noad.eth
noad.ethOP4w ago
Here is some example code showing what I had to do:
const body = embeddings
.map((embedding, idx) =>
JSON.stringify({
id: `${idx + 1}`,
values: embedding,
})
)
.join("\n");

const response = await client.vectorize.indexes.insert(
"example-index",
{
account_id: ACCOUNT_ID,
body: "OVERRIDDEN BELOW",
},
{ body: Buffer.from(body) }
);
const body = embeddings
.map((embedding, idx) =>
JSON.stringify({
id: `${idx + 1}`,
values: embedding,
})
)
.join("\n");

const response = await client.vectorize.indexes.insert(
"example-index",
{
account_id: ACCOUNT_ID,
body: "OVERRIDDEN BELOW",
},
{ body: Buffer.from(body) }
);

Did you find this page helpful?