2025-09-01 17:37:39 +02:00
|
|
|
|
#!/usr/bin/env python3
|
2025-09-05 07:33:05 +02:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2025-09-04 16:42:43 +02:00
|
|
|
|
"""
|
2025-09-09 11:12:33 +02:00
|
|
|
|
Script: import_markdown.py — Markdown → Qdrant (Notes, Chunks, Edges)
|
|
|
|
|
|
Version: 3.1.0
|
|
|
|
|
|
Datum: 2025-09-09
|
|
|
|
|
|
|
|
|
|
|
|
Kurzbeschreibung
|
|
|
|
|
|
----------------
|
|
|
|
|
|
Liest Markdown-Dateien aus einem Vault ein und schreibt Notes, Chunks und Edges
|
|
|
|
|
|
idempotent nach Qdrant. Die Change-Detection basiert standardmäßig ausschließlich
|
|
|
|
|
|
auf dem **Body-Hash** (ENV: MINDNET_HASH_MODE), sodass reine Frontmatter-Änderungen
|
|
|
|
|
|
nicht unnötig Re-Imports auslösen (abwärtskompatibel).
|
|
|
|
|
|
|
|
|
|
|
|
Wichtige Kompatibilitäts-Erweiterung
|
|
|
|
|
|
------------------------------------
|
|
|
|
|
|
- Persistiert nun den **Volltext** der Note im Notes-Payload unter ``fulltext``.
|
|
|
|
|
|
So kann der Export **verlustfrei** rekonstruiert werden, auch wenn die Chunk-
|
|
|
|
|
|
Payloads (noch) kein ``text``-Feld enthalten.
|
|
|
|
|
|
- Speichert den ``path`` **relativ** zum Vault (führt absolute Pfade auf relative
|
|
|
|
|
|
Pfade zurück), sodass Exporte zuverlässig unter ``--out`` landen.
|
|
|
|
|
|
|
|
|
|
|
|
Features
|
|
|
|
|
|
--------
|
|
|
|
|
|
- Deterministische IDs (UUIDv5) über qdrant_points.* (beibehalten)
|
|
|
|
|
|
- Idempotente Upserts für Notes/Chunks/Edges
|
|
|
|
|
|
- Optionale Vorreinigung pro geänderter Note: ``--purge-before-upsert``
|
2025-09-08 18:36:59 +02:00
|
|
|
|
- Robuste Edge-Erzeugung:
|
2025-09-09 11:12:33 +02:00
|
|
|
|
* Chunk-Scope: belongs_to / prev / next / references (+ backlink)
|
|
|
|
|
|
* Fallback-Mode: Note-Scope references, falls chunk_payloads keine references liefern
|
|
|
|
|
|
- Optionaler Note-Embedding-Vektor (``--embed-note``)
|
|
|
|
|
|
|
|
|
|
|
|
Qdrant / ENV
|
|
|
|
|
|
------------
|
|
|
|
|
|
- QDRANT_URL (oder QDRANT_HOST/QDRANT_PORT)
|
|
|
|
|
|
- QDRANT_API_KEY (optional)
|
|
|
|
|
|
- COLLECTION_PREFIX (Default: mindnet)
|
|
|
|
|
|
- VECTOR_DIM (Default: 384)
|
|
|
|
|
|
- MINDNET_HASH_MODE: "body" (Default) | "frontmatter" | "body+frontmatter"
|
|
|
|
|
|
|
|
|
|
|
|
Aufruf
|
|
|
|
|
|
------
|
|
|
|
|
|
python3 -m scripts.import_markdown --vault ./vault
|
|
|
|
|
|
python3 -m scripts.import_markdown --vault ./vault --apply
|
|
|
|
|
|
python3 -m scripts.import_markdown --vault ./vault --apply --purge-before-upsert
|
|
|
|
|
|
python3 -m scripts.import_markdown --vault ./vault --note-id 20250821-foo --apply
|
|
|
|
|
|
# optionaler Note-Vektor
|
|
|
|
|
|
python3 -m scripts.import_markdown --vault ./vault --apply --embed-note
|
|
|
|
|
|
|
|
|
|
|
|
Beispiele
|
|
|
|
|
|
---------
|
|
|
|
|
|
COLLECTION_PREFIX=mindnet QDRANT_URL=http://127.0.0.1:6333 \\
|
2025-09-08 18:36:59 +02:00
|
|
|
|
python3 -m scripts.import_markdown --vault ./vault --apply --purge-before-upsert
|
2025-09-09 11:12:33 +02:00
|
|
|
|
|
|
|
|
|
|
Hinweise
|
|
|
|
|
|
--------
|
|
|
|
|
|
- Dry-Run (ohne --apply) zeigt Entscheidungen je Note als JSON (keine Schreibvorgänge).
|
|
|
|
|
|
- Backfill-Tools existieren weiterhin, werden aber nur als Reparatur eingesetzt.
|
2025-09-04 16:42:43 +02:00
|
|
|
|
"""
|
|
|
|
|
|
|
2025-09-05 11:04:42 +02:00
|
|
|
|
from __future__ import annotations
|
2025-09-09 11:12:33 +02:00
|
|
|
|
|
2025-09-06 14:04:46 +02:00
|
|
|
|
import argparse
|
2025-09-09 11:12:33 +02:00
|
|
|
|
import json
|
2025-09-06 14:04:46 +02:00
|
|
|
|
import os
|
2025-09-09 11:12:33 +02:00
|
|
|
|
import re
|
2025-09-06 14:04:46 +02:00
|
|
|
|
import sys
|
2025-09-09 11:12:33 +02:00
|
|
|
|
from typing import Dict, Iterable, List, Optional, Tuple
|
|
|
|
|
|
|
2025-09-03 07:58:57 +02:00
|
|
|
|
from dotenv import load_dotenv
|
2025-09-09 11:12:33 +02:00
|
|
|
|
import yaml
|
2025-09-05 11:53:59 +02:00
|
|
|
|
from qdrant_client.http import models as rest
|
2025-09-03 07:58:57 +02:00
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# Core/Projekt-Module
|
|
|
|
|
|
from app.core.parser import (
|
|
|
|
|
|
read_markdown,
|
|
|
|
|
|
normalize_frontmatter,
|
|
|
|
|
|
validate_required_frontmatter,
|
|
|
|
|
|
)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
from app.core.note_payload import make_note_payload
|
2025-09-03 07:58:57 +02:00
|
|
|
|
from app.core.validate_note import validate_note_payload
|
|
|
|
|
|
from app.core.chunker import assemble_chunks
|
|
|
|
|
|
from app.core.chunk_payload import make_chunk_payloads
|
2025-09-08 18:36:59 +02:00
|
|
|
|
from app.core.embed import embed_texts, embed_one
|
|
|
|
|
|
from app.core.qdrant import QdrantConfig, get_client, ensure_collections
|
2025-09-06 14:04:46 +02:00
|
|
|
|
from app.core.qdrant_points import (
|
|
|
|
|
|
points_for_chunks,
|
2025-09-08 18:36:59 +02:00
|
|
|
|
points_for_note,
|
2025-09-06 14:04:46 +02:00
|
|
|
|
points_for_edges,
|
|
|
|
|
|
upsert_batch,
|
|
|
|
|
|
)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
from app.core.edges import deriv_edges_for_note
|
2025-09-03 07:58:57 +02:00
|
|
|
|
|
2025-09-05 11:53:59 +02:00
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
# Hilfsfunktionen
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2025-09-01 17:37:39 +02:00
|
|
|
|
|
2025-09-06 14:04:46 +02:00
|
|
|
|
def iter_md(root: str) -> List[str]:
|
2025-09-09 11:12:33 +02:00
|
|
|
|
"""Sammelt alle .md-Dateien unterhalb von root, filtert systemische Ordner."""
|
|
|
|
|
|
out: List[str] = []
|
|
|
|
|
|
for dirpath, _, filenames in os.walk(root):
|
|
|
|
|
|
for fn in filenames:
|
|
|
|
|
|
if not fn.lower().endswith(".md"):
|
|
|
|
|
|
continue
|
|
|
|
|
|
p = os.path.join(dirpath, fn)
|
|
|
|
|
|
pn = p.replace("\\", "/")
|
|
|
|
|
|
if any(ex in pn for ex in ["/.obsidian/", "/_backup_frontmatter/", "/_imported/"]):
|
|
|
|
|
|
continue
|
|
|
|
|
|
out.append(p)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
return sorted(out)
|
2025-09-05 11:53:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
def collections(prefix: str) -> Tuple[str, str, str]:
|
|
|
|
|
|
return f"{prefix}_notes", f"{prefix}_chunks", f"{prefix}_edges"
|
2025-09-06 15:42:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
def fetch_existing_note_hash(client, prefix: str, note_id: str) -> Optional[str]:
|
2025-09-09 11:12:33 +02:00
|
|
|
|
"""Liest den bisherigen hash_fulltext aus der Notes-Collection (falls vorhanden)."""
|
2025-09-08 18:36:59 +02:00
|
|
|
|
notes_col, _, _ = collections(prefix)
|
2025-09-09 11:12:33 +02:00
|
|
|
|
f = rest.Filter(must=[rest.FieldCondition(
|
|
|
|
|
|
key="note_id",
|
|
|
|
|
|
match=rest.MatchValue(value=note_id),
|
|
|
|
|
|
)])
|
2025-09-08 18:36:59 +02:00
|
|
|
|
points, _ = client.scroll(
|
2025-09-06 15:42:10 +02:00
|
|
|
|
collection_name=notes_col,
|
|
|
|
|
|
scroll_filter=f,
|
|
|
|
|
|
with_payload=True,
|
|
|
|
|
|
with_vectors=False,
|
2025-09-08 18:36:59 +02:00
|
|
|
|
limit=1,
|
2025-09-06 15:42:10 +02:00
|
|
|
|
)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
if not points:
|
2025-09-06 15:42:10 +02:00
|
|
|
|
return None
|
2025-09-08 18:36:59 +02:00
|
|
|
|
pl = points[0].payload or {}
|
2025-09-06 15:42:10 +02:00
|
|
|
|
return pl.get("hash_fulltext")
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
def purge_note_artifacts(client, prefix: str, note_id: str) -> None:
|
2025-09-06 14:04:46 +02:00
|
|
|
|
"""
|
2025-09-09 11:12:33 +02:00
|
|
|
|
Löscht alle Chunks+Edges zu einer Note. Collections bleiben bestehen.
|
2025-09-06 14:04:46 +02:00
|
|
|
|
"""
|
2025-09-08 18:36:59 +02:00
|
|
|
|
_, chunks_col, edges_col = collections(prefix)
|
2025-09-06 14:04:46 +02:00
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
# Chunks der Note löschen
|
|
|
|
|
|
f_chunks = rest.Filter(
|
|
|
|
|
|
must=[rest.FieldCondition(key="note_id", match=rest.MatchValue(value=note_id))]
|
|
|
|
|
|
)
|
2025-09-06 15:42:10 +02:00
|
|
|
|
client.delete(collection_name=chunks_col, points_selector=f_chunks, wait=True)
|
2025-09-06 14:04:46 +02:00
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
# Edges der Note löschen (Chunk- und Note-Scope)
|
|
|
|
|
|
should = [
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# Chunk-IDs (note_id#c...)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
rest.FieldCondition(key="source_id", match=rest.MatchText(text=f"{note_id}#")),
|
|
|
|
|
|
rest.FieldCondition(key="target_id", match=rest.MatchText(text=f"{note_id}#")),
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# Note-Scope (source/target == note_id)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
rest.FieldCondition(key="source_id", match=rest.MatchValue(value=note_id)),
|
|
|
|
|
|
rest.FieldCondition(key="target_id", match=rest.MatchValue(value=note_id)),
|
|
|
|
|
|
]
|
|
|
|
|
|
f_edges = rest.Filter(should=should)
|
|
|
|
|
|
client.delete(collection_name=edges_col, points_selector=f_edges, wait=True)
|
|
|
|
|
|
|
2025-09-06 14:04:46 +02:00
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
def has_chunk_level_refs(chunk_payloads: List[Dict]) -> bool:
|
|
|
|
|
|
return any(isinstance(ch.get("references"), list) and ch["references"] for ch in chunk_payloads)
|
2025-09-06 14:04:46 +02:00
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
|
|
|
|
|
|
def fallback_note_level_edges(note_meta: Dict, chunk_payloads: List[Dict]) -> List[Dict]:
|
|
|
|
|
|
"""
|
2025-09-09 11:12:33 +02:00
|
|
|
|
Falls chunk_payloads keine 'references' enthalten, erzeugen wir:
|
|
|
|
|
|
- belongs_to + prev/next aus chunk_payloads
|
|
|
|
|
|
- references/backlink auf Note-Scope aus note_meta['references'] (falls vorhanden)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
"""
|
|
|
|
|
|
edges: List[Dict] = []
|
|
|
|
|
|
|
|
|
|
|
|
# belongs_to + prev/next (Chunk-Scope)
|
|
|
|
|
|
for ch in chunk_payloads:
|
|
|
|
|
|
src = ch["id"]
|
|
|
|
|
|
edges.append({"src_id": src, "dst_id": note_meta["id"], "edge_type": "belongs_to", "scope": "chunk"})
|
|
|
|
|
|
nb = ch.get("neighbors") or {}
|
|
|
|
|
|
prev_id = nb.get("prev")
|
|
|
|
|
|
next_id = nb.get("next")
|
|
|
|
|
|
if prev_id:
|
|
|
|
|
|
edges.append({"src_id": src, "dst_id": prev_id, "edge_type": "next", "scope": "chunk"})
|
|
|
|
|
|
edges.append({"src_id": prev_id, "dst_id": src, "edge_type": "prev", "scope": "chunk"})
|
|
|
|
|
|
if next_id:
|
|
|
|
|
|
edges.append({"src_id": src, "dst_id": next_id, "edge_type": "next", "scope": "chunk"})
|
|
|
|
|
|
edges.append({"src_id": next_id, "dst_id": src, "edge_type": "prev", "scope": "chunk"})
|
|
|
|
|
|
|
|
|
|
|
|
# Note-Scope references/backlink
|
|
|
|
|
|
for tid in (note_meta.get("references") or []):
|
|
|
|
|
|
edges.append({"src_id": note_meta["id"], "dst_id": tid, "edge_type": "references", "scope": "note"})
|
|
|
|
|
|
edges.append({"src_id": tid, "dst_id": note_meta["id"], "edge_type": "backlink", "scope": "note"})
|
|
|
|
|
|
|
|
|
|
|
|
# Dedupe
|
|
|
|
|
|
uniq = {}
|
|
|
|
|
|
for e in edges:
|
2025-09-09 11:12:33 +02:00
|
|
|
|
key = (e["src_id"], e["dst_id"], e["edge_type"], e.get("scope", ""))
|
|
|
|
|
|
uniq[key] = e
|
2025-09-08 18:36:59 +02:00
|
|
|
|
return list(uniq.values())
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
def _normalize_rel_path(abs_path: str, vault_root: str) -> str:
|
|
|
|
|
|
"""Gibt einen **relativen** Pfad zurück, normalisiert auf forward slashes."""
|
|
|
|
|
|
try:
|
|
|
|
|
|
rel = os.path.relpath(abs_path, vault_root)
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
rel = abs_path # Fallback
|
|
|
|
|
|
return rel.replace("\\", "/").lstrip("/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2025-09-06 14:04:46 +02:00
|
|
|
|
# Main
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# -----------------------------------------------------------------------------
|
2025-09-05 07:41:28 +02:00
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
def main() -> None:
|
2025-09-08 18:36:59 +02:00
|
|
|
|
load_dotenv()
|
2025-09-01 17:37:39 +02:00
|
|
|
|
ap = argparse.ArgumentParser()
|
2025-09-08 18:36:59 +02:00
|
|
|
|
ap.add_argument("--vault", required=True, help="Pfad zum Obsidian-Vault (Root-Ordner)")
|
|
|
|
|
|
ap.add_argument("--apply", action="store_true", help="Schreibt in Qdrant; ohne Flag nur Dry-Run")
|
|
|
|
|
|
ap.add_argument("--purge-before-upsert", action="store_true",
|
|
|
|
|
|
help="Vor Upsert Chunks & Edges der GEÄNDERTEN Note löschen")
|
|
|
|
|
|
ap.add_argument("--note-id", help="Nur eine bestimmte Note-ID verarbeiten")
|
|
|
|
|
|
ap.add_argument("--embed-note", action="store_true", help="Optional: Note-Volltext einbetten")
|
|
|
|
|
|
ap.add_argument("--force-replace", action="store_true",
|
|
|
|
|
|
help="Änderungserkennung ignorieren und immer upserten (+ optional Purge)")
|
2025-09-01 17:37:39 +02:00
|
|
|
|
args = ap.parse_args()
|
|
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# Qdrant
|
2025-09-08 18:36:59 +02:00
|
|
|
|
cfg = QdrantConfig.from_env()
|
2025-09-03 07:58:57 +02:00
|
|
|
|
client = get_client(cfg)
|
2025-09-05 11:04:42 +02:00
|
|
|
|
ensure_collections(client, cfg.prefix, cfg.dim)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
notes_col, chunks_col, edges_col = collections(cfg.prefix)
|
2025-09-03 07:58:57 +02:00
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
root = os.path.abspath(args.vault)
|
|
|
|
|
|
files = iter_md(root)
|
2025-09-03 07:58:57 +02:00
|
|
|
|
if not files:
|
2025-09-06 14:04:46 +02:00
|
|
|
|
print("Keine Markdown-Dateien gefunden.", file=sys.stderr)
|
|
|
|
|
|
sys.exit(2)
|
2025-09-03 07:58:57 +02:00
|
|
|
|
|
2025-09-06 14:04:46 +02:00
|
|
|
|
processed = 0
|
2025-09-08 18:36:59 +02:00
|
|
|
|
for path in files:
|
|
|
|
|
|
parsed = read_markdown(path)
|
|
|
|
|
|
fm = normalize_frontmatter(parsed.frontmatter)
|
|
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# Pflichtfelder prüfen (z. B. id, title) – bei Fehler: Note überspringen
|
2025-09-04 16:42:43 +02:00
|
|
|
|
try:
|
2025-09-05 09:22:50 +02:00
|
|
|
|
validate_required_frontmatter(fm)
|
2025-09-04 16:42:43 +02:00
|
|
|
|
except Exception:
|
2025-09-03 07:58:57 +02:00
|
|
|
|
continue
|
2025-09-08 18:36:59 +02:00
|
|
|
|
|
2025-09-03 07:58:57 +02:00
|
|
|
|
if args.note_id and fm.get("id") != args.note_id:
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
2025-09-06 14:04:46 +02:00
|
|
|
|
processed += 1
|
2025-09-05 11:53:59 +02:00
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
# Note-Payload & Validierung
|
|
|
|
|
|
note_pl = make_note_payload(parsed, vault_root=root)
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# **Kompat-Erweiterung**: Volltext & relativer Pfad sicherstellen
|
|
|
|
|
|
if "fulltext" not in (note_pl or {}):
|
|
|
|
|
|
note_pl["fulltext"] = parsed.body or ""
|
|
|
|
|
|
# Pfad ggf. relativieren (falls make_note_payload es noch nicht tut)
|
|
|
|
|
|
if note_pl.get("path"):
|
|
|
|
|
|
note_pl["path"] = _normalize_rel_path(os.path.join(root, note_pl["path"])
|
|
|
|
|
|
if not os.path.isabs(note_pl["path"]) else note_pl["path"],
|
|
|
|
|
|
root)
|
|
|
|
|
|
else:
|
|
|
|
|
|
# fallback: relativer Pfad aus parsed.path
|
|
|
|
|
|
note_pl["path"] = _normalize_rel_path(parsed.path, root)
|
|
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
validate_note_payload(note_pl)
|
|
|
|
|
|
note_id = note_pl["note_id"]
|
2025-09-06 15:42:10 +02:00
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# Change-Detection (Body-basiert per hash_fulltext)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
new_hash = note_pl.get("hash_fulltext")
|
|
|
|
|
|
old_hash = None
|
|
|
|
|
|
if not args.force_replace:
|
|
|
|
|
|
old_hash = fetch_existing_note_hash(client, cfg.prefix, note_id)
|
|
|
|
|
|
changed = args.force_replace or (old_hash != new_hash)
|
2025-09-03 07:58:57 +02:00
|
|
|
|
|
2025-09-08 18:36:59 +02:00
|
|
|
|
# Chunks + Embeddings
|
2025-09-06 14:04:46 +02:00
|
|
|
|
chunks = assemble_chunks(fm["id"], parsed.body, fm.get("type", "concept"))
|
2025-09-03 07:58:57 +02:00
|
|
|
|
chunk_pls = make_chunk_payloads(fm, note_pl["path"], chunks)
|
2025-09-08 18:36:59 +02:00
|
|
|
|
vecs = embed_texts([c.text for c in chunks])
|
|
|
|
|
|
|
|
|
|
|
|
# Optional: Note-Vektor
|
|
|
|
|
|
note_vec = embed_one(parsed.body) if args.embed_note else None
|
|
|
|
|
|
|
|
|
|
|
|
# Edges
|
|
|
|
|
|
edges = deriv_edges_for_note(fm, chunk_pls)
|
|
|
|
|
|
if not edges or (not has_chunk_level_refs(chunk_pls) and (fm.get("references") or note_pl.get("references"))):
|
|
|
|
|
|
# Ergänze fm['references'] falls noch nicht im fm vorhanden
|
|
|
|
|
|
if "references" not in fm and "references" in note_pl:
|
|
|
|
|
|
fm["references"] = note_pl["references"]
|
|
|
|
|
|
edges = fallback_note_level_edges(fm, chunk_pls)
|
|
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# Zusammenfassung
|
2025-09-08 18:36:59 +02:00
|
|
|
|
summary = {
|
|
|
|
|
|
"note_id": note_id,
|
2025-09-06 14:04:46 +02:00
|
|
|
|
"title": fm.get("title"),
|
|
|
|
|
|
"chunks": len(chunk_pls),
|
|
|
|
|
|
"edges": len(edges),
|
2025-09-08 18:36:59 +02:00
|
|
|
|
"changed": changed,
|
|
|
|
|
|
"decision": ("apply" if args.apply and changed else
|
|
|
|
|
|
"apply-skip-unchanged" if args.apply and not changed else
|
|
|
|
|
|
"dry-run"),
|
2025-09-06 14:04:46 +02:00
|
|
|
|
"path": note_pl["path"],
|
2025-09-08 18:36:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
print(json.dumps(summary, ensure_ascii=False))
|
|
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# Dry-Run?
|
2025-09-08 18:36:59 +02:00
|
|
|
|
if not args.apply:
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
# Optionaler Purge NUR für geänderte Notes
|
|
|
|
|
|
if changed and args.purge_before_upsert:
|
|
|
|
|
|
purge_note_artifacts(client, cfg.prefix, note_id)
|
|
|
|
|
|
|
2025-09-09 11:12:33 +02:00
|
|
|
|
# Upserts: Notes / Chunks / Edges
|
2025-09-08 18:36:59 +02:00
|
|
|
|
notes_name, note_pts = points_for_note(cfg.prefix, note_pl, note_vec, cfg.dim)
|
|
|
|
|
|
upsert_batch(client, notes_name, note_pts)
|
|
|
|
|
|
|
|
|
|
|
|
chunks_name, chunk_pts = points_for_chunks(cfg.prefix, chunk_pls, vecs)
|
|
|
|
|
|
upsert_batch(client, chunks_name, chunk_pts)
|
|
|
|
|
|
|
|
|
|
|
|
edges_name, edge_pts = points_for_edges(cfg.prefix, edges)
|
|
|
|
|
|
upsert_batch(client, edges_name, edge_pts)
|
2025-09-06 14:04:46 +02:00
|
|
|
|
|
|
|
|
|
|
print(f"Done. Processed notes: {processed}")
|
|
|
|
|
|
|
2025-09-01 17:37:39 +02:00
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2025-09-03 07:58:57 +02:00
|
|
|
|
main()
|