|
|
|
|
|
from __future__ import annotations |
|
|
|
|
|
import json |
|
|
import os |
|
|
import sys |
|
|
from typing import Any, Dict |
|
|
|
|
|
import requests |
|
|
|
|
|
|
|
|
QDRANT_URL = os.environ.get("QDRANT_URL", "http://localhost:17000") |
|
|
COLLECTION = os.environ.get("QDRANT_COLLECTION", "elizabeth_embeddings") |
|
|
VECTOR_SIZE = int(os.environ.get("QDRANT_VECTOR_SIZE", "1536")) |
|
|
DISTANCE = os.environ.get("QDRANT_DISTANCE", "Cosine") |
|
|
|
|
|
|
|
|
def ensure_collection() -> Dict[str, Any]: |
|
|
r = requests.get(f"{QDRANT_URL}/collections/{COLLECTION}", timeout=5) |
|
|
if r.status_code == 200: |
|
|
return {"status": "exists"} |
|
|
payload = { |
|
|
"vectors": {"size": VECTOR_SIZE, "distance": DISTANCE}, |
|
|
"hnsw_config": {"m": 64, "ef_construct": 128, "full_scan_threshold": 10000}, |
|
|
"optimizers_config": {"default_segment_number": 2}, |
|
|
} |
|
|
r = requests.put(f"{QDRANT_URL}/collections/{COLLECTION}", json=payload, timeout=30) |
|
|
return {"status": "created", "code": r.status_code, "body": r.text} |
|
|
|
|
|
|
|
|
def main() -> None: |
|
|
try: |
|
|
res = ensure_collection() |
|
|
print(json.dumps(res)) |
|
|
except Exception as e: |
|
|
print(json.dumps({"error": str(e)})) |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|