Hi, I'm getting this error when I try to upsert my document embeddings..."The argument to upsert had type errors: item at index 0 of the 'values' array must be number". Please could anyone take a look at it

Here is the code that is performing the embedding and the upserting:

const updatePineconeVectorStore = async (client, indexName, docs, embeddings) => {
    const index = client.Index(indexName);
    const splitter = new RecursiveCharacterTextSplitter();
    const queue = [];

    try {
        const splitDocs = await splitter.splitDocuments(docs);

        // Loop over splitDocs and enqueue each splitDoc into a queue
        for (let splitDoc of splitDocs) {
            queue.push(splitDoc);
        }

        const batchSize = 6;

        while (queue.length > 0) {
            //Extract a batch of document from the queue
            const batch = queue.slice(0, batchSize);

            //Construct vector and perform upsert operations for the current batch
            const vectors = await Promise.all(batch.map(async (splitDoc, idx) => {
                const splitDocEmbeddings = await embeddings.embedDocuments(
                    splitDoc.pageContent.replace(/\n/g, " ").split(",")
                );

                return {
                    id: `${splitDoc.metadata.source}_${idx}`,
                    values: splitDocEmbeddings,
                    metadata: {
                        ...splitDoc.metadata,
                    },
                };
            }));

            await index.upsert(vectors);

            console.log(`Processed batch of ${batch.length} documents. Remaining queue size: ${queue.length}`);
        }
    } catch (err) {
        console.error("Error occurred during document processing:", err.message);
    }
};

Here is how one of the documents objects in the vectors array looks like:
ar

Hi there, the values parameter expects an array of numbers like:

values: [0.1, 0.2, 0.3, ...]

but looks like you’re passing an array that contains an array, like:

values: [ [ 0.1, 0.2, 0.3, ...] ]

Hope this helps.

1 Like

ohh… thanks that did it.

1 Like

@luwaservices, glad to hear that

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.