pinecone-io / pinecone-ts-client

The official TypeScript/Node client for the Pinecone vector database
https://www.pinecone.io
Apache License 2.0
182 stars 38 forks source link

types(update): wrap metadata param in `Partial` #199

Closed omikader closed 8 months ago

omikader commented 8 months ago

Problem

This PR makes it so that you don't need to supply all of the required fields in your custom metadata interface when updating a vector using the TS client.

For example, say I have a metadata interface defined as the following:

interface MyMetadata {
  title: string;
  source: string;
  isArchived?: boolean;
}

I want to update the value for isArchived, but I want to leave the values for title and source as is. I'd write the following code, but I get a type error because no value for title or source were provided

const ns = pinecone.index<MyMetadata>(indexName).namespace(namespace);
await ns.update({ id: "abc123", metadata: { isArchived: true });
Type '{ isArchived: boolean; }' is missing the following properties from type '{ title: string; source: string; isArchived?: boolean | undefined; }': title, source

Solution

By wrapping the generic in Partial, we make it so that all of the fields in the interface are optional which is the intent of this method according to the documentation

If set_metadata is included, the values of the fields specified in it will be added or overwrite the previous value.

Type of Change

Test Plan

N/A

austin-denoble commented 8 months ago

Hey @omikader, thanks for the great PR description and fix. This looks like it makes sense to me, I'll let CI run and merge when ready, thank you!

Validating CI in a draft here since forks don't share secrets: https://github.com/pinecone-io/pinecone-ts-client/pull/200