This commit is contained in:
1 parent
23b1cb2966
commit
e9532e8878
30 files changed
+1835
-542
No files matched your search
@@ -1,50 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
# scripts/gc_qdrant_after_vault_scan.py
|
||||
# Version: 1.0.0 (2025-09-05)
|
||||
#
|
||||
# Zweck
|
||||
# -----
|
||||
# Garbage-Collector für Qdrant: löscht Einträge (Edges, Chunks, Notes), deren Note-ID
|
||||
# nicht mehr im Obsidian-Vault vorhanden ist. So bleiben Vektorindex/Graph mit dem Vault konsistent.
|
||||
#
|
||||
# Aufrufparameter
|
||||
# ---------------
|
||||
# --vault PATH Pfad zum Obsidian-Vault (z. B. ./vault) [erforderlich]
|
||||
# --mode {edges,content,all}
|
||||
# edges -> nur Kanten mit source_id/target_id ∉ Vault-Notes löschen
|
||||
# content -> Chunks & Notes löschen, deren note_id ∉ Vault-Notes (keine Edges)
|
||||
# all -> zuerst edges, dann content
|
||||
# --prefix PREFIX Collection-Präfix (Default: aus ENV COLLECTION_PREFIX oder "mindnet")
|
||||
# --apply Ohne diesen Schalter: Dry-Run (nur Vorschau). Mit Schalter: ausführen.
|
||||
# --yes Sicherheitsabfrage überspringen (non-interaktiv)
|
||||
# --batch-size N Größe für In-Filter (Default: 1000)
|
||||
#
|
||||
# Hinweise
|
||||
# --------
|
||||
# - Benötigt funktionierendes Python-venv mit allen Abhängigkeiten von mindnet (qdrant-client usw.).
|
||||
# - Läuft gegen die drei Collections {prefix}_notes, {prefix}_chunks, {prefix}_edges (keine anderen Projekte).
|
||||
# - Nutzt OR-Filter (Filter.should) korrekt, keine minimum_should (Pydantic v2 lässt die Option nicht zu).
|
||||
#
|
||||
# Änderungen ggü. vorher
|
||||
# ----------------------
|
||||
# - Neu: eigenes GC-Tool; berührt ausschließlich das übergebene Projekt-Präfix.
|
||||
# - Sichere Dry-Run-Vorschau mit Zählung pro Collection; interaktive Bestätigung.
|
||||
# - Löscht Edges mittels Filter auf (source_id ∈ MISSING) ODER (target_id ∈ MISSING).
|
||||
# - Löscht Chunks/Notes mittels Filter auf note_id ∈ MISSING.
|
||||
#
|
||||
# Beispiele
|
||||
# ---------
|
||||
# DRY RUN: python3 -m scripts.gc_qdrant_after_vault_scan --vault ./vault --mode all
|
||||
# APPLY: python3 -m scripts.gc_qdrant_after_vault_scan --vault ./vault --mode all --apply
|
||||
# CI-Modus: python3 -m scripts.gc_qdrant_after_vault_scan --vault ./vault --mode edges --apply --yes
|
||||
#
|
||||
# Kompatibilität / Kontext
|
||||
# ------------------------
|
||||
# - Frontmatter-Validierung & Parsing wie im Projekt (parser.read_markdown, validate_required_frontmatter). :contentReference[oaicite:0]{index=0}
|
||||
# - Note-Payload-Schema (u. a. note_id, hash_fulltext) wie spezifiziert. :contentReference[oaicite:1]{index=1}
|
||||
# - Collection-Namen & Anlage-Logik über app.core.qdrant (notes/chunks = dim, edges = 1D). :contentReference[oaicite:2]{index=2}
|
||||
# - Edges nutzen Felder source_id/target_id; Chunks/Notes tragen note_id in payload. :contentReference[oaicite:3]{index=3} :contentReference[oaicite:4]{index=4}
|
||||
#
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
FILE: scripts/gc_qdrant_after_vault_scan.py
|
||||
VERSION: 2.1.0 (2025-12-15)
|
||||
STATUS: Active
|
||||
COMPATIBILITY: v2.9.1 (Post-WP14/WP-15b)
|
||||
|
||||
Zweck:
|
||||
-------
|
||||
Garbage-Collector für Qdrant: löscht Einträge, deren Note-ID nicht mehr
|
||||
im Vault vorhanden ist. Hält Vektorindex/Graph mit dem Vault konsistent.
|
||||
|
||||
Funktionsweise:
|
||||
---------------
|
||||
1. Scannt Vault und sammelt alle note_ids
|
||||
2. Lädt note_ids aus Qdrant
|
||||
3. Berechnet Differenz (verwaiste IDs)
|
||||
4. Löscht verwaiste Einträge:
|
||||
- mode=edges: Nur Edges mit source_id/target_id ∉ Vault
|
||||
- mode=content: Chunks & Notes mit note_id ∉ Vault
|
||||
- mode=all: Zuerst edges, dann content
|
||||
5. Nutzt Batch-Filter für effiziente Löschung
|
||||
|
||||
Ergebnis-Interpretation:
|
||||
------------------------
|
||||
- Ausgabe: JSON mit Preview und Statistiken
|
||||
* mode: DRY-RUN oder APPLY
|
||||
* vault_note_ids: Anzahl Notizen im Vault
|
||||
* qdrant_note_ids: Anzahl Notizen in Qdrant
|
||||
* orphans: Anzahl verwaister Notizen
|
||||
* deleted: Anzahl gelöschter Einträge (nach --apply)
|
||||
- Exit-Code 0: Erfolgreich
|
||||
|
||||
Verwendung:
|
||||
-----------
|
||||
- Regelmäßige Wartung nach Vault-Bereinigung
|
||||
- Konsistenz-Check zwischen Vault und Datenbank
|
||||
- Vor Migrationen
|
||||
|
||||
Sicherheitsmerkmale:
|
||||
-------------------
|
||||
- Dry-Run standardmäßig (keine Änderungen ohne --apply)
|
||||
- Interaktive Bestätigung (außer mit --yes)
|
||||
- Nur betroffene Collections werden geändert
|
||||
|
||||
Aufruf:
|
||||
-------
|
||||
python3 -m scripts.gc_qdrant_after_vault_scan --vault ./vault --mode all
|
||||
python3 -m scripts.gc_qdrant_after_vault_scan --vault ./vault --mode all --apply
|
||||
python3 -m scripts.gc_qdrant_after_vault_scan --vault ./vault --mode edges --apply --yes
|
||||
|
||||
Parameter:
|
||||
----------
|
||||
--vault PATH Pfad zum Vault-Verzeichnis (erforderlich)
|
||||
--mode MODE edges | content | all (Default: all)
|
||||
- edges: Nur Edges löschen
|
||||
- content: Nur Chunks & Notes löschen
|
||||
- all: Beides (zuerst edges, dann content)
|
||||
--prefix TEXT Collection-Präfix (Default: ENV COLLECTION_PREFIX oder mindnet)
|
||||
--apply Führt tatsächliches Löschen durch (sonst Dry-Run)
|
||||
--yes Keine interaktive Bestätigung
|
||||
--batch-size N Batch-Größe für Filter (Default: 1000)
|
||||
|
||||
Änderungen:
|
||||
-----------
|
||||
v2.1.0 (2025-12-15): Kompatibilität mit WP-14 Modularisierung
|
||||
- Aktualisiert: Import-Pfade für neue Struktur
|
||||
v1.0.0 (2025-09-05): Initial Release
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import argparse, os, glob, json, sys
|
||||
from typing import Iterable, Set, Tuple, List
|
||||
|
||||
Reference in new issue
Block a user