Updating and deleting vectors

Vector Databases for Embeddings with Pinecone

James Chapman

Curriculum Manager, DataCamp

Keeping things fresh...

  • Keep data current
  • Optimize query performance
  • Maintain data integrity

The lifecycle of data from capture, to usage, validation, and updates or removal.

Vector Databases for Embeddings with Pinecone

Updating vector values

index.fetch(ids=['1'])
{'namespace': '',
 'usage': {'read_units': 1},
 'vectors': {'1': {'id': '1',
                   'metadata': {"genre": "action", "year": 2023},
                   'values': [-0.0131468913, ...]}
            }
}
Vector Databases for Embeddings with Pinecone

Updating vector values

index.update(

id="1",
values=[0.370695321, ...]
)
  • Ensure: list length = index dimensionality
1 https://docs.pinecone.io/docs/update-data
Vector Databases for Embeddings with Pinecone

Updating vector values

index.fetch(ids=['1'])
{'namespace': '',
 'usage': {'read_units': 1},
 'vectors': {'1': {'id': '1',
                   'metadata': {"genre": "action", "year": 2023},
                   'values': [0.370695321, ...]}
            }
}
Vector Databases for Embeddings with Pinecone

Updating vector metadata

index.update(
    id="1",
    set_metadata={"genre": "comedy", "rating": 5}
)
1 https://docs.pinecone.io/docs/update-data
Vector Databases for Embeddings with Pinecone

Updating vector metadata

index.fetch(ids=['1'])
{'namespace': '',
 'usage': {'read_units': 1},
 'vectors': {'1': {'id': '1',
                   'metadata': {"genre": "comedy", "year": 2023, "rating": 5},
                   'values': [0.370695321, ...]}
            }
}
Vector Databases for Embeddings with Pinecone

Updating values and metadata

index.update(
    id="1",
    values=[-0.31956, ...],
    set_metadata={"genre": "thriller", "ratings": 4}
)
1 https://docs.pinecone.io/docs/update-data
Vector Databases for Embeddings with Pinecone

Deleting vectors

index.delete(
    ids=["1", "2"]
)
1 https://docs.pinecone.io/docs/delete-data
Vector Databases for Embeddings with Pinecone

Deleting vectors by-metadata

index.delete(
    filter={
        "genre": {"$eq": "action"},
    }
)
Vector Databases for Embeddings with Pinecone

Deleting vectors within a namespace

index.delete(delete_all=True, namespace='namespace1')
  • Note: Also removes the namespace!
1 https://docs.pinecone.io/docs/delete-data
Vector Databases for Embeddings with Pinecone

Let's practice!

Vector Databases for Embeddings with Pinecone

Preparing Video For Download...