From 566fe813b966989406543455540c119848e960fb Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 4 Sep 2025 16:52:12 +0200 Subject: [PATCH] =?UTF-8?q?scripts/reset=5Fqdrant.py=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/reset_qdrant.py | 95 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 scripts/reset_qdrant.py diff --git a/scripts/reset_qdrant.py b/scripts/reset_qdrant.py new file mode 100644 index 0000000..26d4a50 --- /dev/null +++ b/scripts/reset_qdrant.py @@ -0,0 +1,95 @@ +#!/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() \ No newline at end of file