Qdrant vector DB supports updating multiple points using batch_update_points()
. Batch update points can take in multiple different operations as parameters and run them as a single API operation.
batch_update_points()
supports 4 kinds of update operations.
- UpsertOperation
- DeleteOperation
- UpdateVectorsOperation
- DeleteVectorsOperation
- SetPayloadOperation
- OverwritePayload
- DeletePayloadOperation
- ClearPayloadOperation
batch_update_points()
supports mixing up different kinds of operations in one request. For example you could perform an UpsertOperation
for point ids [1, 2, 3]
along with a delete operation on point id [4, 5, 6]
.
You can mix and match these operations in any way as per your requirements.
Examples
Setup
Install qdrant-client
pip install qdrant-client
Create the collection
from qdrant_client import QdrantClient
from qdrant_client import models
COLLECTION_NAME = "test_collection"
client = QdrantClient(location=":memory:")
client.create_collection(
collection_name=COLLECTION_NAME,
vectors_config=models.VectorParams(size=3, distance=models.Distance.COSINE),
)
Batch upsert
client.batch_update_points(
collection_name=COLLECTION_NAME,
update_operations=[
models.UpsertOperation(
upsert=models.PointsList(
points=[
models.PointStruct(
id=1,
vector=[0.9, 0.1, 0.1],
payload={
"name": "one",
"description": "description for one",
"location": "location for one"},
),
models.PointStruct(
id=2,
vector=[0.9, 0.1, 0.1],
payload={"name": "two",
"description": "description for two",
"location": "location for two"},
),
models.PointStruct(
id=3,
vector=[0.9, 0.1, 0.1],
payload={"name": "three",
"description": "description for three",
"location": "location for three"},
),
models.PointStruct(
id=4,
vector=[0.9, 0.1, 0.1],
payload={"name": "four",
"description": "description for four",
"location": "location for four"},
),
]
)
)
]
)
Retrieve the upserted points
client.retrieve(
collection_name=COLLECTION_NAME,
ids=[1, 2, 3, 4],
)
Batch set payload
# Batch update payload
client.batch_update_points(
collection_name=COLLECTION_NAME,
update_operations=[
# Points can be updated with the same payload in one operation
models.SetPayloadOperation(
set_payload=models.SetPayload(
payload={"description": "updated description for one and two"},
points=[1, 2],
)
),
# Or they can be updated with the different payloads in multiple operations
models.SetPayloadOperation(
set_payload=models.SetPayload(
payload={"description": "updated description for three"},
points=[3],
)
),
models.SetPayloadOperation(
set_payload=models.SetPayload(
payload={"description": "updated description for four"},
points=[4],
)
),
],
)
Retrieve the updated points
client.retrieve(
collection_name=COLLECTION_NAME,
ids=[1, 2, 3, 4],
)