This page shows you how to use the update operation to update parts of existing records in dense or sparse indexes. To update entire records, use the upsert operation instead.
The update operation does not validate the existence of IDs within an index. If a non-existent ID is specified, no records are affected and a 200 OK status is returned.
To update the dense vector value of a record in a dense index, specify the namespace, record id, and the new dense vector values. The new dense vector values must have the same length as the existing dense vector values.
In this example, assume you want to update the dense vector values of the following record in the example-namespace namespace:
from pinecone.grpc import PineconeGRPC as Pineconepc = Pinecone(api_key="YOUR_API_KEY")# To get the unique host for an index, # see https://docs.pinecone.io/guides/manage-data/target-an-indexindex = pc.Index(host="INDEX_HOST")index.update(id="id-3", values=[4.0, 2.0], namespace="example-namespace")
After the update, the dense vector values are changed, but the metadata is unchanged:
from pinecone.grpc import PineconeGRPC as Pineconepc = Pinecone(api_key="YOUR_API_KEY")# To get the unique host for an index, # see https://docs.pinecone.io/guides/manage-data/target-an-indexindex = pc.Index(host="INDEX_HOST")index.update( id="id-3", sparse_values={"indices": [2, 6], "values": [0.5, 0.5]}, namespace="example-namespace")
After the update, the sparse value indices array is changed, but the rest of the record is unchanged:
from pinecone.grpc import PineconeGRPC as Pineconepc = Pinecone(api_key="YOUR_API_KEY")# To get the unique host for an index, # see https://docs.pinecone.io/guides/manage-data/target-an-indexindex = pc.Index(host="INDEX_HOST")index.update( id="id-3", set_metadata={"type": "web", "new": True}, namespace="example-namespace")
After the update, the type metadata field is web, the new property is added with the value true, and the genre property is unchanged:
from pinecone.grpc import PineconeGRPC as Pineconepc = Pinecone(api_key="YOUR_API_KEY")# To get the unique host for an index, # see https://docs.pinecone.io/guides/manage-data/target-an-indexindex = pc.Index(host="INDEX_HOST")index.update( id="id-3", values=[5.0, 3.0], set_metadata={"genre": "comedy"}, namespace="example-namespace")
After the update, the dense vector values and the genre metadata value are changed, but the type metadata value is unchanged:
Pinecone is eventually consistent, so there can be a slight delay before new or changed records are visible to queries. You can view index stats to check data freshness.
Assistant
Responses are generated using AI and may contain mistakes.