Hi, I am having issue in inserting

Hi, I am having issue in inserting vector with correct vector format, anyone else experiencing same issue, there is no error but it is returning null. Any idea
15 Replies
garvitg
garvitg•2mo ago
Hi @Utkarsh Saxena. Thanks for reaching out! Could you please share some details of the issue you are facing?
Utkarsh Saxena
Utkarsh SaxenaOP•2mo ago
@garvit this is the code block: const modelResp = await env.AI.run('@cf/baai/bge-small-en-v1.5', { text: limitedHeadings.map(heading => heading.content), }); //console.log("modelResp after inserting headings content for vectorizing : ", modelResp) const vectors: Array<VectorizeVector> = [] if (modelResp && modelResp.data) { modelResp.data.forEach((vector: number[], index: number) => { if (headings[index] && vector) { vectors.push({ id: headings[index].id, values: vector) } }) console.log("inserting vectors after processing modelResp : ", modelResp.data.length, " vectors length: ", vectors.length) } else { console.error("empty modelResp", modelResp, " headings sent to model: ", limitedHeadings); } //console.log("inserting vectors :", vectors) let vectorsInserted: VectorInserted[] = []; if (vectors.length > 0) { console.log("vectors to be inserted : ", vectors) const res = await env.VECTORIZE_INDEX_2.insert(vectors); console.log("inserted vectors :", res.count, " vectors length : ", vectors.length) if (res && res.ids) { for (let i = 0; i < res.ids.length; i++) { if (headings[i] && res.ids[i]) { vectorsInserted.push({ content_id: headings[i].content_id, vid2: res.ids[i] }) } } } } in this I am getting proper vector dimension from model, and i also checked vector array which i am inserting attached in image, still getting null after insert method without any exception or error.
No description
garvitg
garvitg•2mo ago
I was able to insert vectors by making some tweaks to the code you have provided (attached as file) Summary of the changes: 1. Fixed the syntax of the vectors.push statement: added the closing curly brace. 2. Replaced the usages of headings with limitedHeadings. 3. Created some mock data for limitedHeadings and deduced the type of VectorInserted based on the code. 4. Ensured that the index bound to the worker contains 384 dimensions to match the output vector size of the @cf/baai/bge-small-en-v1.5 model.
garvitg
garvitg•2mo ago
Recommendations: 1. I noticed that you are using a Vectorize V1 index while analyzing the code. We recommend that you transition to a Vectorize V2 index: https://developers.cloudflare.com/vectorize/reference/transition-vectorize-legacy/ to receive the added scalability and performance benefits. V1 indexes are on a deprecation path. 2. We recommend the use of Worker logs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/ for additional insights and debugging ability into any issues related to your worker's functionality.
Cloudflare Docs
Transition legacy Vectorize indexes · Vectorize
Legacy Vectorize (V1) indexes are on a deprecation path as of Aug 15, 2024. Your Vectorize index may be a legacy index if it fulfills any of the follwing crieria:
Cloudflare Docs
Workers Logs · Cloudflare Workers docs
Store, filter, and analyze log data emitted from Cloudflare Workers.
Utkarsh Saxena
Utkarsh SaxenaOP•2mo ago
I tried the code, actually it was some typo in my last code which i sent here, i fixed all issue of code, still getting null after inserting vectors, vectors are well structured in log before insert step, still null.
No description
No description
garvitg
garvitg•2mo ago
I am able to use the code I shared above to insert vectors successfully (check the attached image). Could you please share the index and the account you are using over DM? Also, are you able to query vectors? Since you are using the insert command (and not upsert) there is a chance that the vectors are already present in your index and a subsequent attempt to insert the same vectors could result in a null response. But you will be able to get results if you try to query the index and if there are any vectors present in the index.
No description
San
San•2mo ago
Utkarsh sent you the details over DM. The index is v2, it has 365k vectors stored, and the limit per index is 500k. read query works fine, the issue is only with insert.
garvitg
garvitg•2mo ago
Well that probably explains it. Please use the Vectorize interface for V2 indexes and not VectorizeIndex interface (which is used for V1 indexes). For V2 indexes, inserts would not work if you use the VectorizeIndex interface. Also, there are no res.count or res.ids fields for V2 indexes, since insertions are asynchronous. Please define your worker environment as:
export interface Env {
VECTORIZE_INDEX_2: Vectorize;
}
export interface Env {
VECTORIZE_INDEX_2: Vectorize;
}
For more details about the transition from V1 to V2 indexes, please refer to https://developers.cloudflare.com/vectorize/reference/transition-vectorize-legacy/.
Cloudflare Docs
Transition legacy Vectorize indexes · Vectorize
Legacy Vectorize (V1) indexes are on a deprecation path as of Aug 15, 2024. Your Vectorize index may be a legacy index if it fulfills any of the follwing crieria:
San
San•2mo ago
thanks, let me try out and confirm
Utkarsh Saxena
Utkarsh SaxenaOP•2mo ago
Thanks, Garvit it started working.
garvitg
garvitg•2mo ago
Happy to help! 🙂
Utkarsh Saxena
Utkarsh SaxenaOP•2mo ago
Hi, @garvitg the issue still persist, on insertion of vector, insert method is returning mutationID successfully, but when i am querying the vectorDB for same vectorID, it is giving null.
No description
Utkarsh Saxena
Utkarsh SaxenaOP•2mo ago
I queried the index info using endpoint: curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/vectorize/v2/indexes/$INDEX_NAME/info \ -H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ -H "X-Auth-Key: $CLOUDFLARE_API_KEY" and got this as response: image attached, here you can see: "processedUpToDatetime":"2024-12-05T09:44:56.497Z" is too old, why is that too old? and i also tried inserting vectors directly through api endpoint and got mutation id successfully but no change in vector index count or anything:
No description
No description
garvitg
garvitg•2mo ago
Hi @Utkarsh Saxena, the processedUpToDatetime value for your index does seem a bit unexpected and I can help look into that. Could you please DM the name of your index and the account id you are using?
San
San•2mo ago
The details are the same as those we sent you last time. you can check DM from Utkarsh for the details.

Did you find this page helpful?