pinecone-io / pinecone-vercel-starter

Pinecone + Vercel AI SDK Starter
https://pinecone-vercel-example.vercel.app
418 stars 127 forks source link

Update chunkedUpsert.ts #28

Open Yackadaisical opened 9 months ago

Yackadaisical commented 9 months ago

The chunkedUpsert function is designed to split an array of PineconeRecord vectors into smaller chunks and upsert (insert or update) each chunk into a Pinecone index. It uses the sliceIntoChunks helper function to create the chunks based on the specified chunkSize.

Problem

Using current code with large files will run into this error:

Error upserting chunk [PineconeBadRequestError: Request size 3MB exceeds the maximum supported size of 2MB] { name: 'PineconeBadRequestError', cause: undefined

Solution

There is a bug in the chunkedUpsert function. Inside the map callback, it should be upserting the chunk rather than the entire vectors array. This is likely the reason why the request size is exceeding the limit, as it's attempting to upsert the entire array of vectors in each iteration instead of just the chunk.

Type of Change