Your NODE JS Api is NOT GOOD.. differences between the doc and the API reference and nothing work

Your NODE JS Api is not good… differences between the doc and the API reference and nothing work

What’s the good call to upsert?

I got : Error calling upsert: PineconeClient: Error calling upsertRaw: RequiredError: Required parameter requestParameters.upsertRequest was null or undefined when calling upser

I followed your API reference…

onst vector1 = {
id: ‘vec1’,
values: [0.1,0.2,0.3,0.4],
metadata: {‘genre’: ‘drama’}

const vector2 = {
id: ‘vec2’,
values: [0.2,0.3,0.4,0.5],
metadata: {‘genre’: ‘action’}
}

const upsertrequest = {
vectors: [vector1, vector2]
};

await index.upsert(upsertrequest);

Btw in your API reference sometimes some “}” are missing… it’s “.index” instead “.Index”

Not really pro

Your message isn’t very nice, but I’ve had great success just making https calls directly and not using the libraries.

Thanks for your input @LevJulien.

We indeed found some mistakes in the documentation, and they have been corrected. That said, please note that whenever we reference index (lowercase), the intent is to reference an instance of Index.

Your request is mostly correct, and can be fixed by rewriting the following:

const upsertrequest = {
    vectors: [vector1, vector2]
};
await index.upsert(upsertrequest);

To

const upsertRequest = {
    vectors: [vector1, vector2]
};
await index.upsert({ upsertRequest });

Please review the updated upsert docs.

Apologies for the error. Please follow up on this thread if you run into any other issue.
Thanks!

I followed the documentation and got the error:

 index.upsertVectors is not a function

My entire code is:


import { PineconeClient } from "@pinecone-database/pinecone";

const pinecone = new PineconeClient();
await pinecone.init({
  environment: "redacted",
  apiKey: "redacted",
});

const index = pinecone.Index("sebastian");
const upsertRequest = {
  vectors: [
    {
      id: "vec1",
      vector: [0.1, 0.2, 0.3, 0.4],
      metadata: {
        genre: "drama",
      },
    },
    {
      id: "vec2",
      vector: [0.2, 0.3, 0.4, 0.5],
      metadata: {
        genre: "action",
      },
    },
  ],
  namespace: "example-namespace",
};
const upsertResponse = await index.upsertVectors({ upsertRequest });

The function name is upsert and not upsertVectors.
The following line:

const upsertResponse = await index.upsertVectors({ upsertRequest });

Should be:

const upsertResponse = await index.upsert({ upsertRequest });

I dont understand. You can literally copy paste the code from the “updated” tutorial and it returns “PineconeClient: Error calling upsert: PineconeClient: Error calling upsertRaw: ResponseError: Response returned an error code” // “PineconeClient: Error calling upsert: PineconeClient: Error calling upsertRaw: RequiredError: Required parameter requestParameters.upsertRequest was null or undefined when calling upsert.”. I have tried every single possible combination of batches versus individual vectors, wasted multiple hours at this point thinking I had something misconfigured, but nothing works. Meanwhile I got the Python library working within minutes. What is going on?

@sobad I’m sorry for the inconvenience and I’d love to help you solve this issue!

I’ve verified that the code above works as intended. Here’s an example to clarify:

const index = client.Index(indexName)
const v1: Vector = {
  id: '1',
  values: [0.1, 0.2, 0.3, 0.4, 0.5],
  metadata: { "key": "value" }
}

const v2: Vector = {
  id: '2',
  values: [0.11, 0.12, 0.13, 0.14, 0.15],
  metadata: { "key": "value" }
}
const upsertRequest: UpsertRequest = {
  vectors: [
    v1, v2
  ]
}
const res = await index.upsert({ upsertRequest })
console.log(res)

This returns:

{ upsertedCount: 2 }

Are you using the latest version of the client (0.0.9)?
Can you please provide an example of how you’re calling the function?

  const index = pinecone.Index('testing')

  const vector1 = {
    id: '1',
    values: [0.1, 0.2, 0.3, 0.4, 0.5],
    metadata: { "key": "value" }
  }

  const vector2 = {
    id: '2',
    values: [0.11, 0.12, 0.13, 0.14, 0.15],
    metadata: { "key": "value" }
  }

  const upsertRequest = {
    vectors: [
      vector1, vector2
    ]
  }
  const rez = await index.upsert({ upsertRequest })

node:internal/process/esm_loader:100
internalBinding(‘errors’).triggerUncaughtException(
^
PineconeClient: Error calling upsert: PineconeClient: Error calling upsertRaw: ResponseError: Response returned an error code

My exact code, and I have tried many other variations of it.
image

Im having the same issue

Thought I was going insane and that you had fixed yours lol

I won’t hang you out to dry, we seems to be the only 2 people on this planet publicly struggling our asses with off this

@sobad / @jhs - how many dimensions is your index configured to use?

I may just be incompetent but I am calling the function differently.

const index = client.Index(indexName) // const index = pinecone.index("sms-messages")
const v1: Vector = { // const vector1 = {
  id: '1',
  values: [0.1, 0.2, 0.3, 0.4, 0.5],
  metadata: { "key": "value" }
}

const v2: Vector = { // const vector2 = {
  id: '2',
  values: [0.11, 0.12, 0.13, 0.14, 0.15],
  metadata: { "key": "value" }
}
const upsertRequest: UpsertRequest = {
  vectors: [
    v1, v2
  ]
}
const res = await index.upsert({ upsertRequest }) // const upsertResponse = await index.upsert({ upsertRequest });

console.log(res)

I have added in // what I am doing differently, I have followed what was in the docs and my create index function worked fine. But this returns

PineconeClient: Error calling upsert: PineconeClient: Error calling upsertRaw: ResponseError: Response returned an error code  

Index is configured as 1536, cosine, s1.x1

@jhs - that is the issue then. You can only upsert/update/query with vectors that are the same dimension as your index. Right now you’re trying to upsert vector with a dimension of 5, and that won’t work.

I’m actively working on exposing the correct error, which isn’t properly exposed at the moment. I apologize for this, and I’m working as fast as possible to rectify it. I suspect @sobad also has the same issue.

2 Likes

Thanks a lot for your help.

1 Like

Thanks. I don’t believe this was my issue, even though I had in fact forgotten about that while briefly testing the versions here. I ended up converting the python tutorial code to react and found the “iMax” value was returning NaN for some reason, and a couple other formatting things. I’m honestly not sure at this point. I used chatgpt and bing to basically debug it all but here is the working code if anyone stumbles upon it in the future. Its not very optimized but the important thing is it works.

Thanks guys.

const index = await pinecone.Index(“app”);

let embeddingTokensUsed = 0

for (let i = 0; i < lines.length; i += batchSize) {
  // Set end position of batch
  const iEnd = Math.min(i + batchSize, lines.length);
  
  // Get batch of lines and IDs
  const linesBatch = await lines.slice(i, iEnd);
  const idsBatch = Array.from({ length: linesBatch.length }, (_, n) => String(i + n));
  // Create embeddings for the batch
  const res = await openai.createEmbedding({
    input: linesBatch,
    model: MODEL,
  });
  embeddingTokensUsed += res.data.usage.total_tokens
  console.log("used " + embeddingTokensUsed)

  const embeddings = res.data.data.map((record) => record.embedding);
  // Prepare metadata and upsert batch to Pinecone
  const metadata = linesBatch.map((line) => ({ text: line.trim() }));
  const toUpsert = idsBatch.map((id, i) => ({
    id,
    values: embeddings[i],
    metadata: metadata[i],
  }));

  const leVectors = []
  for(let x = 0; x < toUpsert.length; x++){
    leVectors.push(toUpsert[x])
  }
  console.log(leVectors.length)

  const upsertRequest = {
    vectors: leVectors,
    namespace: "testooor"
  }

  await index.upsert({upsertRequest});
}

It’s good to know you’re unblocked. One quick clarification: The client is not meant to be used in the front end (with React etc) but rather in the backend, running on either Node.JS or Deno.

Hi again,

So my upsert is now working perfectly, the vectors are getting created and indexed with the correct namespace but I am having the same issues as yesterday only this time with the query function

 var error = new Error(message);
              ^
Error: Request failed with status code 400

My full query code is

const xq = await openai.createEmbedding({
  model: "text-embedding-ada-002",
  query: userMessage,
});


const queryembedding = xq.data[0].embedding;

const queryRequest = {
  query: {
    vector: queryembedding,
    topK: 10,
    includeValues: true,
    includeMetadata: false
  },
  namespace: sessionId,
}

const queryResponse = await index.query({ queryRequest })


console.log("Embeddings queried")

The rest of my upsert code is:

const userEmbedding = await openai.createEmbedding({
  model: "text-embedding-ada-002",
  input: userMessage,
});

const userEmbeddingData = userEmbedding.data.data[0].embedding;
const upsertRequest = {
  vectors: [
    {
      id: embeddingId,
      values: userEmbeddingData,
    },
  ],
  namespace: sessionId,
};
const upsertResponse = await index.upsert({ upsertRequest });

I was looking at the docs for the openAI API and in the docs is uses the xq but I didn’t manage to get that working and based on what you said yesterday, I think the error must be with the dimensions but im not sure how to resolve this, any guidance would be appreciated.

Same here I just was going to come back here to look through and see what I was missing :sob::sob::sob: I am so lost on why this isn’t working, I literally was using it the other day?