Manage data

In addition to inserting and querying data, there are other ways you can interact with vector data in a Pinecone index. This section walks through the various vector operations available.

Video overview

Connect to an index

If you're using a Pinecone client library to access an index, you'll need to open a session with the index:

pythoncurl
# Connect to the index
index = pinecone.Index("pinecone-index")
# Not applicable

Pinecone indexes each have their own DNS endpoint.

Describe index statistics

Get statistics about an index, such as vector count per namespace:

pythoncurl
index.describe_index_stats()
curl -i -X GET https://YOUR_INDEX-PROJECT_NAME.svc.us-west1-gcp.pinecone.io/describe_index_stats \
  -H 'Api-Key: YOUR_API_KEY'

Fetching vectors

The Fetch operation looks up and returns vectors, by id, from an index. The returned vectors include the vector data and/or metadata.

Fetch items by their ids:

pythoncurl
index.fetch(ids=["id-1", "id-2"])

# Returns:
# {'namespace': '',
#  'vectors': {'id-1': {'id': 'id-1',
#                       'values': [0.568879, 0.632687092, 0.856837332, ...]},
#              'id-2': {'id': 'id-2',
#                       'values': [0.00891787093, 0.581895, 0.315718859, ...]}}}
curl -i -X GET "https://YOUR_INDEX-YOUR_PROJECT.svc.us-west1-gcp.pinecone.io/vectors/fetch?ids=id-1&ids=id-2" \
  -H 'Api-Key: YOUR_API_KEY'
# Output:
# {
#   "vectors": {
#     "id-1": {
#       "id": "id-1",
#       "values": [0.568879, 0.632687092, 0.856837332, ...]
#     },
#     "id-2": {
#       "id": "id-2",
#       "values": [0.00891787093, 0.581895, 0.315718859, ...]
#     }
#   },
#   "namespace": ""
# }

Updating vectors

Updating an item by id is done the same way as inserting items. (Write operations in Pinecone are idempotent.)

The Upsert operation writes vectors into an index.

note

If a new value is upserted for an existing vector id, it will overwrite the previous value.

  1. Update the value of the item ("id-3", [3., 3.]):
pythoncurl
index.upsert(vectors=[("id-3", [3.3, 3.3])])
curl -i -X POST https://YOUR_INDEX-YOUR_PROJECT.svc.us-west1-gcp.pinecone.io/vectors/upsert \
  -H 'Api-Key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "vectors": [
      {
        "id": "id-0",
        "values": [3.3, 3.3]
      }
    ]
  }'
  1. Fetch the item again. We should get ("id-3", [3.3, 3.3]):
pythoncurl
index.fetch(ids=["id-3"])
curl -i -X GET https://YOUR_INDEX-YOUR_PROJECT.svc.us-west1-gcp.pinecone.io/vectors/fetch?ids=id-3 \
  -H 'Api-Key: YOUR_API_KEY'

Deleting vectors

The Delete operation deletes vectors, by id, from an index.

Alternatively, it can also delete all vectors from an index or namespace.

note

If you delete all vectors from a single namespace, it will also delete the namespace.

To delete vectors by their ids:

pythoncurl
index.delete(ids=["id-1", "id-2"], namespace='example-namespace')
curl -i -X DELETE "https://YOUR_INDEX-YOUR_PROJECT.svc.us-west1-gcp.pinecone.io.pinecone.io/vectors/delete?ids=id-1&ids=id-2&namespace=example-namespace" \
  -H 'Api-Key: YOUR_API_KEY'

To delete all vectors from a namespace:

pythoncurl
index.delete(delete_all=True, namespace='example-namespace')
curl -i -X DELETE "https://YOUR_INDEX-YOUR_PROJECT.svc.us-west1-gcp.pinecone.io/vectors/delete?delete_all=true&namespace=example-namespace" \
  -H 'Api-Key: YOUR_API_KEY'