CRUD & Batch Operations
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
This page covers the point-level CRUD operations Qdrant exposes on top of the collections and points introduced in Collections & Points — upserting, retrieving, and deleting points — plus the scroll API for paging over a collection’s contents, and the batching techniques that keep large writes fast and memory-bounded.
All examples on this page run against the six-product products collection from
the running example, with a Cosine collection of
4-dimensional vectors, and the outputs shown are what Qdrant 1.20 returned.
How a write travels
Before the individual calls, it helps to know what "the write succeeded" means, because it differs between the two modes of every write endpoint:
With wait=false the response means "durably queued"; a search issued immediately afterwards may not see the new
point yet. With wait=true (wait=True, which is the default of the Python client) the call returns only after the
change is applied, so a following search is guaranteed to see it. Bulk loaders use wait=false for throughput and
finish with one wait=true write or a count check; interactive code and tests use wait=true. Each operation also
gets a monotonically increasing operation_id, which is also what appears as version on every point, so writes
to one collection are applied in the order they were accepted.
Upsert: create or replace by id
upsert is Qdrant’s only write primitive for points: there is no separate "insert" that fails on a duplicate
id — a point with an id already present in the collection is replaced in full (vector and payload both), and
an id not yet present is created. This is the same call already shown in
Points, repeated here as the CRUD baseline the rest of
this page builds on.
from qdrant_client import QdrantClient, models
from qdrant_client.models import PointStruct
client = QdrantClient(url="http://localhost:6333")
client.upsert(
collection_name="products",
points=[
PointStruct(
id=1,
vector=[0.12, -0.98, 0.33, 0.47],
payload={"category": "audio", "in_stock": True},
),
],
)
Because upsert replaces the whole point, an upsert that omits a payload field the existing point had drops
that field rather than leaving it untouched — partial payload edits go through the separate
set_payload/overwrite_payload calls instead of upsert. The experiment below shows it on the Bluetooth speaker
(id 2): the upsert sends only a name, and everything else is gone.
client.upsert("products", wait=True, points=[
models.PointStruct(id=2, vector=[0.8, 0.2, 0.1, 0.0], payload={"name": "Bluetooth speaker"}),
])
print(client.retrieve("products", ids=[2])[0].payload)
# {'name': 'Bluetooth speaker'} <- category, price, brand ... were dropped
Upsert is also idempotent: sending the same point twice leaves the collection in the same state as sending it
once, which makes a retry after a timeout safe. When a write must only replace a point whose current payload meets
a condition, the REST body accepts an update_filter. Here the filter requires a price above 1000, which point 1
does not meet, so the write is a no-op and the name stays Studio headphones:
curl -X PUT 'http://localhost:6333/collections/products/points?wait=true' \
-H 'Content-Type: application/json' \
-d '{"points":[{"id":1,"vector":[0.9,0.1,0.0,0.1],"payload":{"name":"x"}}],
"update_filter":{"must":[{"key":"price","range":{"gt":1000}}]}}'
Sending a vector of the wrong length is rejected for the whole request, not just that point:
Wrong input: Vector dimension error: expected dim: 4, got 2.
Retrieve points by id
retrieve fetches specific points by id, with independent flags for whether the response should include the
vector and/or the payload — useful for a lookup that only needs the payload (skipping the cost of returning a
large vector) or one that needs neither and is really just an existence check.
result = client.retrieve(
collection_name="products",
ids=[1, 2, 3],
with_vectors=True, # include the stored vector(s) in the response
with_payload=True, # include the payload in the response
)
for point in result:
print(point.id, point.payload)
Over REST the defaults are different from the Python client: a plain POST /collections/products/points with
{"ids":[1,99]} returns {"result":[{"id":1}]} — no payload, no vector — and silently omits the unknown id 99
rather than failing. The Python retrieve sets with_payload=True for you. With vectors requested, a Cosine
collection returns the stored, normalized vector ([0.9878784, 0.10976427, 0.0, 0.10976427] for point 1).
with_payload also accepts a list of field names (or an inclusion/exclusion object) to return only part of the
payload, and both flags default to returning the payload but not the vector — set with_vectors=True
explicitly whenever the vector itself is needed.
Updating part of a point
Re-upserting a whole point to change one price is wasteful and, as shown above, dangerous. Qdrant has dedicated
partial-update calls that touch only the payload or only the vectors. The sequence below runs against point 2 after
its payload was restored:
# merge: add or change keys, leave the rest untouched
client.set_payload("products", payload={"price": 79, "on_sale": True}, points=[2], wait=True)
# {'name': ..., 'category': 'audio', 'price': 79, 'brand': 'globex', ..., 'on_sale': True}
# remove individual keys
client.delete_payload("products", keys=["on_sale"], points=[2], wait=True)
# replace the whole payload, keeping the vector
client.overwrite_payload("products", payload={"name": "Bluetooth speaker", "price": 89}, points=[2], wait=True)
# remove the whole payload
client.clear_payload("products", points_selector=models.PointIdsList(points=[2]), wait=True)
# replace only the vector, keeping the payload
client.update_vectors("products", points=[models.PointVectors(id=6, vector=[0.1, 0.1, 0.8, 0.3])], wait=True)
| Operation | REST endpoint | Effect on the payload |
|---|---|---|
|
|
Merges the given keys into the existing payload. |
|
|
Replaces the whole payload. |
|
|
Removes the listed keys only. |
|
|
Removes the entire payload. |
Each of these also accepts a filter instead of an explicit list of ids, so
{"payload":{"on_sale":true},"filter":{"must":[{"key":"brand","match":{"value":"initech"}}]}} puts every Initech
product on sale in one request. After update_vectors the retrieved vector for point 6 is the normalized
[0.11547006, 0.11547006, 0.9237605, 0.34641019] — the vector changed and the payload is intact.
Delete points
Points can be deleted either by an explicit list of ids or by a filter that matches on payload conditions — the same filter syntax used to narrow a search, covered in Filtering & Payload Indexing.
from qdrant_client.models import Filter, FieldCondition, MatchValue, PointIdsList, FilterSelector
# By id list.
client.delete(
collection_name="products",
points_selector=PointIdsList(points=[1, 2, 3]),
)
# By filter: every point whose payload matches, regardless of id.
client.delete(
collection_name="products",
points_selector=FilterSelector(
filter=Filter(
must=[FieldCondition(key="in_stock", match=MatchValue(value=False))]
)
),
)
A filter-based delete can match and remove an unbounded number of points in one call — there is no need to
first page through matches and delete them one id at a time. On the catalog, the filter above removes the two
out-of-stock products (the soundbar and the espresso machine) and leaves four points; a second delete by explicit ids
that no longer exist is not an error, it simply removes nothing. A delete first marks points as removed; the space is
reclaimed later when the optimizer vacuums the affected segments (its deleted_threshold, 0.2 by default, is the
fraction of deleted vectors that triggers it).
Deleting is one of the few operations where a filter is dangerous without a safety net: a filter that accidentally
matches everything deletes everything. Run the same filter through client.count(..., count_filter=...) first and
check the number.
The scroll API: paging over all points
Retrieving a collection’s full contents — for a export, a migration, or a background job — does not go
through vector search at all, since search always needs a query vector to rank against. Instead, the
Scroll API pages through all points in a
collection (optionally narrowed by a filter) independently of any similarity ranking: each call takes a
limit and returns that many points plus a next_page_offset cursor, which is passed as the offset on the
next call. Iteration stops once next_page_offset comes back null (or the page is empty), meaning there is
nothing left to fetch.
next_offset = None
all_points = []
while True:
points, next_offset = client.scroll(
collection_name="products",
limit=100,
offset=next_offset,
with_payload=True,
with_vectors=False,
)
all_points.extend(points)
if next_offset is None:
break
print(f"scrolled {len(all_points)} points")
On the six-product catalog with limit=4 the loop makes two calls, and the cursor is simply the id of the first
point of the next page:
page 1 -> ids [1, 2, 3, 4] next_page_offset = 5
page 2 -> ids [5, 6] next_page_offset = null
Over REST the same pagination is POST /collections/products/points/scroll with {"limit":2,"offset":3}, which
returns points 3 and 4 and "next_page_offset":5. Scroll accepts the same filter as a search, so an export of
only the in-stock products is one scroll with a filter. By default points come back in id order; to page in payload
order instead, pass order_by. That needs a payload index on the field (otherwise the server answers
No range index for order_by key: price), and it pages by value rather than by an opaque offset:
client.create_payload_index("products", "price", models.PayloadSchemaType.INTEGER)
points, _ = client.scroll("products", limit=3, with_payload=["name", "price"],
order_by=models.OrderBy(key="price", direction=models.Direction.ASC))
print([(p.payload["name"], p.payload["price"]) for p in points])
# [('Ergonomic mouse', 59), ('Bluetooth speaker', 89), ('Mechanical keyboard', 129)]
Two cheap relatives of scroll are worth knowing: client.count("products", exact=True) returns the number of
points matching an optional filter without transferring any of them, and client.facet("products", key="category")
returns the count per distinct value (audio 3, computing 2, kitchen 1 on this catalog) from a keyword
index.
This is the same offset-forward, "resume after the last cursor I saw" shape as any other cursor-based pagination — see Pagination: Offset vs. Keyset for the general keyset/cursor pattern and why it scales better than a numeric offset; this section only shows the scroll API’s own request/response shape, not that general trade-off again.
Batch upsert and batch delete
Both upsert and delete already accept many points or many ids in a single request — the examples above
already send lists rather than one point/id per call, and that is the primary batching lever: fewer network
round trips, and the server can apply the whole set as one write. For a very large upsert (millions of
points, or vectors too large to build as one in-memory list) it still pays to split the upsert into batches
of a bounded size, so memory usage and any one request’s payload size stay predictable regardless of the total
data volume:
def batched(iterable, size):
batch = []
for item in iterable:
batch.append(item)
if len(batch) == size:
yield batch
batch = []
if batch:
yield batch
def all_points():
# A generator over however many points need to be upserted, e.g. read
# from a file or another database rather than held in memory at once.
for i in range(1, 1_000_001):
yield PointStruct(
id=i,
vector=[0.0] * 4,
payload={"category": "audio"},
)
for batch in batched(all_points(), size=256):
client.upsert(collection_name="products", points=batch)
Batch deletes follow the same shape: a PointIdsList (or a FilterSelector) sent in one delete call removes
every id/match in that call, so splitting a huge id-based delete into chunks of, say, a few thousand ids at a
time bounds request size the same way batched upserts do.
The Python client already ships this loop. upload_points (and upload_collection for parallel arrays of ids and
vectors) takes any iterable, cuts it into batches and can use several worker processes. Loading 500 generated
points in batches of 128 into the catalog and then deleting them again by a text filter looks like this, with the
counts it printed:
client.upload_points(
"products",
points=(models.PointStruct(id=100 + i, vector=[0.0, 0.0, 0.1 * i, 1.0], payload={"name": f"bulk {i}"})
for i in range(1, 501)),
batch_size=128,
wait=True,
)
print(client.count("products").count) # 504 = 4 catalog points + 500 uploaded
client.delete("products", wait=True, points_selector=models.FilterSelector(
filter=models.Filter(must=[models.FieldCondition(key="name", match=models.MatchText(text="bulk"))])))
print(client.count("products").count) # 4
Several different writes can also be sent as one ordered request with the batch endpoint, which applies them in
sequence and returns one operation_id per step. This request upserts a travel adapter, changes its price and deletes
the espresso machine, and Qdrant answered with three completed operations:
curl -X POST 'http://localhost:6333/collections/products/points/batch?wait=true' \
-H 'Content-Type: application/json' \
-d '{"operations":[
{"upsert":{"points":[{"id":7,"vector":[0.2,0.2,0.2,0.9],"payload":{"name":"Travel adapter","price":19}}]}},
{"set_payload":{"payload":{"price":17},"points":[7]}},
{"delete":{"points":[6]}}
]}'
The batch is not a transaction: if the second operation fails the first stays applied. Use it to save round trips, not to get atomicity.
The Java/Kotlin client (io.qdrant:client) exposes the same batch-upsert call, built around protobuf
PointStruct messages and a list passed to upsertAsync. The snippet below compiles against
io.qdrant:client:1.20.0 and can be dropped into the Demo class from
Getting Started:
import io.qdrant.client.grpc.Points.PointStruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static io.qdrant.client.PointIdFactory.id;
import static io.qdrant.client.ValueFactory.value;
import static io.qdrant.client.VectorsFactory.vectors;
List<PointStruct> batch = new ArrayList<>();
for (long i = 1; i <= 256; i++) {
batch.add(PointStruct.newBuilder()
.setId(id(i))
.setVectors(vectors(0.12f, -0.98f, 0.33f, 0.47f))
.putAllPayload(Map.of("category", value("audio")))
.build());
}
client.upsertAsync("products", batch).get();
As with the Python example, a huge total point count should still be split across several upsertAsync calls
of a fixed batch size rather than assembled into one very large List<PointStruct>.
Where to go next
-
Pagination: Offset vs. Keyset — the general offset-vs-keyset cursor pattern the scroll API’s
next_page_offsetfollows; this page deliberately did not re-derive that trade-off, only the scroll API’s own shape. -
Hybrid & Sparse Search — combining dense and sparse vector search, the previous topic in this reference’s reading order.
-
Clustering & Storage — how a collection’s points are sharded and replicated across a cluster once write volume outgrows a single node.