95 lines
2.3 KiB
Python
95 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Name: scripts/reset_qdrant.py
|
|
Version: v1.0.0 (2025-09-04)
|
|
Kurzbeschreibung:
|
|
Löscht entweder die gesamten mindnet-Collections (Wipe) und legt sie gemäß
|
|
Projekt-Defaults neu an, oder löscht nur alle Punkte (Truncate), wobei die
|
|
Collection-Konfiguration erhalten bleibt.
|
|
|
|
|
|
Aufruf (aus Projekt-Root, im venv):
|
|
python3 -m scripts.reset_qdrant --mode wipe [--prefix PREFIX]
|
|
python3 -m scripts.reset_qdrant --mode truncate [--prefix PREFIX]
|
|
|
|
|
|
Parameter:
|
|
--mode wipe | truncate
|
|
--prefix Collection-Prefix (Default: env COLLECTION_PREFIX oder 'mindnet')
|
|
|
|
|
|
Umgebungsvariablen (optional):
|
|
QDRANT_URL, QDRANT_API_KEY, COLLECTION_PREFIX, VECTOR_DIM (Default 384)
|
|
|
|
|
|
Hinweise:
|
|
- Wipe: Collections werden komplett gelöscht und via ensure_collections() neu
|
|
erstellt (Notes/Chunks: 384d/COSINE; Edges: 1d/DOT).
|
|
- Truncate: löscht nur Points (behält Settings/Indexing).
|
|
|
|
|
|
Changelog:
|
|
v1.0.0: Initiale Version.
|
|
"""
|
|
from __future__ import annotations
|
|
import argparse
|
|
|
|
|
|
from qdrant_client import QdrantClient
|
|
from qdrant_client.http import models as rest
|
|
|
|
|
|
from app.core.qdrant import QdrantConfig, get_client, ensure_collections, collection_names
|
|
|
|
|
|
|
|
|
|
def delete_all_points(client: QdrantClient, collections):
|
|
match_all = rest.Filter(must=[])
|
|
for col in collections:
|
|
if client.collection_exists(col):
|
|
client.delete_points(collection_name=col, points_selector=match_all, wait=True)
|
|
|
|
|
|
|
|
|
|
def wipe_collections(client: QdrantClient, collections):
|
|
for col in collections:
|
|
if client.collection_exists(col):
|
|
client.delete_collection(col)
|
|
|
|
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser(description="Wipe oder truncate mindnet-Collections in Qdrant.")
|
|
ap.add_argument("--mode", choices=["wipe", "truncate"], required=True,
|
|
help="wipe = Collections löschen & neu anlegen; truncate = nur Inhalte löschen")
|
|
ap.add_argument("--prefix", help="Collection-Prefix (Default: env COLLECTION_PREFIX oder 'mindnet')")
|
|
args = ap.parse_args()
|
|
|
|
|
|
cfg = QdrantConfig.from_env()
|
|
if args.prefix:
|
|
cfg.prefix = args.prefix
|
|
|
|
|
|
client = get_client(cfg)
|
|
notes, chunks, edges = collection_names(cfg.prefix)
|
|
cols = [notes, chunks, edges]
|
|
|
|
|
|
if args.mode == "wipe":
|
|
wipe_collections(client, cols)
|
|
ensure_collections(client, cfg.prefix, cfg.dim)
|
|
print(f"Wiped & recreated: {cols}")
|
|
else:
|
|
delete_all_points(client, cols)
|
|
print(f"Truncated (deleted all points in): {cols}")
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |