File size: 1,472 Bytes
c838634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
scripts/export_vectors.py
─────────────────────────
Dumps all Qdrant vectors + payloads to data/vectors.json

This file is committed to git so HF Spaces can import vectors on startup
without needing to re-run CLIP (which takes 5+ minutes on CPU).

Import takes ~3 seconds for 541 vectors vs ~10 minutes for full re-indexing.

Run:
    python scripts/export_vectors.py
"""

import json
import pathlib
from qdrant_client import QdrantClient
from app.config import settings

DATA = pathlib.Path("data")
OUT  = DATA / "vectors.json"

def export():
    client = QdrantClient(host=settings.qdrant_host, port=settings.qdrant_port)

    print(f"Fetching all points from '{settings.collection_name}'...")
    points, offset = [], None
    while True:
        batch, offset = client.scroll(
            collection_name=settings.collection_name,
            with_vectors=True,
            with_payload=True,
            limit=256,
            offset=offset,
        )
        points.extend(batch)
        print(f"  fetched {len(points)} so far...")
        if offset is None:
            break

    data = [
        {"id": p.id, "vector": p.vector, "payload": p.payload}
        for p in points
    ]

    OUT.write_text(json.dumps(data, indent=None, separators=(",", ":")))
    size = OUT.stat().st_size / 1024
    print(f"\nβœ… Exported {len(data)} vectors β†’ {OUT}  ({size:.0f} KB)")

if __name__ == "__main__":
    export()