Skip to content

Instantly share code, notes, and snippets.

@kenn
Created April 30, 2023 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenn/aa2f09b2e0772648d42bdb1e26ad3569 to your computer and use it in GitHub Desktop.
Save kenn/aa2f09b2e0772648d42bdb1e26ad3569 to your computer and use it in GitHub Desktop.
def scroll_merge(klass, source_names, target_name, batch_size = 100):
Qdrant.recreate(target_name) # reset target collection
def generator(source_name):
offset = None
while True:
# Scroll https://qdrant.tech/documentation/points/#scroll-points
# https://github.com/qdrant/qdrant-client/blob/master/qdrant_client/qdrant_client.py#L412
result = Qdrant.client.scroll(
collection_name=source_name,
offset=offset,
limit=batch_size,
with_payload=True,
with_vectors=True,
)
points = result[0]
offset = result[1]
if points:
yield points
if offset is None:
break
for source_name in source_names:
for points in generator(source_name):
print(f'Upserting {len(points)} points from {source_name} to {target_name}...', flush=True)
Qdrant.client.upsert(
collection_name=target_name,
points=points,
wait=True,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment