Update data

This page shows you how to use the update operation to update parts of existing records in an index namespace. To update entire records, use the upsert operation instead.

⚠️

Warning

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.

Update dense vector values

In this example, assume you want to update the dense vector values of the following record in the ns1 namespace: ("id-3", [3.0, 3.0], {"type": "doc", "genre": "drama"}).

from pinecone import Pinecone

pc = Pinecone(api_key="YOUR_API_KEY")
index = pc.Index("pinecone-index")

index.update(id="id-3", values=[4.0, 2.0], namespace="ns1")
import { Pinecone } from '@pinecone-database/pinecone'

const pc = new Pinecone({ apiKey: "YOUR_API_KEY" })
const index = pc.index("pinecone-index")

await index.namespace('ns1').update({
 	id: 'id-3',
 	values: [4.0, 2.0]
});
# The `POST` request below uses the unique endpoint for an index.
# See https://docs.pinecone.io/docs/get-index-endpoint for details.
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"

curl -X POST "https://$INDEX_HOST/vectors/update" \
	-H "Api-Key: $PINECONE_API_KEY" \
	-H 'Content-Type: application/json' \
	-d '{
			"id": "id-3",
			"values": [
				4.0,
				2.0
			],
			"namespace": "ns1"
		}'

After the update, the dense vector values are changed, but the metadata is unchanged: ("id-3", [4.0, 2.0], {"type": "doc", "genre": "drama"}).

Update metadata values

When updating metadata, only the specified metadata fields are modified, and if a specified metadata file does not exist, it is added.

In this example, assume you are updating the metadata values of following record in the ns1 namespace:

(id="id-3", values=[4.0, 2.0], metadata={"type": "doc", "genre": "drama"}).

from pinecone import Pinecone

pc = Pinecone(api_key="YOUR_API_KEY")
index = pc.Index("pinecone-index")

index.update(
	id="id-3", 
	set_metadata={"type": "web", "new": True}, 
	namespace="ns1"
)
import { Pinecone } from '@pinecone-database/pinecone'

const pc = new Pinecone({ apiKey: "YOUR_API_KEY" })
const index = pc.index("pinecone-index")

await index.namespace('ns1').update({
	id: 'id-3',
	metadata: {
		type: "web",
		new: true,
	},
});
# The `POST` request below uses the unique endpoint for an index.
# See https://docs.pinecone.io/docs/get-index-endpoint for details.
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"

curl -X POST "https://$INDEX_HOST/vectors/update" \
  -H "Api-Key: $PINECONE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
      "id": "id-3",
      "setMetadata": {
          "type": "web",
          "new": true
      },
      "namespace": "ns1"
    }'

After the update, the type metadata field is web, the new property is added with the value true, and the genre property is unchanged:

(id="id-3", values=[4.0, 2.0], metadata={"type": "web", "new": true, "genre": "drama"}).

Update sparse vector values

In this example, assume you are updating the sparse vector values of the following record in the ns1 namespace:

(
	id="id-3", 
	values=[1.0, 2.0], 
	sparse_values={"indices": [1, 5], "values": [0.5, 0.5]}
)
from pinecone import Pinecone

pc = Pinecone(api_key="YOUR_API_KEY")
index = pc.Index("pinecone-index")

index.update(
	id="id-3", 
	sparse_values={"indices": [2, 6], "values": [0.5, 0.5]},
	namespace="ns1"
)
import { Pinecone } from '@pinecone-database/pinecone'

const pc = new Pinecone({ apiKey: "YOUR_API_KEY" })
const index = pc.index("pinecone-index")

await index.namespace('ns1').update({
  id: 'id-3',
  sparseValues: {'indices': [2, 6], 'values': [0.5, 0.5]},
});
# The `POST` request below uses the unique endpoint for an index.
# See https://docs.pinecone.io/docs/get-index-endpoint for details.
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"

curl -X POST "https://$INDEX_HOST/vectors/update" \
  -H "Api-Key: $PINECONE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
      "id": "id-3",
      "sparse_values": {"indices": [2, 6], "values": [0.5, 0.5]},
      "namespace": "ns1"
    }'

After the update, the sparse value indices array is changed, but the rest of the record is unchanged:

(
	id="id-3", 
	values=[1.0, 2.0], 
	sparse_values={"indices": [2, 6], "values": [0.5, 0.5]}
)

Update a combination of values

ℹ️

Note

To update an entire record, use the upsert operation instead.

In this example, assume you are updating the dense vector values and one metadata value of the following record in the ns1 namespace:

(id="id-3", values=[4.0, 2.0], metadata={"type": "doc", "genre": "drama"}).

from pinecone import Pinecone

pc = Pinecone(api_key="YOUR_API_KEY")
index = pc.Index("pinecone-index")

index.update(
	id="id-3", 
	values=[5.0, 3.0], 
	set_metadata={"genre": "comedy"},
	namespace="ns1"
)
import { Pinecone } from '@pinecone-database/pinecone'

const pc = new Pinecone({ apiKey: "YOUR_API_KEY" })
const index = pc.index("pinecone-index")

await index.namespace('ns1').update({
  id: 'id-3',
  values: [5.0, 3.0],
  metadata: {
    type: "comedy",
  },
});
# The `POST` request below uses the unique endpoint for an index.
# See https://docs.pinecone.io/docs/get-index-endpoint for details.
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"

# Update both values and metadata
curl -X POST "https://$INDEX_HOST/vectors/update" \
  -H "Api-Key: $PINECONE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
        "id": "id-3",
        "values": [5.0, 3.0],
        "setMetadata": {"type": "comedy"},
        "namespace": "ns1"
      }'

After the update, the dense vector values and the genre metadata value would be changed, but the type metadata value would be unchanged: (id="id-3", values=[5.0, 3.0], metadata={"type": "doc", "genre": "comedy"}).