Appearance
批量操作
为什么需要批量
高维向量 + 大量点:单条 HTTP 请求效率低。批量 upsert 可减少往返次数,提高吞吐。
Python 批量 Upsert
python
from qdrant_client.models import PointStruct
def chunks(lst, n):
for i in range(0, len(lst), n):
yield lst[i : i + n]
all_points = [
PointStruct(id=i, vector=[0.01 * (i % 10)] * 384, payload={"idx": i})
for i in range(1000)
]
for batch in chunks(all_points, 200):
client.upsert(collection_name="demo_text", points=batch)Java 批量
将 List<PointStruct> 分批调用 upsertAsync,每批大小与 Python 类似,注意 gRPC 消息大小限制;超大 batch 可能需调大服务端或客户端限制。
并发写入
多线程/多进程同时 upsert 不同 id 通常安全;同一 id 并发 upsert 可能产生后写覆盖。可用队列串行化同一 id 的更新。
导入后建索引
若先大批量导入再统一建 payload 索引,有时更利于导入速度;具体以数据量与官方建议为准。
下一篇进入 检索:向量搜索、过滤、滚动。