From 314fc8ac948ecc87fefdea572561ce1e06633696 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 24 Sep 2025 12:16:35 +0200 Subject: [PATCH] =?UTF-8?q?scripts/debug=5Fqdrant=5Fstate.py=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/debug_qdrant_state.py | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 scripts/debug_qdrant_state.py diff --git a/scripts/debug_qdrant_state.py b/scripts/debug_qdrant_state.py new file mode 100644 index 0000000..7d363ab --- /dev/null +++ b/scripts/debug_qdrant_state.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +scripts/debug_qdrant_state.py +Zeigt Prefix, Collections und einfache Counts (notes/chunks/edges) + sample note_ids. + +Aufruf: + export COLLECTION_PREFIX="mindnet" + python3 -m scripts.debug_qdrant_state + # oder: + python3 -m scripts.debug_qdrant_state --prefix mindnet +""" +from __future__ import annotations +import argparse, os, json +from app.core.qdrant import QdrantConfig, get_client + +def count_points(client, collection: str) -> int: + try: + res = client.count(collection, exact=True) + return int(getattr(res, "count", 0)) + except Exception: + pts, _ = client.scroll(collection, limit=1) + return 1 if pts else 0 + +def sample_ids(client, collection: str, id_key: str, limit: int = 5): + pts, _ = client.scroll(collection, with_payload=True, with_vectors=False, limit=limit) + out = [] + for p in pts or []: + pl = p.payload or {} + if id_key in pl: + out.append(pl[id_key]) + return out + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--prefix", default=os.environ.get("COLLECTION_PREFIX", "mindnet")) + args = ap.parse_args() + + cfg = QdrantConfig.from_env() + cfg.prefix = args.prefix + client = get_client(cfg) + + notes = f"{cfg.prefix}_notes" + chunks = f"{cfg.prefix}_chunks" + edges = f"{cfg.prefix}_edges" + + print(json.dumps({ + "prefix": cfg.prefix, + "collections": {"notes": notes, "chunks": chunks, "edges": edges}, + "counts": { + "notes": count_points(client, notes), + "chunks": count_points(client, chunks), + "edges": count_points(client, edges), + }, + "samples": { + "notes.note_id": sample_ids(client, notes, "note_id"), + "chunks.note_id": sample_ids(client, chunks, "note_id"), + "edges.note_id": sample_ids(client, edges, "note_id"), + } + }, ensure_ascii=False, indent=2)) + +if __name__ == "__main__": + main()