dmpantiu commited on
Commit
320004c
·
verified ·
1 Parent(s): d222880

server kit: in-collection resume + async upserts + batch 512

Browse files
Files changed (1) hide show
  1. server/load_all.py +41 -27
server/load_all.py CHANGED
@@ -33,7 +33,7 @@ TARBALLS = {
33
  "qdrant_eqc_qa.tar.gz": ["eqc_qa"],
34
  "qdrant_publications.tar.gz": ["publications"],
35
  }
36
- BATCH = 256
37
 
38
  # The embedded (local-mode) indexes cannot persist payload indexes, so they are
39
  # re-created here exactly as the original loaders defined them.
@@ -97,46 +97,60 @@ def migrate_collection(local: QdrantClient, remote: QdrantClient,
97
  info = local.get_collection(coll)
98
  total = local.count(coll).count
99
 
 
100
  if remote.collection_exists(coll):
101
  have = remote.count(coll).count
102
  if have == total and not recreate:
103
  log(f"{coll}: server already has {have}/{total} points — skip "
104
  f"(--recreate to force)")
105
  return
106
- log(f"{coll}: server has {have}/{total} recreating")
107
- remote.delete_collection(coll)
108
-
109
- remote.create_collection(
110
- collection_name=coll,
111
- vectors_config=info.config.params.vectors,
112
- sparse_vectors_config=info.config.params.sparse_vectors,
113
- on_disk_payload=True,
114
- )
115
- indexes = {f: s.data_type for f, s in (info.payload_schema or {}).items()}
116
- if not indexes:
117
- indexes = PAYLOAD_INDEXES.get(coll, {})
118
- for field, schema in indexes.items():
119
- remote.create_payload_index(collection_name=coll, field_name=field,
120
- field_schema=schema)
121
- log(f"{coll}: created (vectors={list(info.config.params.vectors)}, "
122
- f"sparse={list(info.config.params.sparse_vectors or {})}, "
123
- f"payload indexes={list(indexes)})")
124
-
125
- done, offset, t0 = 0, None, time.time()
 
 
 
 
 
 
 
 
126
  while True:
127
  points, offset = local.scroll(coll, limit=BATCH, offset=offset,
128
  with_payload=True, with_vectors=True)
129
  if not points:
130
  break
131
- remote.upsert(coll, points=[
132
- models.PointStruct(id=p.id, vector=p.vector, payload=p.payload)
133
- for p in points])
134
- done += len(points)
135
- if done % (BATCH * 40) == 0 or offset is None:
 
 
 
 
136
  rate = done / max(time.time() - t0, 1e-9)
137
- log(f"{coll}: {done}/{total} ({rate:.0f} pts/s)")
138
  if offset is None:
139
  break
 
140
 
141
  got = remote.count(coll).count
142
  status = "OK" if got == total else "MISMATCH"
 
33
  "qdrant_eqc_qa.tar.gz": ["eqc_qa"],
34
  "qdrant_publications.tar.gz": ["publications"],
35
  }
36
+ BATCH = 512
37
 
38
  # The embedded (local-mode) indexes cannot persist payload indexes, so they are
39
  # re-created here exactly as the original loaders defined them.
 
97
  info = local.get_collection(coll)
98
  total = local.count(coll).count
99
 
100
+ skip_first = 0
101
  if remote.collection_exists(coll):
102
  have = remote.count(coll).count
103
  if have == total and not recreate:
104
  log(f"{coll}: server already has {have}/{total} points — skip "
105
  f"(--recreate to force)")
106
  return
107
+ if recreate or have == 0 or have > total:
108
+ log(f"{coll}: server has {have}/{total} — recreating")
109
+ remote.delete_collection(coll)
110
+ else:
111
+ # Interrupted copy: local scroll order is deterministic and
112
+ # upserts are idempotent, so resume with an overlap margin.
113
+ skip_first = max(0, have - 8 * BATCH)
114
+ log(f"{coll}: server has {have}/{total} — resuming from "
115
+ f"~{skip_first} (with overlap)")
116
+
117
+ if not remote.collection_exists(coll):
118
+ remote.create_collection(
119
+ collection_name=coll,
120
+ vectors_config=info.config.params.vectors,
121
+ sparse_vectors_config=info.config.params.sparse_vectors,
122
+ on_disk_payload=True,
123
+ )
124
+ indexes = {f: s.data_type for f, s in (info.payload_schema or {}).items()}
125
+ if not indexes:
126
+ indexes = PAYLOAD_INDEXES.get(coll, {})
127
+ for field, schema in indexes.items():
128
+ remote.create_payload_index(collection_name=coll, field_name=field,
129
+ field_schema=schema)
130
+ log(f"{coll}: created (vectors={list(info.config.params.vectors)}, "
131
+ f"sparse={list(info.config.params.sparse_vectors or {})}, "
132
+ f"payload indexes={list(indexes)})")
133
+
134
+ done, seen, offset, t0 = 0, 0, None, time.time()
135
  while True:
136
  points, offset = local.scroll(coll, limit=BATCH, offset=offset,
137
  with_payload=True, with_vectors=True)
138
  if not points:
139
  break
140
+ seen += len(points)
141
+ if seen > skip_first:
142
+ batch = points if seen - len(points) >= skip_first else \
143
+ points[-(seen - skip_first):]
144
+ remote.upsert(coll, wait=False, points=[
145
+ models.PointStruct(id=p.id, vector=p.vector, payload=p.payload)
146
+ for p in batch])
147
+ done += len(batch)
148
+ if seen % (BATCH * 40) == 0 or offset is None:
149
  rate = done / max(time.time() - t0, 1e-9)
150
+ log(f"{coll}: {skip_first + done}/{total} ({rate:.0f} pts/s live)")
151
  if offset is None:
152
  break
153
+ time.sleep(2) # let async upserts settle before the count check
154
 
155
  got = remote.count(coll).count
156
  status = "OK" if got == total else "MISMATCH"