File size: 1,264 Bytes
feb5410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import shutil
import os
from app.core.config import QDRANT_PATH, COLLECTION_NAME, CATEGORIES
from qdrant_client import QdrantClient

def clear_vector_db():
    print(f"Checking Qdrant database at: {QDRANT_PATH}")
    try:
        client = QdrantClient(path=QDRANT_PATH)
        all_collections = CATEGORIES + [COLLECTION_NAME]
        
        for coll in all_collections:
            if client.collection_exists(coll):
                print(f"Deleting collection: {coll}")
                client.delete_collection(coll)
            else:
                print(f"Collection {coll} does not exist.")
    except Exception as e:
        print(f"Error deleting collections via client: {e}")
    if os.path.exists(QDRANT_PATH):
        print(f"Removing storage directory: {QDRANT_PATH}")
        try:
            shutil.rmtree(QDRANT_PATH)
            print("Successfully removed VectorDB directory.")
        except Exception as e:
            print(f"Error removing directory: {e}")
    else:
        print("VectorDB directory already cleared.")

if __name__ == "__main__":
    confirm = input("This will delete all existing vector data. Are you sure? (y/n): ")
    if confirm.lower() == 'y':
        clear_vector_db()
    else:
        print("Operation cancelled.")