File size: 1,670 Bytes
3a82c7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
"""Initialize the Qdrant collection for AdaptiveRAG.

Useful when bootstrapping a fresh Qdrant deployment (Docker / Cloud) before
running the app, or to verify your env vars are wired correctly.

Usage:
    uv run python scripts/init_qdrant.py
    uv run python scripts/init_qdrant.py --recreate
"""

from __future__ import annotations

import argparse
import logging
import sys
from pathlib import Path

# Allow running this script directly from the repo root.
sys.path.insert(0, str(Path(__file__).parent.parent))

from dotenv import load_dotenv  # noqa: E402

from src.indexing import QdrantStore  # noqa: E402

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger("init_qdrant")


def main() -> int:
    parser = argparse.ArgumentParser(description="Initialize Qdrant collection.")
    parser.add_argument(
        "--recreate",
        action="store_true",
        help="Drop the existing collection (if any) before creating.",
    )
    args = parser.parse_args()

    load_dotenv()

    store = QdrantStore()

    if args.recreate:
        try:
            store.client.delete_collection(store.collection_name)
            logger.info(f"Dropped collection '{store.collection_name}'")
        except Exception as exc:
            logger.warning(f"Drop failed (it may not exist yet): {exc}")
        # Re-init to recreate.
        store = QdrantStore()

    total = store.total_chunks()
    logger.info(
        f"Collection '{store.collection_name}' is ready "
        f"({total} existing chunks)."
    )
    return 0


if __name__ == "__main__":
    raise SystemExit(main())