pinecone-client icon indicating copy to clipboard operation
pinecone-client copied to clipboard

Suggestion: Upsert call should return the count of vectors inserted

Open nicolaerusan opened this issue 2 years ago • 0 comments

Currently, the Upsert call handles batching (which is 👌 ), but I noticed that right now the function doesn't return anything.

It may be useful to modify this function to be consistent with the Upsert Pinecone API call which returns an object that has:

upsertedCount as a number when successful.

To support batch mode it could return a response that has the sum of all the upsertedCounts from each individual batch's response.

  async upsert(params: {
    vectors: SetRequired<Vector<Metadata>, 'metadata'>[];
    batchSize?: number;
  }): Promise<void> {
    // Don't upsert more than `params.batchSize` vectors in a single request
    const batchSize = params.batchSize || 50;
    for (let i = 0; i < params.vectors.length; i += batchSize) {
      const vectors = params.vectors.slice(i, i + batchSize);
      const vectorsWithoutMetadataNulls = vectors.map(removeNullValues);
      await this.api
        .post('vectors/upsert', {
          json: {
            namespace: this.namespace,
            vectors: vectorsWithoutMetadataNulls,
          },
        })
        .json();
    }
  }

nicolaerusan avatar Jan 19 '23 20:01 nicolaerusan