Spaces:
Sleeping
Sleeping
Download scripts/68_clone_qdrant_for_eval.py from juhaha1230/AI_Menu_Search: direct link, hf CLI and curl.
- Browser
- Download file 2.5 kB
-
https://huggingface.co/spaces/juhaha1230/AI_Menu_Search/resolve/main/scripts/68_clone_qdrant_for_eval.py
- Command line
-
hf download hf://spaces/juhaha1230/AI_Menu_Search/scripts/68_clone_qdrant_for_eval.py
-
curl -L -o 68_clone_qdrant_for_eval.py https://huggingface.co/spaces/juhaha1230/AI_Menu_Search/resolve/main/scripts/68_clone_qdrant_for_eval.py
2.5 kB
| """Clone legacy Qdrant collections into isolated version-aware eval copies.""" | |
| from __future__ import annotations | |
| import argparse | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| from qdrant_client.models import Distance, PayloadSchemaType, PointStruct, VectorParams | |
| from config import EMBEDDING_DIM | |
| from core.qdrant_conn import get_qdrant_client | |
| def _clone(source: str, target: str, app_version: str) -> int: | |
| client = get_qdrant_client() | |
| existing = {item.name for item in client.get_collections().collections} | |
| if source not in existing: | |
| raise SystemExit(f"source collection missing: {source}") | |
| if target in existing: | |
| raise SystemExit(f"target collection already exists: {target}") | |
| client.create_collection( | |
| collection_name=target, | |
| vectors_config=VectorParams(size=EMBEDDING_DIM, distance=Distance.COSINE), | |
| ) | |
| client.create_payload_index( | |
| collection_name=target, | |
| field_name="app_version", | |
| field_schema=PayloadSchemaType.KEYWORD, | |
| ) | |
| copied = 0 | |
| offset = None | |
| while True: | |
| points, offset = client.scroll( | |
| collection_name=source, | |
| limit=256, | |
| offset=offset, | |
| with_payload=True, | |
| with_vectors=True, | |
| ) | |
| batch = [] | |
| for point in points: | |
| payload = dict(point.payload or {}) | |
| payload["app_version"] = app_version | |
| batch.append( | |
| PointStruct(id=point.id, vector=point.vector, payload=payload) | |
| ) | |
| if batch: | |
| client.upsert(collection_name=target, points=batch) | |
| copied += len(batch) | |
| if offset is None: | |
| break | |
| return copied | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--source-menu", default="herogun_menus") | |
| parser.add_argument("--source-query", default="herogun_queries") | |
| parser.add_argument("--target-menu", required=True) | |
| parser.add_argument("--target-query", required=True) | |
| parser.add_argument("--app-version", default="1.5.5") | |
| args = parser.parse_args() | |
| menu_count = _clone(args.source_menu, args.target_menu, args.app_version) | |
| query_count = _clone(args.source_query, args.target_query, args.app_version) | |
| print( | |
| f"cloned menu={menu_count} query={query_count} " | |
| f"app_version={args.app_version}" | |
| ) | |
| if __name__ == "__main__": | |
| main() | |