0

I am trying to insert the vectors into by pinecone database by this lines of code:

console.log('inserting vectors into Pinecone');

    const namespace = pineconeIndex.namespace(convertToAscii(filekey));

    console.log("inserting vectors into pinecone");
    await namespace.upsert(vectors);

    return documents[0];  

But i am getting the error for 'vectors' in upsert method: Argument of type 'Vector[]' is not assignable to parameter of type 'PineconeRecord<RecordMetadata>[]'. Type 'Vector' is not assignable to type 'PineconeRecord<RecordMetadata>'. Types of property 'metadata' are incompatible. Type 'object | undefined' is not assignable to type 'RecordMetadata | undefined'. Type 'object' is not assignable to type 'RecordMetadata'.

I am expecting to insert my vectors in pinecone database in next.js. If any others methods are known please let me know.

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Mar 16, 2024 at 10:14

2 Answers 2

0

As chunkedUpsert() method is deprecated. It takes arguments as Vector types, but now using this await namespace.upsert(vectors) method, Pinecone expects records inserted into indexes have the type as PineconeRecord not Vector.

You can import it like this:-

import { PineconeRecord } from '@pinecone-database/pinecone';

return {
      id: hash,
      values:embeddings,
      metadata:{
        text: doc.metadata.text,
        pageNumber: doc.metadata.pageNumber
      }
    } as PineconeRecord

Changing this from Vector to PineconeRecord must resolve your issue.

Sign up to request clarification or add additional context in comments.

Comments

0

This could solve your issue,

Import following library,

import { Pinecone, PineconeRecord } from "@pinecone-database/pinecone";

Define type as following by replacing Vector to PineconeRecord,

return {
      id: hash,
      values:embeddings,
      metadata:{
        text: doc.metadata.text,
        pageNumber: doc.metadata.pageNumber
      }
    } as PineconeRecord

In case, if you are getting PineconeRecord type error, try to add the validVectors to filter out any undefined vectors

  const validVectors = vectors.filter(
    (vector): vector is PineconeRecord => vector !== undefined
  );

console.log('inserting vectors into Pinecone');

    const namespace = pineconeIndex.namespace(convertToAscii(filekey));

    console.log("inserting vectors into pinecone");
    await namespace.upsert(vectors);

    return documents[0];  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.