Need help with Embeddings - TypeError: records.forEach is not a function

I could use some help here, I’m using the following versions:

  • NodeJS (v20.11.0)
  • @pinecone-database/pinecone": “^3.0.2”
  • OpenAI model text-embedding-ada-002

Error:

Error during embedding generation: TypeError: records.forEach is not a function

Code: embeddingController.js

const axios = require('axios');
const { Pinecone } = require('@pinecone-database/pinecone');
const { v4: uuidv4 } = require('uuid'); // Use UUID for unique IDs

(async () => {
  const fetch = (await import('node-fetch')).default;
  global.fetch = fetch; // Resolve fetch implementation warning
})();

// Initialize Pinecone client
const pinecone = new Pinecone({
    apiKey: process.env.PINECONE_API_KEY,
  });

  exports.generateEmbedding = async (req, res) => {
    const { text } = req.body;
  
    try {
      // Generate embedding from OpenAI API
      const response = await axios.post(
        'https://api.openai.com/v1/embeddings',
        {
          model: 'text-embedding-ada-002',
          input: text,
        },
        {
          headers: {
            Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
          },
        }
      );
  
      const embeddings = response.data.data;
      if (!Array.isArray(embeddings) || embeddings.length === 0) {
        throw new Error('Invalid embedding response from OpenAI API');
      }
  
      const embedding = embeddings[0].embedding;
      console.log('Length of the embedding:', embedding.length);
  
      // Check if the embedding dimension matches the required length for Pinecone
      if (embedding.length !== 1536) {
        throw new Error('Embedding dimension mismatch: Expected 1536.');
      }
  
      // Assign a unique ID to the vector
      const uniqueId = uuidv4();
  
      // Construct the vector to be upserted
      const vector = {
        id: uniqueId,
        values: embedding,
        metadata: { text: text }  // Store the original text as metadata
      };
  
      // Initialize the Pinecone index
      const index = pinecone.Index('secret');
  
      // Prepare the payload for upsert
      const upsertPayload = {
        vectors: [vector]  // Pass the vector in an array as required by Pinecone
      };
  
      // Log the payload before upserting
      console.log('Upsert payload:', upsertPayload);
  
      // Perform the upsert operation
      await index.upsert(upsertPayload);
  
      res.status(200).send({ message: 'Embedding generated and stored successfully.', id: uniqueId });
    } catch (error) {
      console.error('Error during embedding generation:', error);
      res.status(500).send(error.message);
    }
  };```

Hi @nnettey, and welcome to the Pinecone community forums!

Thank you for your question.

Based off your error message and the code you provided, it looks like the vectors you’re trying to upsert are malformed.

Could you please console.log your upsertPayload object prior to calling index.upsert? That will help us to see if something is wrong with your vector format.

At a high-level, your vectors need to look like this:

[
  { id: '1', values: [0.1, 0.2, 0.3] },
  { id: '2', values: [0.4, 0.5, 0.6] },
  // more records...
]

Hope this helps!
Zack

Length of the embedding: 1536
First 5 values of embedding: [
-0.024920061,
-0.017879197,
-0.007459801,
-0.007932796,
-0.019419808
]
Generated uniqueId: d6745304-645e-41f9-bd3f-ddaa6169c497
Upsert payload (without full embedding): {
id: ‘d6745304-645e-41f9-bd3f-ddaa6169c497’,
values: ‘Array of length 1536’,
metadata: { text: ‘Downtown Store sales performance in January 2024.’ }
}

I am just bringing more information (current code and error log) in hopes that it’ll provide more insights so someone can help me. Thanks in advance.
Code
const axios = require(‘axios’);
const { Pinecone } = require(‘@pinecone-database/pinecone’);
const { v4: uuidv4 } = require(‘uuid’);
require(‘dotenv’).config(); // Ensure that the .env file is loaded

// Initialize Pinecone client
let pinecone;

async function initializePinecone() {
console.log(‘Initializing Pinecone client’);
pinecone = new Pinecone({
apiKey: process.env.PINECONE_API_KEY, // Use the API key from the environment variable
});
console.log(‘Pinecone client initialized successfully’);
}

exports.generateEmbedding = async (req, res) => {
const { text } = req.body;

try {
console.log(‘Starting generateEmbedding function’);

// Initialize Pinecone if not already initialized
if (!pinecone) {
  await initializePinecone();
}

// Step 1: Obtain the embeddings from OpenAI
console.log('Step 1: Obtaining embeddings from OpenAI');
const openAIResponse = await getOpenAIEmbedding(text);
logOpenAIResponse(openAIResponse);

// Step 2: Inspect and analyze the OpenAI payload
console.log('Step 2: Inspecting OpenAI payload');
const embedding = inspectOpenAIPayload(openAIResponse);

// Step 3: Format the payload for Pinecone
console.log('Step 3: Formatting payload for Pinecone');
const pineconePayload = formatPineconePayload(embedding, text);
logPineconePayload(pineconePayload);

// Step 4: Upsert into Pinecone
console.log('Step 4: Upserting into Pinecone');
const upsertResponse = await upsertToPinecone(pineconePayload);
console.log('Pinecone Upsert Response:', JSON.stringify(upsertResponse, null, 2));

res.status(200).send({ message: 'Embedding generated and stored successfully.', id: pineconePayload.vectors[0].id });

} catch (error) {
console.error(‘Error during embedding generation:’, error);
res.status(500).send({
message: ‘Error during embedding generation’,
error: error.message,
stack: error.stack
});
}
};

async function getOpenAIEmbedding(text) {
console.log(‘Sending request to OpenAI API’);
try {
const response = await axios.post(
https://api.openai.com/v1/embeddings’,
{
model: ‘text-embedding-ada-002’,
input: text,
},
{
headers: {
Authorization: Bearer ${process.env.OPENAI_API_KEY}, // Use OpenAI API key from environment variable
},
}
);
console.log(‘Received response from OpenAI API’);
return response.data;
} catch (error) {
console.error(‘Error in getOpenAIEmbedding:’, error);
throw error;
}
}

function inspectOpenAIPayload(payload) {
console.log(‘Inspecting OpenAI payload’);
try {
if (!payload || !payload.data || !Array.isArray(payload.data) || payload.data.length === 0) {
throw new Error(‘Invalid response structure from OpenAI API’);
}

const embedding = payload.data[0].embedding;

if (!Array.isArray(embedding) || embedding.length === 0) {
  throw new Error('Invalid embedding in OpenAI API response');
}

if (embedding.length !== 1536) {
  throw new Error(`Embedding dimension mismatch: Expected 1536, got ${embedding.length}`);
}

console.log('OpenAI payload inspection completed successfully');
return embedding;

} catch (error) {
console.error(‘Error in inspectOpenAIPayload:’, error);
throw error;
}
}

function formatPineconePayload(embedding, text) {
console.log(‘Formatting Pinecone payload’);
try {
// Correct format for Pinecone upsert payload
return {
vectors: [
{
id: uuidv4(),
values: embedding,
metadata: { text: text }
}
]
};
} catch (error) {
console.error(‘Error in formatPineconePayload:’, error);
throw error;
}
}

async function upsertToPinecone(payload) {
console.log(‘Preparing to upsert to Pinecone’);
try {
const index = pinecone.index(process.env.PINECONE_INDEX);
console.log(‘Sending upsert request to Pinecone’);

// Ensure that payload.vectors is an array - Test Perplexity changes
if (!Array.isArray(payload.vectors)) {
    throw new Error('payload.vectors must be an array');
}
  
  // Restructure the payload to match Pinecone's expected format
  const vectors = payload.vectors.map(vector => ({
    id: vector.id,
    values: vector.values,
    metadata: vector.metadata
  }));

// Verify that vectors is an array - Test Perplexity changes
if (!Array.isArray(vectors)) {
    throw new Error('vectors must be an array');

//I added this from Perplexity - otherwise, everything seems to be just logging
    const vectors = Array.from(payload.vectors).map(vector => ({
    id: vector.id,
    values: vector.values,
    metadata: vector.metadata
    }));
}

  const response = await index.upsert({ vectors });
  console.log('Received upsert response from Pinecone');
  return response;
} catch (error) {
  console.error('Error in upsertToPinecone:', error);
  throw error;
}

}

// async function upsertToPinecone(payload) {
// console.log(‘Preparing to upsert to Pinecone’);
// try {
// const index = pinecone.index(process.env.PINECONE_INDEX); // Use the index name from the environment variable
// console.log(‘Sending upsert request to Pinecone’);
// const response = await index.upsert(payload); // Use the correct payload structure
// console.log(‘Received upsert response from Pinecone’);
// return response;
// } catch (error) {
// console.error(‘Error in upsertToPinecone:’, error);
// throw error;
// }
// }

function logOpenAIResponse(response) {
const { data, model, usage } = response;
console.log(‘OpenAI API Response:’);
console.log(‘Model:’, model);
console.log(‘Usage:’, usage);
console.log(‘Data:’);
data.forEach((item, index) => {
console.log( Item ${index + 1}:);
console.log(’ Object:‘, item.object);
console.log(’ Embedding:‘, item.embedding.slice(0, 5).map(n => n.toFixed(8)).join(’, ') + ‘…’);
console.log( (${item.embedding.length} total values));
});
}

function logPineconePayload(payload) {
console.log(‘Formatted Pinecone Payload:’);
payload.vectors.forEach((vector, index) => {
console.log( Vector ${index + 1}:);
console.log(’ ID:‘, vector.id);
console.log(’ Values:‘, vector.values.slice(0, 5).map(n => n.toFixed(8)).join(’, ‘) + ‘…’);
console.log( (${vector.values.length} total values));
console.log(’ Metadata:', JSON.stringify(vector.metadata));
});
}

Error:

smart-dashboard-backend@1.0.0 start
node server.js

Failed to find any user-provided fetch implementation. Using global fetch implementation.
Failed to find any user-provided fetch implementation. Using global fetch implementation.
Server running on http://localhost:3000
Starting generateEmbedding function
Initializing Pinecone client
Failed to find any user-provided fetch implementation. Using global fetch implementation.
Failed to find any user-provided fetch implementation. Using global fetch implementation.
Pinecone client initialized successfully
Step 1: Obtaining embeddings from OpenAI
Sending request to OpenAI API
Received response from OpenAI API
OpenAI API Response:
Model: text-embedding-ada-002
Usage: { prompt_tokens: 11, total_tokens: 11 }
Data:
Item 1:
Object: embedding
Embedding: -0.02492006, -0.01787920, -0.00745980, -0.00793280, -0.01941981…
(1536 total values)
Step 2: Inspecting OpenAI payload
Inspecting OpenAI payload
OpenAI payload inspection completed successfully
Step 3: Formatting payload for Pinecone
Formatting Pinecone payload
Formatted Pinecone Payload:
Vector 1:
ID: 3d96fdb4-59c4-4cf2-8f59-8b258f4f4455
Values: -0.02492006, -0.01787920, -0.00745980, -0.00793280, -0.01941981…
(1536 total values)
Metadata: {“text”:“Downtown Store sales performance in January 2024.”}
Step 4: Upserting into Pinecone
Preparing to upsert to Pinecone
Sending upsert request to Pinecone
Error in upsertToPinecone: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at UpsertCommand. (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:71:30)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:33:23)
at Object.next (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:14:53)
at C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:8:71
at new Promise ()
at __awaiter (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:4:12)
at UpsertCommand.run (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:66:16)
at Index. (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:369:70)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at UpsertCommand. (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:71:30)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:33:23)
at Object.next (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:14:53)
at C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:8:71
at new Promise ()
at __awaiter (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:4:12)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at UpsertCommand. (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:71:30)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at UpsertCommand. (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:71:30)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:33:23)
at Object.next (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:14:53)
at C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:8:71
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at UpsertCommand. (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:71:30)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:33:23)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at UpsertCommand. (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:71:30)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)
Error during embedding generation: TypeError: records.forEach is not a function
at UpsertCommand.validator (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:53:21)
at UpsertCommand. (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:71:30)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:33:23)
at Object.next (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:14:53)
at C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:8:71
at new Promise ()
at __awaiter (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:4:12)
at UpsertCommand.run (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\upsert.js:66:16)
at Index. (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:369:70)
at step (C:\Data\LocalNettCreative\smart-dashboard-backend\node_modules@pinecone-database\pinecone\dist\data\index.js:33:23)

Hi @nnettey, just to confirm, the values field actually contains an array like [-0.024920061, -0.017879197...], correct?

Yes…and I truncated the list for brevity.

Any solution to this “TypeError: records.forEach is not a function” while upserting.
I too facing this issue

This code solved my issue:

await index.upsert([   
          {
            id: id,
            values: embedding,
            metadata: { text: text }
          }             
    ]);
3 Likes

This is still a problem and the solution by @appyou.labs is the answer.

Does any one find any solution I also got same error

My Document format is 
[
  {
     id: 'e1155ebb-dcd5-4e6e-914f-c2040512bf23',
      values: [
         0.011354017,  -0.011341083,   -0.018204585, -0.0073649045,
         0.08368674, 0.00023397003,    -0.01874673,  0.0036869808,
         0.02013123,    0.05555253,   0.0055771307,   0.032065485,
        -0.02658448,   0.010055206, -0.00039107262,  -0.026397776,
         0.010732306,  0.0009040295,    -0.03897449,  -0.007176808,
        -0.03917052,  -0.013641686,    -0.02601374,  -0.024340503,
        -0.008319293,  0.0023706453,    0.029447423,  -0.053926665,
        -0.056432765,   0.010725038,    -0.05729338,    0.04068783,
        -0.057509046,   0.021009933,   -0.011675764,   -0.07451308,
         0.03553602,    0.02360018,   -0.020834697,  -0.016477264,
         0.012823754, -0.0044780034,   0.0155311795,   0.045373075,
         0.023174718,   0.017651249,   -0.017668413,   0.006892326,
         0.010145407,  -0.050457586,     0.04526436,   -0.03333952,
         0.051551092,  -0.017029405,    0.021945493, -0.0104806395,
         0.03820274,   0.006993213,   -0.026271556,   0.005284213,
         0.008479656,   0.027970372,    0.014876148,    0.05786055,
        -0.022604734,   -0.08086265,   -0.057218052,   0.019958457,
         0.05837788,  -0.022363458,   0.0035999794,   -0.06550974,
         0.054727647,  -0.024598433,   -0.070066616,  -0.111930676,
        -0.012123667,    0.05187214,     0.03904765,  0.0071906727,
         0.007413799,   -0.04072281,  -0.0041764253,  -0.085484006,
        -0.058109455,  0.0038700802,    -0.01753551,  -0.003449706,
             0.013984,   0.041816227,   -0.011436847,   0.019775018,
         0.0116873775,   -0.06557887,    0.015242518,    0.06895593,
        -0.04322726,   -0.06292457,    0.002645299,  -0.022437187,
     ... 668 more items ],
        metadata: {
        text: '1\t\n' +
            'Sample PDF \n' +
            ' \n' +
            'Created for testing PDFObject \n' +
            ' \n' +
            'This PDF is three pages long. Three long pages. Or three short pages if \n' +
            'you’re optimistic. Is it the same as saying “three long minutes”, knowing \n' +
            'that all minutes are the same duration, and one cannot possibly be longer \n' +
            'than the other? If these pages are all the same size, can one possibly be \n' +
            'longer than the other? \n' +
            ' \n' +
            'I digress. Here’s some Latin. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec \n' +
            'odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum \n' +
            'imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris \n' +
            'massa.  Vestibulum  lacinia  arcu  eget  nulla.  Class  aptent  taciti  sociosqu  ad  litora  torquent  per \n' +
            'conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero.  \n' +
            ' \n' +
            'Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem \n' +
            'at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. \n' +
            'Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia \n' +
            'aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh.  \n' +
            ' \n' +
            'Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia \n' +
            'nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque \n' +
            'adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. \n' +
            'Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices.  \n' +
            ' \n' +
            'Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. \n' +
            'Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue \n' +
    }
  },
 ... rest of other data
]

I am using
node version : v20.15.0
npm version : 10.7.0
@pinecone-database/pinecone : 4.1.0

@ZacharyProser did you find any solution for this ?

Hey @brian2 did you find any solution I also encounter same issue

I’ve found the solution to the issue I was facing — I was making a mistake in my approach.

I wanted to store documents in separate namespaces. In my previous approach, I was passing both vectors and the namespace directly to the upsert function. However, the upsert function only accepts an array, not an object.

Here’s what I was doing, which was incorrect:

const pineConeIndex = pineCone.Index("my-index");
await pineConeIndex.upsert({ vectors, namespace: namespace });

To store documents with a namespace, there’s a method called namespace where you need to pass the namespace name first. Here’s the correct approach:

const pineConeIndex = pineCone.Index("my-index");
const namespace = "my-namespace";
const ns = pineConeIndex.namespace(namespace);
await ns.upsert(vectors);