File size: 1,231 Bytes
503b0e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
import os, sys, time
import requests

QDRANT_URL = os.environ.get("QDRANT_URL", "http://127.0.0.1:17000")

COLLECTION = {
    "name": "elizabeth_embeddings",
    "config": {
        "vectors": {"size": 1536, "distance": "Cosine"},
        "hnsw_config": {"m": 64, "ef_construct": 128, "full_scan_threshold": 10000},
        "optimizers_config": {"default_segment_number": 2}
    }
}

def ensure_collection():
    name = COLLECTION["name"]
    cfg = COLLECTION["config"]
    r = requests.get(f"{QDRANT_URL}/collections")
    r.raise_for_status()
    names = [c.get("name") for c in r.json().get("result", {}).get("collections", [])]
    if name in names:
        print(f"Collection exists: {name}")
        return
    # Create
    put = requests.put(f"{QDRANT_URL}/collections/{name}", json=cfg)
    if put.status_code not in (200, 201):
        print(f"Failed to create {name}: {put.status_code} {put.text}")
        sys.exit(1)
    print(f"Created collection: {name}")

if __name__ == "__main__":
    for _ in range(10):
        try:
            ensure_collection()
            sys.exit(0)
        except Exception as e:
            print(f"Bootstrap retry: {e}")
            time.sleep(2)
    sys.exit(1)