Skip to main content
This page shows you how to update the data in an index namespace. The kind of index determines which operation you use. An index with a document schema uses the Documents API, and a vector index uses the Vectors API. If you aren’t sure which kind of index you have, see Adopt the Documents API.
  • Update documents: Patch fields on a document by ID, or patch metadata fields across every document matching a filter.
  • Update by ID: Update a single record’s metadata (add or change fields) or vector values.
  • Update by metadata: Update metadata (add or change fields) across multiple records using a metadata filter. Vector values can’t be updated.
To replace whole documents or records, use the upsert operation instead.
Updates consume write units (WUs). See Understanding cost for how update cost is calculated.

Update documents

In an index with a document schema, upsert replaces the whole document for a given _id. To change individual fields instead, use the documents update operation, which leaves the fields you don’t mention unchanged. To patch specific documents, send one entry per _id. Include the fields you want to set, and name any fields to drop in _remove_fields. Both schema-declared fields and metadata fields can be set or removed this way:
To apply the same patch to every document matching a metadata filter expression, send filter with set_fields, remove_fields, or both:
The response reports how many documents matched the filter:
For the full request and response schema, see Update documents.

Limitations

  • By-ID requests: Each request can patch up to 1,000 documents. See Update limits.
  • By-filter requests: set_fields and remove_fields both accept metadata fields only, and reject a field declared in the schema with a 400. A by-filter update applies one value to every matched document, which would leave vector and full-text-searchable fields identical across the whole match set. To change a schema-declared field, patch each document by ID.
This operation ignores the dry_run parameter that Update by metadata supports. A dry_run request returns 202 with a matched_records count, exactly like the preview you expect, and the update is applied anyway. It also accepts unrecognized parameters rather than rejecting them, so check the parameter names before you send a request you can’t undo.

Update by ID

To update the vector and/or metadata of a single record, use the update operation with the following parameters:
  • namespace: The namespace containing the record to update. To use the default namespace, set the namespace to "__default__".
  • id: The ID of the record to update.
  • One or both of the following:
    • Updated values for the vector. Specify one of the following:
      • values: For dense vectors. Must have the same length as the existing vector.
      • sparse_values: For sparse vectors.
    • setMetadata: The metadata to add or change. When updating metadata, only the specified metadata fields are modified, and if a specified metadata field doesn’t exist, it is added.
If a non-existent record ID is specified, no records are affected and a 200 OK status is returned.
In this example, assume you are updating the dense vector values and one metadata value of the following record in the example-namespace namespace:
After the update, the dense vector values and the genre metadata value are changed, but the type metadata value is unchanged:

Update by metadata

To add or change metadata across multiple records in a namespace, use the update operation with the following parameters:
  • namespace: The namespace containing the records to update. To use the default namespace, set this to "__default__".
  • filter: A metadata filter expression to match the records to update.
  • setMetadata: The metadata to add or change. When updating metadata, only the specified metadata fields are modified. If a specified metadata field doesn’t exist, it is added.
  • dry_run: Optional. If true, the number of records that match the filter expression is returned, but the records aren’t updated.
    Each request updates a maximum of 100,000 records. Use "dry_run": true to check if you need to run the request multiple times. See the example below for details.
For example, let’s say you have records that represent chunks of a single document with metadata that keeps track of chunk and document details, and you want to store the author’s name with each chunk of the document:
The following code updates all matching records with the new author metadata field:

Handling large updates

If you need to update most of the records in a large namespace, contact Support for help creating an export to enable a faster and more cost-effective approach.
Each request updates a maximum of 100,000 records. For larger datasets, use dry_run to check the count and repeat the request as needed:
  1. To check how many records match the filter expression, send a request with dry_run set to true:
    curl
    The response contains the number of records that match the filter expression:
    Since this number exceeds the 100,000 record limit, you’ll need to run the update request multiple times.
  2. Initiate the first update by sending the request without the dry_run parameter:
    curl
    Again, the response contains the total number of records that match the filter expression, but only 100,000 will be updated:
  3. Pinecone is eventually consistent, so there can be a slight delay before your update request is processed. Repeat the dry_run request until the number of matching records shows that the first 100,000 records have been updated:
    curl
  4. Once the first 100,000 records have been updated, update the remaining records:
    curl
  5. Repeat the dry_run request until the number of matching records shows that the remaining records have been updated:
    curl
    Once the request has completed, all matching records include the author name as metadata:

Limitations

  • Each request updates a maximum of 100,000 records, per Update limits. Use "dry_run": true to check if you need to run the request multiple times. See the example above for details.
  • Large update-by-metadata requests can be slow to process. A request that matches many records takes longer to complete and to be reflected, so size the work with dry_run and batch it. See Handling large updates.
  • You can add or change metadata across multiple records, but you can’t remove metadata fields.

Remove a metadata field

To remove a metadata field from a record, use the upsert operation to replace the record’s metadata, providing the record’s existing ID and vector values along with only the metadata you want to keep. Because upsert replaces a record’s metadata in full, any fields you omit are cleared. In an index with a document schema, remove a field with _remove_fields instead of replacing the document. See Update documents.

Data freshness

Pinecone is eventually consistent, so there can be a slight delay before updates are visible to queries. You can use log sequence numbers to check whether an update request has completed.

See also