Compare commits
42
Commits
V2.6.0
...
v2.6.1-graph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84e319a42f | ||
|
|
efd9c74cd3 | ||
|
|
eccdf43cd3 | ||
|
|
9e25e5b26b | ||
|
|
cee8fc05c2 | ||
|
|
9a55d45832 | ||
|
|
48de6aed8c | ||
|
|
8772271648 | ||
|
|
0cb216c2bc | ||
|
|
eb45d78c47 | ||
|
|
582aed61ec | ||
|
|
0294414d26 | ||
|
|
3a2a78e0fd | ||
|
|
245a96809a | ||
|
|
bb41b11cce | ||
|
|
af73ab9371 | ||
|
|
cba1337066 | ||
|
|
d50ed70467 | ||
|
|
f313f0873b | ||
|
|
f7a4dab707 | ||
|
|
3861246ac6 | ||
|
|
053c22bc15 | ||
|
|
bbfa2049eb | ||
|
|
0b47ffdcb6 | ||
|
|
cf91730e45 | ||
|
|
ae0768e4de | ||
|
|
ccc848f2e2 | ||
|
|
c6ccad1d18 | ||
|
|
4e8512c812 | ||
|
|
f1bcbb1543 | ||
|
|
537a2883bf | ||
|
|
72a3988e49 | ||
|
|
93b8bc48e4 | ||
|
|
19f8d76e21 | ||
|
|
772a202d6e | ||
|
|
dc16bbf8a4 | ||
|
|
028ad7e941 | ||
|
|
620858a575 | ||
|
|
0bb5f57cc6 | ||
|
|
0a4374dc8c | ||
|
|
8afa402118 | ||
|
|
1eee189a49 |
No files matched your search
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# mindnet API (bundle)
|
# mindnet API (bundle)
|
||||||
|
|
||||||
This bundle provides a minimal FastAPI app for embeddings and Qdrant upserts/queries plus a Markdown importer.
|
This bundle provides a minimal FastAPI app for embeddings and Qdrant upserts/queries plus a Markdown importer.
|
||||||
@@ -35,5 +34,5 @@ python3 scripts/import_markdown.py --vault /path/to/Obsidian
|
|||||||
See `scripts/quick_test.sh` for a runnable example.
|
See `scripts/quick_test.sh` for a runnable example.
|
||||||
|
|
||||||
>Anmerkung:
|
>Anmerkung:
|
||||||
Diese Datei ist veraltet
|
Diese Datei ist veraltet und muss auf Stand 2.6.0 gebracht werden
|
||||||
|
|
||||||
+34
-517
@@ -1,533 +1,50 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
import requests
|
|
||||||
import uuid
|
import uuid
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import re
|
|
||||||
import yaml
|
|
||||||
import unicodedata
|
|
||||||
from datetime import datetime
|
|
||||||
from pathlib import Path
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
# --- CONFIGURATION ---
|
# --- CONFIG & STYLING ---
|
||||||
load_dotenv()
|
st.set_page_config(page_title="mindnet v2.6", page_icon="🧠", layout="wide")
|
||||||
API_BASE_URL = os.getenv("MINDNET_API_URL", "http://localhost:8002")
|
|
||||||
CHAT_ENDPOINT = f"{API_BASE_URL}/chat"
|
|
||||||
FEEDBACK_ENDPOINT = f"{API_BASE_URL}/feedback"
|
|
||||||
INGEST_ANALYZE_ENDPOINT = f"{API_BASE_URL}/ingest/analyze"
|
|
||||||
INGEST_SAVE_ENDPOINT = f"{API_BASE_URL}/ingest/save"
|
|
||||||
HISTORY_FILE = Path("data/logs/search_history.jsonl")
|
|
||||||
|
|
||||||
# Timeout Strategy
|
|
||||||
timeout_setting = os.getenv("MINDNET_API_TIMEOUT") or os.getenv("MINDNET_LLM_TIMEOUT")
|
|
||||||
API_TIMEOUT = float(timeout_setting) if timeout_setting else 300.0
|
|
||||||
|
|
||||||
# --- PAGE SETUP ---
|
|
||||||
st.set_page_config(page_title="mindnet v2.5", page_icon="🧠", layout="wide")
|
|
||||||
|
|
||||||
# --- CSS STYLING ---
|
|
||||||
st.markdown("""
|
st.markdown("""
|
||||||
<style>
|
<style>
|
||||||
.block-container { padding-top: 2rem; max_width: 1000px; margin: auto; }
|
.block-container { padding-top: 2rem; max_width: 1200px; margin: auto; }
|
||||||
|
.intent-badge { background-color: #e8f0fe; color: #1a73e8; padding: 4px 10px; border-radius: 12px; font-size: 0.8rem; font-weight: 600; border: 1px solid #d2e3fc; display: inline-block; margin-bottom: 0.5rem; }
|
||||||
.intent-badge {
|
.draft-box { border: 1px solid #d0d7de; border-radius: 6px; padding: 16px; background-color: #f6f8fa; margin: 10px 0; }
|
||||||
background-color: #e8f0fe; color: #1a73e8;
|
.preview-box { border: 1px solid #e0e0e0; border-radius: 6px; padding: 24px; background-color: white; }
|
||||||
padding: 4px 10px; border-radius: 12px;
|
|
||||||
font-size: 0.8rem; font-weight: 600;
|
|
||||||
border: 1px solid #d2e3fc; display: inline-block; margin-bottom: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.draft-box {
|
|
||||||
border: 1px solid #d0d7de;
|
|
||||||
border-radius: 6px;
|
|
||||||
padding: 16px;
|
|
||||||
background-color: #f6f8fa;
|
|
||||||
margin-top: 10px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.preview-box {
|
|
||||||
border: 1px solid #e0e0e0;
|
|
||||||
border-radius: 6px;
|
|
||||||
padding: 24px;
|
|
||||||
background-color: white;
|
|
||||||
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
""", unsafe_allow_html=True)
|
""", unsafe_allow_html=True)
|
||||||
|
|
||||||
|
# --- MODULE IMPORTS ---
|
||||||
|
try:
|
||||||
|
from ui_config import QDRANT_URL, QDRANT_KEY, COLLECTION_PREFIX
|
||||||
|
from ui_graph_service import GraphExplorerService
|
||||||
|
|
||||||
|
# Komponenten
|
||||||
|
from ui_sidebar import render_sidebar
|
||||||
|
from ui_chat import render_chat_interface
|
||||||
|
from ui_editor import render_manual_editor
|
||||||
|
|
||||||
|
# Die beiden Graph-Engines
|
||||||
|
from ui_graph import render_graph_explorer as render_graph_agraph
|
||||||
|
from ui_graph_cytoscape import render_graph_explorer_cytoscape # <-- Import
|
||||||
|
|
||||||
|
except ImportError as e:
|
||||||
|
st.error(f"Import Error: {e}. Bitte stelle sicher, dass alle UI-Dateien im Ordner liegen und 'streamlit-cytoscapejs' installiert ist.")
|
||||||
|
st.stop()
|
||||||
|
|
||||||
# --- SESSION STATE ---
|
# --- SESSION STATE ---
|
||||||
if "messages" not in st.session_state: st.session_state.messages = []
|
if "messages" not in st.session_state: st.session_state.messages = []
|
||||||
if "user_id" not in st.session_state: st.session_state.user_id = str(uuid.uuid4())
|
if "user_id" not in st.session_state: st.session_state.user_id = str(uuid.uuid4())
|
||||||
|
|
||||||
# --- HELPER FUNCTIONS ---
|
# --- SERVICE INIT ---
|
||||||
|
graph_service = GraphExplorerService(QDRANT_URL, QDRANT_KEY, COLLECTION_PREFIX)
|
||||||
|
|
||||||
def slugify(value):
|
# --- MAIN ROUTING ---
|
||||||
if not value: return ""
|
|
||||||
value = str(value).lower()
|
|
||||||
replacements = {'ä': 'ae', 'ö': 'oe', 'ü': 'ue', 'ß': 'ss', '&': 'und', '+': 'und'}
|
|
||||||
for k, v in replacements.items():
|
|
||||||
value = value.replace(k, v)
|
|
||||||
|
|
||||||
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
|
|
||||||
value = re.sub(r'[^\w\s-]', '', value).strip()
|
|
||||||
return re.sub(r'[-\s]+', '-', value)
|
|
||||||
|
|
||||||
def normalize_meta_and_body(meta, body):
|
|
||||||
ALLOWED_KEYS = {"title", "type", "status", "tags", "id", "created", "updated", "aliases", "lang"}
|
|
||||||
clean_meta = {}
|
|
||||||
extra_content = []
|
|
||||||
|
|
||||||
if "titel" in meta and "title" not in meta:
|
|
||||||
meta["title"] = meta.pop("titel")
|
|
||||||
|
|
||||||
tag_candidates = ["tags", "emotionale_keywords", "keywords", "schluesselwoerter"]
|
|
||||||
all_tags = []
|
|
||||||
for key in tag_candidates:
|
|
||||||
if key in meta:
|
|
||||||
val = meta[key]
|
|
||||||
if isinstance(val, list): all_tags.extend(val)
|
|
||||||
elif isinstance(val, str): all_tags.extend([t.strip() for t in val.split(",")])
|
|
||||||
|
|
||||||
for key, val in meta.items():
|
|
||||||
if key in ALLOWED_KEYS:
|
|
||||||
clean_meta[key] = val
|
|
||||||
elif key in tag_candidates:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if val and isinstance(val, str):
|
|
||||||
header = key.replace("_", " ").title()
|
|
||||||
extra_content.append(f"## {header}\n{val}\n")
|
|
||||||
|
|
||||||
if all_tags:
|
|
||||||
clean_tags = []
|
|
||||||
for t in all_tags:
|
|
||||||
t_clean = str(t).replace("#", "").strip()
|
|
||||||
if t_clean: clean_tags.append(t_clean)
|
|
||||||
clean_meta["tags"] = list(set(clean_tags))
|
|
||||||
|
|
||||||
if extra_content:
|
|
||||||
new_section = "\n".join(extra_content)
|
|
||||||
final_body = f"{new_section}\n{body}"
|
|
||||||
else:
|
|
||||||
final_body = body
|
|
||||||
|
|
||||||
return clean_meta, final_body
|
|
||||||
|
|
||||||
def parse_markdown_draft(full_text):
|
|
||||||
"""
|
|
||||||
HEALING PARSER: Repariert kaputten LLM Output (z.B. fehlendes schließendes '---').
|
|
||||||
"""
|
|
||||||
clean_text = full_text.strip()
|
|
||||||
|
|
||||||
# 1. Code-Block Wrapper entfernen
|
|
||||||
pattern_block = r"```(?:markdown|md|yaml)?\s*(.*?)\s*```"
|
|
||||||
match_block = re.search(pattern_block, clean_text, re.DOTALL | re.IGNORECASE)
|
|
||||||
if match_block:
|
|
||||||
clean_text = match_block.group(1).strip()
|
|
||||||
|
|
||||||
meta = {}
|
|
||||||
body = clean_text
|
|
||||||
yaml_str = ""
|
|
||||||
|
|
||||||
# 2. Versuch A: Standard Split (Idealfall)
|
|
||||||
parts = re.split(r"^---+\s*$", clean_text, maxsplit=2, flags=re.MULTILINE)
|
|
||||||
|
|
||||||
if len(parts) >= 3:
|
|
||||||
yaml_str = parts[1]
|
|
||||||
body = parts[2]
|
|
||||||
|
|
||||||
# 3. Versuch B: Healing (Wenn LLM das schließende --- vergessen hat)
|
|
||||||
elif clean_text.startswith("---"):
|
|
||||||
# Wir suchen die erste Überschrift '#', da Frontmatter davor sein muss
|
|
||||||
# Pattern: Suche --- am Anfang, dann nimm alles bis zum ersten # am Zeilenanfang
|
|
||||||
fallback_match = re.search(r"^---\s*(.*?)(?=\n#)", clean_text, re.DOTALL | re.MULTILINE)
|
|
||||||
if fallback_match:
|
|
||||||
yaml_str = fallback_match.group(1)
|
|
||||||
# Der Body ist alles NACH dem YAML String (inklusive dem #)
|
|
||||||
body = clean_text.replace(f"---{yaml_str}", "", 1).strip()
|
|
||||||
|
|
||||||
# 4. YAML Parsing
|
|
||||||
if yaml_str:
|
|
||||||
yaml_str_clean = yaml_str.replace("#", "") # Tags cleanen
|
|
||||||
try:
|
|
||||||
parsed = yaml.safe_load(yaml_str_clean)
|
|
||||||
if isinstance(parsed, dict):
|
|
||||||
meta = parsed
|
|
||||||
except Exception as e:
|
|
||||||
print(f"YAML Parsing Warning: {e}")
|
|
||||||
|
|
||||||
# Fallback: Titel aus H1
|
|
||||||
if not meta.get("title"):
|
|
||||||
h1_match = re.search(r"^#\s+(.*)$", body, re.MULTILINE)
|
|
||||||
if h1_match:
|
|
||||||
meta["title"] = h1_match.group(1).strip()
|
|
||||||
|
|
||||||
# Correction: type/status swap
|
|
||||||
if meta.get("type") == "draft":
|
|
||||||
meta["status"] = "draft"
|
|
||||||
meta["type"] = "experience"
|
|
||||||
|
|
||||||
return normalize_meta_and_body(meta, body)
|
|
||||||
|
|
||||||
def build_markdown_doc(meta, body):
|
|
||||||
"""Baut das finale Dokument zusammen."""
|
|
||||||
if "id" not in meta or meta["id"] == "generated_on_save":
|
|
||||||
raw_title = meta.get('title', 'note')
|
|
||||||
clean_slug = slugify(raw_title)[:50] or "note"
|
|
||||||
meta["id"] = f"{datetime.now().strftime('%Y%m%d')}-{clean_slug}"
|
|
||||||
|
|
||||||
meta["updated"] = datetime.now().strftime("%Y-%m-%d")
|
|
||||||
|
|
||||||
ordered_meta = {}
|
|
||||||
prio_keys = ["id", "type", "title", "status", "tags"]
|
|
||||||
for k in prio_keys:
|
|
||||||
if k in meta: ordered_meta[k] = meta.pop(k)
|
|
||||||
ordered_meta.update(meta)
|
|
||||||
|
|
||||||
try:
|
|
||||||
yaml_str = yaml.dump(ordered_meta, default_flow_style=None, sort_keys=False, allow_unicode=True).strip()
|
|
||||||
except:
|
|
||||||
yaml_str = "error: generating_yaml"
|
|
||||||
|
|
||||||
return f"---\n{yaml_str}\n---\n\n{body}"
|
|
||||||
|
|
||||||
def load_history_from_logs(limit=10):
|
|
||||||
queries = []
|
|
||||||
if HISTORY_FILE.exists():
|
|
||||||
try:
|
|
||||||
with open(HISTORY_FILE, "r", encoding="utf-8") as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
for line in reversed(lines):
|
|
||||||
try:
|
|
||||||
entry = json.loads(line)
|
|
||||||
q = entry.get("query_text")
|
|
||||||
if q and q not in queries:
|
|
||||||
queries.append(q)
|
|
||||||
if len(queries) >= limit: break
|
|
||||||
except: continue
|
|
||||||
except: pass
|
|
||||||
return queries
|
|
||||||
|
|
||||||
# --- API CLIENT ---
|
|
||||||
|
|
||||||
def send_chat_message(message: str, top_k: int, explain: bool):
|
|
||||||
try:
|
|
||||||
response = requests.post(
|
|
||||||
CHAT_ENDPOINT,
|
|
||||||
json={"message": message, "top_k": top_k, "explain": explain},
|
|
||||||
timeout=API_TIMEOUT
|
|
||||||
)
|
|
||||||
response.raise_for_status()
|
|
||||||
return response.json()
|
|
||||||
except Exception as e:
|
|
||||||
return {"error": str(e)}
|
|
||||||
|
|
||||||
def analyze_draft_text(text: str, n_type: str):
|
|
||||||
try:
|
|
||||||
response = requests.post(
|
|
||||||
INGEST_ANALYZE_ENDPOINT,
|
|
||||||
json={"text": text, "type": n_type},
|
|
||||||
timeout=15
|
|
||||||
)
|
|
||||||
response.raise_for_status()
|
|
||||||
return response.json()
|
|
||||||
except Exception as e:
|
|
||||||
return {"error": str(e)}
|
|
||||||
|
|
||||||
def save_draft_to_vault(markdown_content: str, filename: str = None):
|
|
||||||
try:
|
|
||||||
response = requests.post(
|
|
||||||
INGEST_SAVE_ENDPOINT,
|
|
||||||
json={"markdown_content": markdown_content, "filename": filename},
|
|
||||||
timeout=API_TIMEOUT
|
|
||||||
)
|
|
||||||
response.raise_for_status()
|
|
||||||
return response.json()
|
|
||||||
except Exception as e:
|
|
||||||
return {"error": str(e)}
|
|
||||||
|
|
||||||
def submit_feedback(query_id, node_id, score, comment=None):
|
|
||||||
try:
|
|
||||||
requests.post(FEEDBACK_ENDPOINT, json={"query_id": query_id, "node_id": node_id, "score": score, "comment": comment}, timeout=2)
|
|
||||||
st.toast(f"Feedback ({score}) gesendet!")
|
|
||||||
except: pass
|
|
||||||
|
|
||||||
# --- UI COMPONENTS ---
|
|
||||||
|
|
||||||
def render_sidebar():
|
|
||||||
with st.sidebar:
|
|
||||||
st.title("🧠 mindnet")
|
|
||||||
st.caption("v2.5 | Healing Parser")
|
|
||||||
mode = st.radio("Modus", ["💬 Chat", "📝 Manueller Editor"], index=0)
|
|
||||||
st.divider()
|
|
||||||
st.subheader("⚙️ Settings")
|
|
||||||
top_k = st.slider("Quellen (Top-K)", 1, 10, 5)
|
|
||||||
explain = st.toggle("Explanation Layer", True)
|
|
||||||
st.divider()
|
|
||||||
st.subheader("🕒 Verlauf")
|
|
||||||
for q in load_history_from_logs(8):
|
|
||||||
if st.button(f"🔎 {q[:25]}...", key=f"hist_{q}", use_container_width=True):
|
|
||||||
st.session_state.messages.append({"role": "user", "content": q})
|
|
||||||
st.rerun()
|
|
||||||
return mode, top_k, explain
|
|
||||||
|
|
||||||
def render_draft_editor(msg):
|
|
||||||
if "query_id" not in msg or not msg["query_id"]:
|
|
||||||
msg["query_id"] = str(uuid.uuid4())
|
|
||||||
|
|
||||||
qid = msg["query_id"]
|
|
||||||
key_base = f"draft_{qid}"
|
|
||||||
|
|
||||||
# State Keys
|
|
||||||
data_meta_key = f"{key_base}_data_meta"
|
|
||||||
data_sugg_key = f"{key_base}_data_suggestions"
|
|
||||||
widget_body_key = f"{key_base}_widget_body"
|
|
||||||
data_body_key = f"{key_base}_data_body"
|
|
||||||
|
|
||||||
# --- 1. INIT STATE ---
|
|
||||||
if f"{key_base}_init" not in st.session_state:
|
|
||||||
meta, body = parse_markdown_draft(msg["content"])
|
|
||||||
if "type" not in meta: meta["type"] = "default"
|
|
||||||
if "title" not in meta: meta["title"] = ""
|
|
||||||
tags = meta.get("tags", [])
|
|
||||||
meta["tags_str"] = ", ".join(tags) if isinstance(tags, list) else str(tags)
|
|
||||||
|
|
||||||
# Persistent Data
|
|
||||||
st.session_state[data_meta_key] = meta
|
|
||||||
st.session_state[data_sugg_key] = []
|
|
||||||
st.session_state[data_body_key] = body.strip()
|
|
||||||
|
|
||||||
# Init Widgets Keys
|
|
||||||
st.session_state[f"{key_base}_wdg_title"] = meta["title"]
|
|
||||||
st.session_state[f"{key_base}_wdg_type"] = meta["type"]
|
|
||||||
st.session_state[f"{key_base}_wdg_tags"] = meta["tags_str"]
|
|
||||||
|
|
||||||
st.session_state[f"{key_base}_init"] = True
|
|
||||||
|
|
||||||
# --- 2. RESURRECTION ---
|
|
||||||
if widget_body_key not in st.session_state and data_body_key in st.session_state:
|
|
||||||
st.session_state[widget_body_key] = st.session_state[data_body_key]
|
|
||||||
|
|
||||||
# --- CALLBACKS ---
|
|
||||||
def _sync_meta():
|
|
||||||
meta = st.session_state[data_meta_key]
|
|
||||||
meta["title"] = st.session_state.get(f"{key_base}_wdg_title", "")
|
|
||||||
meta["type"] = st.session_state.get(f"{key_base}_wdg_type", "default")
|
|
||||||
meta["tags_str"] = st.session_state.get(f"{key_base}_wdg_tags", "")
|
|
||||||
st.session_state[data_meta_key] = meta
|
|
||||||
|
|
||||||
def _sync_body():
|
|
||||||
st.session_state[data_body_key] = st.session_state[widget_body_key]
|
|
||||||
|
|
||||||
def _insert_text(text_to_insert):
|
|
||||||
current = st.session_state.get(widget_body_key, "")
|
|
||||||
new_text = f"{current}\n\n{text_to_insert}"
|
|
||||||
st.session_state[widget_body_key] = new_text
|
|
||||||
st.session_state[data_body_key] = new_text
|
|
||||||
|
|
||||||
def _remove_text(text_to_remove):
|
|
||||||
current = st.session_state.get(widget_body_key, "")
|
|
||||||
new_text = current.replace(text_to_remove, "").strip()
|
|
||||||
st.session_state[widget_body_key] = new_text
|
|
||||||
st.session_state[data_body_key] = new_text
|
|
||||||
|
|
||||||
# --- UI LAYOUT ---
|
|
||||||
st.markdown(f'<div class="draft-box">', unsafe_allow_html=True)
|
|
||||||
st.markdown("### 📝 Entwurf bearbeiten")
|
|
||||||
|
|
||||||
meta_ref = st.session_state[data_meta_key]
|
|
||||||
c1, c2 = st.columns([2, 1])
|
|
||||||
with c1:
|
|
||||||
st.text_input("Titel", key=f"{key_base}_wdg_title", on_change=_sync_meta)
|
|
||||||
|
|
||||||
with c2:
|
|
||||||
known_types = ["concept", "project", "decision", "experience", "journal", "value", "goal", "principle", "risk", "belief"]
|
|
||||||
curr_type = st.session_state.get(f"{key_base}_wdg_type", meta_ref["type"])
|
|
||||||
if curr_type not in known_types: known_types.append(curr_type)
|
|
||||||
st.selectbox("Typ", known_types, key=f"{key_base}_wdg_type", on_change=_sync_meta)
|
|
||||||
|
|
||||||
st.text_input("Tags", key=f"{key_base}_wdg_tags", on_change=_sync_meta)
|
|
||||||
|
|
||||||
tab_edit, tab_intel, tab_view = st.tabs(["✏️ Inhalt", "🧠 Intelligence", "👁️ Vorschau"])
|
|
||||||
|
|
||||||
# --- TAB 1: EDITOR ---
|
|
||||||
with tab_edit:
|
|
||||||
st.text_area(
|
|
||||||
"Body",
|
|
||||||
key=widget_body_key,
|
|
||||||
height=500,
|
|
||||||
on_change=_sync_body,
|
|
||||||
label_visibility="collapsed"
|
|
||||||
)
|
|
||||||
|
|
||||||
# --- TAB 2: INTELLIGENCE ---
|
|
||||||
with tab_intel:
|
|
||||||
st.info("Klicke auf 'Analysieren', um Verknüpfungen für den AKTUELLEN Text zu finden.")
|
|
||||||
|
|
||||||
if st.button("🔍 Analyse starten", key=f"{key_base}_analyze"):
|
|
||||||
st.session_state[data_sugg_key] = []
|
|
||||||
|
|
||||||
text_to_analyze = st.session_state.get(widget_body_key, st.session_state.get(data_body_key, ""))
|
|
||||||
current_doc_type = st.session_state.get(f"{key_base}_wdg_type", "concept")
|
|
||||||
|
|
||||||
with st.spinner("Analysiere..."):
|
|
||||||
analysis = analyze_draft_text(text_to_analyze, current_doc_type)
|
|
||||||
|
|
||||||
if "error" in analysis:
|
|
||||||
st.error(f"Fehler: {analysis['error']}")
|
|
||||||
else:
|
|
||||||
suggestions = analysis.get("suggestions", [])
|
|
||||||
st.session_state[data_sugg_key] = suggestions
|
|
||||||
if not suggestions:
|
|
||||||
st.warning("Keine Vorschläge gefunden.")
|
|
||||||
else:
|
|
||||||
st.success(f"{len(suggestions)} Vorschläge gefunden.")
|
|
||||||
|
|
||||||
suggestions = st.session_state[data_sugg_key]
|
|
||||||
if suggestions:
|
|
||||||
current_text_state = st.session_state.get(widget_body_key, "")
|
|
||||||
|
|
||||||
for idx, sugg in enumerate(suggestions):
|
|
||||||
link_text = sugg.get('suggested_markdown', '')
|
|
||||||
is_inserted = link_text in current_text_state
|
|
||||||
|
|
||||||
bg_color = "#e6fffa" if is_inserted else "#ffffff"
|
|
||||||
border = "3px solid #28a745" if is_inserted else "3px solid #1a73e8"
|
|
||||||
|
|
||||||
st.markdown(f"""
|
|
||||||
<div style="border-left: {border}; background-color: {bg_color}; padding: 10px; margin-bottom: 8px; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
|
|
||||||
<b>{sugg.get('target_title')}</b> <small>({sugg.get('type')})</small><br>
|
|
||||||
<i>{sugg.get('reason')}</i><br>
|
|
||||||
<code>{link_text}</code>
|
|
||||||
</div>
|
|
||||||
""", unsafe_allow_html=True)
|
|
||||||
|
|
||||||
if is_inserted:
|
|
||||||
st.button("❌ Entfernen", key=f"del_{idx}_{key_base}", on_click=_remove_text, args=(link_text,))
|
|
||||||
else:
|
|
||||||
st.button("➕ Einfügen", key=f"add_{idx}_{key_base}", on_click=_insert_text, args=(link_text,))
|
|
||||||
|
|
||||||
# --- TAB 3: SAVE ---
|
|
||||||
final_tags_str = st.session_state.get(f"{key_base}_wdg_tags", "")
|
|
||||||
final_tags = [t.strip() for t in final_tags_str.split(",") if t.strip()]
|
|
||||||
|
|
||||||
final_meta = {
|
|
||||||
"id": "generated_on_save",
|
|
||||||
"type": st.session_state.get(f"{key_base}_wdg_type", "default"),
|
|
||||||
"title": st.session_state.get(f"{key_base}_wdg_title", "").strip(),
|
|
||||||
"status": "draft",
|
|
||||||
"tags": final_tags
|
|
||||||
}
|
|
||||||
|
|
||||||
final_body = st.session_state.get(widget_body_key, st.session_state[data_body_key])
|
|
||||||
|
|
||||||
if not final_meta["title"]:
|
|
||||||
h1_match = re.search(r"^#\s+(.*)$", final_body, re.MULTILINE)
|
|
||||||
if h1_match:
|
|
||||||
final_meta["title"] = h1_match.group(1).strip()
|
|
||||||
|
|
||||||
final_doc = build_markdown_doc(final_meta, final_body)
|
|
||||||
|
|
||||||
with tab_view:
|
|
||||||
st.markdown('<div class="preview-box">', unsafe_allow_html=True)
|
|
||||||
st.markdown(final_doc)
|
|
||||||
st.markdown('</div>', unsafe_allow_html=True)
|
|
||||||
|
|
||||||
st.markdown("---")
|
|
||||||
|
|
||||||
b1, b2 = st.columns([1, 1])
|
|
||||||
with b1:
|
|
||||||
if st.button("💾 Speichern & Indizieren", type="primary", key=f"{key_base}_save"):
|
|
||||||
with st.spinner("Speichere im Vault..."):
|
|
||||||
|
|
||||||
raw_title = final_meta.get("title", "")
|
|
||||||
if not raw_title:
|
|
||||||
clean_body = re.sub(r"[#*_\[\]()]", "", final_body).strip()
|
|
||||||
raw_title = clean_body[:40] if clean_body else "draft"
|
|
||||||
|
|
||||||
safe_title = slugify(raw_title)[:60] or "draft"
|
|
||||||
fname = f"{datetime.now().strftime('%Y%m%d')}-{safe_title}.md"
|
|
||||||
|
|
||||||
result = save_draft_to_vault(final_doc, filename=fname)
|
|
||||||
if "error" in result:
|
|
||||||
st.error(f"Fehler: {result['error']}")
|
|
||||||
else:
|
|
||||||
st.success(f"Gespeichert: {result.get('file_path')}")
|
|
||||||
st.balloons()
|
|
||||||
with b2:
|
|
||||||
if st.button("📋 Code anzeigen", key=f"{key_base}_btn_copy"):
|
|
||||||
st.code(final_doc, language="markdown")
|
|
||||||
|
|
||||||
st.markdown("</div>", unsafe_allow_html=True)
|
|
||||||
|
|
||||||
|
|
||||||
def render_chat_interface(top_k, explain):
|
|
||||||
for idx, msg in enumerate(st.session_state.messages):
|
|
||||||
with st.chat_message(msg["role"]):
|
|
||||||
if msg["role"] == "assistant":
|
|
||||||
intent = msg.get("intent", "UNKNOWN")
|
|
||||||
src = msg.get("intent_source", "?")
|
|
||||||
icon = {"EMPATHY":"❤️", "DECISION":"⚖️", "CODING":"💻", "FACT":"📚", "INTERVIEW":"📝"}.get(intent, "🧠")
|
|
||||||
st.markdown(f'<div class="intent-badge">{icon} Intent: {intent} <span style="opacity:0.6; font-size:0.8em">({src})</span></div>', unsafe_allow_html=True)
|
|
||||||
|
|
||||||
with st.expander("🐞 Debug Raw Payload", expanded=False):
|
|
||||||
st.json(msg)
|
|
||||||
|
|
||||||
if intent == "INTERVIEW":
|
|
||||||
render_draft_editor(msg)
|
|
||||||
else:
|
|
||||||
st.markdown(msg["content"])
|
|
||||||
|
|
||||||
if "sources" in msg and msg["sources"]:
|
|
||||||
for hit in msg["sources"]:
|
|
||||||
with st.expander(f"📄 {hit.get('note_id', '?')} ({hit.get('total_score', 0):.2f})"):
|
|
||||||
st.markdown(f"_{hit.get('source', {}).get('text', '')[:300]}..._")
|
|
||||||
if hit.get('explanation'):
|
|
||||||
st.caption(f"Grund: {hit['explanation']['reasons'][0]['message']}")
|
|
||||||
def _cb(qid=msg.get("query_id"), nid=hit.get('node_id')):
|
|
||||||
val = st.session_state.get(f"fb_src_{qid}_{nid}")
|
|
||||||
if val is not None: submit_feedback(qid, nid, val+1)
|
|
||||||
st.feedback("faces", key=f"fb_src_{msg.get('query_id')}_{hit.get('node_id')}", on_change=_cb)
|
|
||||||
|
|
||||||
if "query_id" in msg:
|
|
||||||
qid = msg["query_id"]
|
|
||||||
st.feedback("stars", key=f"fb_glob_{qid}", on_change=lambda: submit_feedback(qid, "generated_answer", st.session_state[f"fb_glob_{qid}"]+1))
|
|
||||||
else:
|
|
||||||
st.markdown(msg["content"])
|
|
||||||
|
|
||||||
if prompt := st.chat_input("Frage Mindnet..."):
|
|
||||||
st.session_state.messages.append({"role": "user", "content": prompt})
|
|
||||||
st.rerun()
|
|
||||||
|
|
||||||
if len(st.session_state.messages) > 0 and st.session_state.messages[-1]["role"] == "user":
|
|
||||||
with st.chat_message("assistant"):
|
|
||||||
with st.spinner("Thinking..."):
|
|
||||||
resp = send_chat_message(st.session_state.messages[-1]["content"], top_k, explain)
|
|
||||||
if "error" in resp:
|
|
||||||
st.error(resp["error"])
|
|
||||||
else:
|
|
||||||
st.session_state.messages.append({
|
|
||||||
"role": "assistant",
|
|
||||||
"content": resp.get("answer"),
|
|
||||||
"intent": resp.get("intent", "FACT"),
|
|
||||||
"intent_source": resp.get("intent_source", "Unknown"),
|
|
||||||
"sources": resp.get("sources", []),
|
|
||||||
"query_id": resp.get("query_id")
|
|
||||||
})
|
|
||||||
st.rerun()
|
|
||||||
|
|
||||||
def render_manual_editor():
|
|
||||||
mock_msg = {
|
|
||||||
"content": "---\ntype: concept\ntitle: Neue Notiz\nstatus: draft\ntags: []\n---\n# Titel\n",
|
|
||||||
"query_id": "manual_mode_v2"
|
|
||||||
}
|
|
||||||
render_draft_editor(mock_msg)
|
|
||||||
|
|
||||||
# --- MAIN ---
|
|
||||||
mode, top_k, explain = render_sidebar()
|
mode, top_k, explain = render_sidebar()
|
||||||
|
|
||||||
if mode == "💬 Chat":
|
if mode == "💬 Chat":
|
||||||
render_chat_interface(top_k, explain)
|
render_chat_interface(top_k, explain)
|
||||||
else:
|
elif mode == "📝 Manueller Editor":
|
||||||
render_manual_editor()
|
render_manual_editor()
|
||||||
|
elif mode == "🕸️ Graph (Agraph)":
|
||||||
|
render_graph_agraph(graph_service)
|
||||||
|
elif mode == "🕸️ Graph (Cytoscape)":
|
||||||
|
render_graph_explorer_cytoscape(graph_service)
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import requests
|
||||||
|
import streamlit as st
|
||||||
|
from ui_config import CHAT_ENDPOINT, INGEST_ANALYZE_ENDPOINT, INGEST_SAVE_ENDPOINT, FEEDBACK_ENDPOINT, API_TIMEOUT
|
||||||
|
|
||||||
|
def send_chat_message(message: str, top_k: int, explain: bool):
|
||||||
|
try:
|
||||||
|
response = requests.post(
|
||||||
|
CHAT_ENDPOINT,
|
||||||
|
json={"message": message, "top_k": top_k, "explain": explain},
|
||||||
|
timeout=API_TIMEOUT
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
except Exception as e:
|
||||||
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
def analyze_draft_text(text: str, n_type: str):
|
||||||
|
try:
|
||||||
|
response = requests.post(INGEST_ANALYZE_ENDPOINT, json={"text": text, "type": n_type}, timeout=15)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
except Exception as e:
|
||||||
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
def save_draft_to_vault(markdown_content: str, filename: str = None):
|
||||||
|
try:
|
||||||
|
response = requests.post(INGEST_SAVE_ENDPOINT, json={"markdown_content": markdown_content, "filename": filename}, timeout=API_TIMEOUT)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
except Exception as e:
|
||||||
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
def submit_feedback(query_id, node_id, score, comment=None):
|
||||||
|
try:
|
||||||
|
requests.post(FEEDBACK_ENDPOINT, json={"query_id": query_id, "node_id": node_id, "score": score, "comment": comment}, timeout=2)
|
||||||
|
st.toast(f"Feedback ({score}) gesendet!")
|
||||||
|
except: pass
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import streamlit as st
|
||||||
|
import os
|
||||||
|
from ui_utils import build_markdown_doc
|
||||||
|
|
||||||
|
def switch_to_editor_callback(note_payload):
|
||||||
|
"""
|
||||||
|
Callback für den 'Bearbeiten'-Button im Graphen.
|
||||||
|
Versucht, die Datei direkt aus dem Vault (Dateisystem) zu lesen.
|
||||||
|
Das garantiert, dass Frontmatter und Inhalt vollständig sind (Single Source of Truth).
|
||||||
|
"""
|
||||||
|
# 1. Pfad ermitteln (Priorität auf 'path' aus Qdrant)
|
||||||
|
origin_fname = note_payload.get('path')
|
||||||
|
|
||||||
|
# Fallback für Legacy-Datenfelder
|
||||||
|
if not origin_fname:
|
||||||
|
origin_fname = note_payload.get('file_path') or note_payload.get('filename')
|
||||||
|
|
||||||
|
content = ""
|
||||||
|
file_loaded = False
|
||||||
|
|
||||||
|
# 2. Versuch: Direkt von der Festplatte lesen
|
||||||
|
# Wir prüfen, ob der Pfad existiert und lesen den aktuellen Stand der Datei.
|
||||||
|
if origin_fname and os.path.exists(origin_fname):
|
||||||
|
try:
|
||||||
|
with open(origin_fname, "r", encoding="utf-8") as f:
|
||||||
|
content = f.read()
|
||||||
|
file_loaded = True
|
||||||
|
except Exception as e:
|
||||||
|
# Fehler im Terminal loggen, aber UI nicht crashen lassen
|
||||||
|
print(f"Fehler beim Lesen von {origin_fname}: {e}")
|
||||||
|
|
||||||
|
# 3. Fallback: Inhalt aus Qdrant nehmen (wenn Datei nicht zugreifbar)
|
||||||
|
if not file_loaded:
|
||||||
|
# Wir nehmen 'fulltext' aus dem Payload
|
||||||
|
content = note_payload.get('fulltext', '')
|
||||||
|
|
||||||
|
if not content:
|
||||||
|
# Letzter Ausweg: Metadaten nehmen und Dummy-Content bauen
|
||||||
|
content = build_markdown_doc(note_payload, "Inhalt konnte nicht geladen werden (Datei nicht gefunden).")
|
||||||
|
else:
|
||||||
|
# Check: Hat der Text ein Frontmatter? Wenn nein, rekonstruieren wir es.
|
||||||
|
if not content.strip().startswith("---"):
|
||||||
|
content = build_markdown_doc(note_payload, content)
|
||||||
|
|
||||||
|
# Notfall-Pfad Konstruktion (falls gar kein Pfad im System ist)
|
||||||
|
if not origin_fname and 'note_id' in note_payload:
|
||||||
|
origin_fname = f"{note_payload['note_id']}.md"
|
||||||
|
|
||||||
|
# 4. Daten an den Editor übergeben
|
||||||
|
# Wir nutzen den Chat-Verlauf als Transportmittel für den State
|
||||||
|
st.session_state.messages.append({
|
||||||
|
"role": "assistant",
|
||||||
|
"intent": "INTERVIEW",
|
||||||
|
"content": content,
|
||||||
|
"query_id": f"edit_{note_payload.get('note_id', 'unknown')}", # Trigger für den Editor
|
||||||
|
"origin_filename": origin_fname,
|
||||||
|
"origin_note_id": note_payload.get('note_id')
|
||||||
|
})
|
||||||
|
|
||||||
|
# 5. Modus umschalten (wechselt den Tab beim nächsten Rerun)
|
||||||
|
st.session_state["sidebar_mode_selection"] = "📝 Manueller Editor"
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import streamlit as st
|
||||||
|
from ui_api import send_chat_message, submit_feedback
|
||||||
|
from ui_editor import render_draft_editor
|
||||||
|
|
||||||
|
def render_chat_interface(top_k, explain):
|
||||||
|
"""
|
||||||
|
Rendert das Chat-Interface.
|
||||||
|
Zeigt Nachrichten an und behandelt User-Input.
|
||||||
|
"""
|
||||||
|
# 1. Verlauf anzeigen
|
||||||
|
for idx, msg in enumerate(st.session_state.messages):
|
||||||
|
with st.chat_message(msg["role"]):
|
||||||
|
if msg["role"] == "assistant":
|
||||||
|
# Intent Badge
|
||||||
|
intent = msg.get("intent", "UNKNOWN")
|
||||||
|
st.markdown(f'<div class="intent-badge">Intent: {intent}</div>', unsafe_allow_html=True)
|
||||||
|
|
||||||
|
# Debugging (optional, gut für Entwicklung)
|
||||||
|
with st.expander("🐞 Payload", expanded=False):
|
||||||
|
st.json(msg)
|
||||||
|
|
||||||
|
# Unterscheidung: Normaler Text oder Editor-Modus (Interview)
|
||||||
|
if intent == "INTERVIEW":
|
||||||
|
render_draft_editor(msg)
|
||||||
|
else:
|
||||||
|
st.markdown(msg["content"])
|
||||||
|
|
||||||
|
# Quellen anzeigen
|
||||||
|
if "sources" in msg and msg["sources"]:
|
||||||
|
for hit in msg["sources"]:
|
||||||
|
score = hit.get('total_score', 0)
|
||||||
|
# Wenn score None ist, 0.0 annehmen
|
||||||
|
if score is None: score = 0.0
|
||||||
|
|
||||||
|
with st.expander(f"📄 {hit.get('note_id', '?')} ({score:.2f})"):
|
||||||
|
st.markdown(f"_{hit.get('source', {}).get('text', '')[:300]}..._")
|
||||||
|
|
||||||
|
# Explanation Layer
|
||||||
|
if hit.get('explanation'):
|
||||||
|
st.caption(f"Grund: {hit['explanation']['reasons'][0]['message']}")
|
||||||
|
|
||||||
|
# Feedback Buttons pro Source
|
||||||
|
def _cb(qid=msg.get("query_id"), nid=hit.get('node_id')):
|
||||||
|
val = st.session_state.get(f"fb_src_{qid}_{nid}")
|
||||||
|
if val is not None: submit_feedback(qid, nid, val+1)
|
||||||
|
|
||||||
|
st.feedback("faces", key=f"fb_src_{msg.get('query_id')}_{hit.get('node_id')}", on_change=_cb)
|
||||||
|
|
||||||
|
# Globales Feedback für die Antwort
|
||||||
|
if "query_id" in msg:
|
||||||
|
qid = msg["query_id"]
|
||||||
|
st.feedback("stars", key=f"fb_glob_{qid}", on_change=lambda: submit_feedback(qid, "generated_answer", st.session_state[f"fb_glob_{qid}"]+1))
|
||||||
|
else:
|
||||||
|
# User Nachricht
|
||||||
|
st.markdown(msg["content"])
|
||||||
|
|
||||||
|
# 2. Input Feld
|
||||||
|
if prompt := st.chat_input("Frage Mindnet..."):
|
||||||
|
st.session_state.messages.append({"role": "user", "content": prompt})
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
# 3. Antwort generieren (wenn letzte Nachricht vom User ist)
|
||||||
|
if len(st.session_state.messages) > 0 and st.session_state.messages[-1]["role"] == "user":
|
||||||
|
with st.chat_message("assistant"):
|
||||||
|
with st.spinner("Thinking..."):
|
||||||
|
resp = send_chat_message(st.session_state.messages[-1]["content"], top_k, explain)
|
||||||
|
|
||||||
|
if "error" in resp:
|
||||||
|
st.error(resp["error"])
|
||||||
|
else:
|
||||||
|
st.session_state.messages.append({
|
||||||
|
"role": "assistant",
|
||||||
|
"content": resp.get("answer"),
|
||||||
|
"intent": resp.get("intent", "FACT"),
|
||||||
|
"sources": resp.get("sources", []),
|
||||||
|
"query_id": resp.get("query_id")
|
||||||
|
})
|
||||||
|
st.rerun()
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import os
|
||||||
|
import hashlib
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
# --- API & PORTS ---
|
||||||
|
API_BASE_URL = os.getenv("MINDNET_API_URL", "http://localhost:8002")
|
||||||
|
CHAT_ENDPOINT = f"{API_BASE_URL}/chat"
|
||||||
|
FEEDBACK_ENDPOINT = f"{API_BASE_URL}/feedback"
|
||||||
|
INGEST_ANALYZE_ENDPOINT = f"{API_BASE_URL}/ingest/analyze"
|
||||||
|
INGEST_SAVE_ENDPOINT = f"{API_BASE_URL}/ingest/save"
|
||||||
|
|
||||||
|
# --- QDRANT ---
|
||||||
|
QDRANT_URL = os.getenv("QDRANT_URL", "http://localhost:6333")
|
||||||
|
QDRANT_KEY = os.getenv("QDRANT_API_KEY", None)
|
||||||
|
if QDRANT_KEY == "": QDRANT_KEY = None
|
||||||
|
COLLECTION_PREFIX = os.getenv("COLLECTION_PREFIX", "mindnet")
|
||||||
|
|
||||||
|
# --- FILES & TIMEOUTS ---
|
||||||
|
HISTORY_FILE = Path("data/logs/search_history.jsonl")
|
||||||
|
timeout_setting = os.getenv("MINDNET_API_TIMEOUT") or os.getenv("MINDNET_LLM_TIMEOUT")
|
||||||
|
API_TIMEOUT = float(timeout_setting) if timeout_setting else 300.0
|
||||||
|
|
||||||
|
# --- STYLING CONSTANTS ---
|
||||||
|
|
||||||
|
# Basierend auf types.yaml
|
||||||
|
GRAPH_COLORS = {
|
||||||
|
# Kerntypen
|
||||||
|
"experience": "#feca57", # Gelb/Orange
|
||||||
|
"project": "#ff9f43", # Dunkleres Orange
|
||||||
|
"decision": "#5f27cd", # Lila
|
||||||
|
|
||||||
|
# Persönlichkeit
|
||||||
|
"value": "#00d2d3", # Cyan
|
||||||
|
"principle": "#0abde3", # Dunkles Cyan
|
||||||
|
"belief": "#48dbfb", # Helles Blau
|
||||||
|
"profile": "#1dd1a1", # Grün
|
||||||
|
|
||||||
|
# Strategie & Risiko
|
||||||
|
"goal": "#ff9ff3", # Pink
|
||||||
|
"risk": "#ff6b6b", # Rot
|
||||||
|
|
||||||
|
# Basis
|
||||||
|
"concept": "#54a0ff", # Blau
|
||||||
|
"task": "#8395a7", # Grau-Blau
|
||||||
|
"journal": "#c8d6e5", # Hellgrau
|
||||||
|
"source": "#576574", # Dunkelgrau
|
||||||
|
"glossary": "#222f3e", # Sehr dunkel
|
||||||
|
|
||||||
|
"default": "#8395a7" # Fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
# System-Kanten, die wir NICHT im Graphen sehen wollen, um Rauschen zu reduzieren
|
||||||
|
SYSTEM_EDGES = ["prev", "next", "belongs_to"]
|
||||||
|
|
||||||
|
def get_edge_color(kind: str) -> str:
|
||||||
|
"""Generiert eine deterministische Farbe basierend auf dem Edge-Typ."""
|
||||||
|
if not kind: return "#bdc3c7"
|
||||||
|
|
||||||
|
# Einige feste Farben für wichtige semantische Typen
|
||||||
|
fixed_colors = {
|
||||||
|
"depends_on": "#ff6b6b", # Rot (Blocker/Abhängigkeit)
|
||||||
|
"blocks": "#ee5253", # Dunkelrot
|
||||||
|
"caused_by": "#ff9ff3", # Pink
|
||||||
|
"related_to": "#c8d6e5", # Hellgrau (Hintergrund)
|
||||||
|
"references": "#bdc3c7", # Grau
|
||||||
|
"derived_from": "#1dd1a1" # Grün
|
||||||
|
}
|
||||||
|
|
||||||
|
if kind in fixed_colors:
|
||||||
|
return fixed_colors[kind]
|
||||||
|
|
||||||
|
# Fallback: Hash-basierte Farbe für dynamische Typen
|
||||||
|
# Wir nutzen einen Pastell-Generator, damit es nicht zu grell wird
|
||||||
|
hash_obj = hashlib.md5(kind.encode())
|
||||||
|
hue = int(hash_obj.hexdigest(), 16) % 360
|
||||||
|
return f"hsl({hue}, 60%, 50%)"
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
import streamlit as st
|
||||||
|
import uuid
|
||||||
|
import re
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from ui_utils import parse_markdown_draft, build_markdown_doc, slugify
|
||||||
|
from ui_api import save_draft_to_vault, analyze_draft_text
|
||||||
|
|
||||||
|
def render_draft_editor(msg):
|
||||||
|
"""
|
||||||
|
Rendert den Markdown-Editor.
|
||||||
|
Nutzt 'origin_filename' aus der Message, um zwischen Update und Neu zu unterscheiden.
|
||||||
|
"""
|
||||||
|
if "query_id" not in msg or not msg["query_id"]:
|
||||||
|
msg["query_id"] = str(uuid.uuid4())
|
||||||
|
|
||||||
|
qid = msg["query_id"]
|
||||||
|
key_base = f"draft_{qid}"
|
||||||
|
|
||||||
|
# State Keys
|
||||||
|
data_meta_key = f"{key_base}_data_meta"
|
||||||
|
data_sugg_key = f"{key_base}_data_suggestions"
|
||||||
|
widget_body_key = f"{key_base}_widget_body"
|
||||||
|
data_body_key = f"{key_base}_data_body"
|
||||||
|
|
||||||
|
# --- INIT STATE ---
|
||||||
|
if f"{key_base}_init" not in st.session_state:
|
||||||
|
meta, body = parse_markdown_draft(msg["content"])
|
||||||
|
if "type" not in meta: meta["type"] = "default"
|
||||||
|
if "title" not in meta: meta["title"] = ""
|
||||||
|
tags = meta.get("tags", [])
|
||||||
|
meta["tags_str"] = ", ".join(tags) if isinstance(tags, list) else str(tags)
|
||||||
|
|
||||||
|
st.session_state[data_meta_key] = meta
|
||||||
|
st.session_state[data_sugg_key] = []
|
||||||
|
st.session_state[data_body_key] = body.strip()
|
||||||
|
|
||||||
|
st.session_state[f"{key_base}_wdg_title"] = meta["title"]
|
||||||
|
st.session_state[f"{key_base}_wdg_type"] = meta["type"]
|
||||||
|
st.session_state[f"{key_base}_wdg_tags"] = meta["tags_str"]
|
||||||
|
|
||||||
|
# Pfad übernehmen (Source of Truth)
|
||||||
|
st.session_state[f"{key_base}_origin_filename"] = msg.get("origin_filename")
|
||||||
|
st.session_state[f"{key_base}_init"] = True
|
||||||
|
|
||||||
|
# --- RESURRECTION ---
|
||||||
|
if widget_body_key not in st.session_state and data_body_key in st.session_state:
|
||||||
|
st.session_state[widget_body_key] = st.session_state[data_body_key]
|
||||||
|
|
||||||
|
# --- SYNC HELPER ---
|
||||||
|
def _sync_meta():
|
||||||
|
meta = st.session_state[data_meta_key]
|
||||||
|
meta["title"] = st.session_state.get(f"{key_base}_wdg_title", "")
|
||||||
|
meta["type"] = st.session_state.get(f"{key_base}_wdg_type", "default")
|
||||||
|
meta["tags_str"] = st.session_state.get(f"{key_base}_wdg_tags", "")
|
||||||
|
st.session_state[data_meta_key] = meta
|
||||||
|
|
||||||
|
def _sync_body():
|
||||||
|
st.session_state[data_body_key] = st.session_state[widget_body_key]
|
||||||
|
|
||||||
|
def _insert_text(t):
|
||||||
|
st.session_state[widget_body_key] = f"{st.session_state.get(widget_body_key, '')}\n\n{t}"
|
||||||
|
st.session_state[data_body_key] = st.session_state[widget_body_key]
|
||||||
|
|
||||||
|
def _remove_text(t):
|
||||||
|
st.session_state[widget_body_key] = st.session_state.get(widget_body_key, '').replace(t, "").strip()
|
||||||
|
st.session_state[data_body_key] = st.session_state[widget_body_key]
|
||||||
|
|
||||||
|
# --- UI LAYOUT ---
|
||||||
|
|
||||||
|
# Header Info (Debug Pfad anzeigen, damit wir sicher sind)
|
||||||
|
origin_fname = st.session_state.get(f"{key_base}_origin_filename")
|
||||||
|
|
||||||
|
if origin_fname:
|
||||||
|
# Dateiname extrahieren für saubere Anzeige
|
||||||
|
display_name = str(origin_fname).split("/")[-1]
|
||||||
|
st.success(f"📂 **Update-Modus**: `{display_name}`")
|
||||||
|
# Debugging: Zeige vollen Pfad im Expander
|
||||||
|
with st.expander("Dateipfad Details", expanded=False):
|
||||||
|
st.code(origin_fname)
|
||||||
|
st.markdown(f'<div class="draft-box" style="border-left: 5px solid #ff9f43;">', unsafe_allow_html=True)
|
||||||
|
else:
|
||||||
|
st.info("✨ **Erstell-Modus**: Neue Datei wird angelegt.")
|
||||||
|
st.markdown(f'<div class="draft-box">', unsafe_allow_html=True)
|
||||||
|
|
||||||
|
st.markdown("### Editor")
|
||||||
|
|
||||||
|
# Meta Felder
|
||||||
|
meta_ref = st.session_state[data_meta_key]
|
||||||
|
c1, c2 = st.columns([2, 1])
|
||||||
|
with c1:
|
||||||
|
st.text_input("Titel", key=f"{key_base}_wdg_title", on_change=_sync_meta)
|
||||||
|
with c2:
|
||||||
|
known_types = ["concept", "project", "decision", "experience", "journal", "value", "goal", "principle", "risk", "belief"]
|
||||||
|
curr_type = st.session_state.get(f"{key_base}_wdg_type", meta_ref["type"])
|
||||||
|
if curr_type not in known_types: known_types.append(curr_type)
|
||||||
|
st.selectbox("Typ", known_types, key=f"{key_base}_wdg_type", on_change=_sync_meta)
|
||||||
|
|
||||||
|
st.text_input("Tags", key=f"{key_base}_wdg_tags", on_change=_sync_meta)
|
||||||
|
|
||||||
|
# Tabs
|
||||||
|
tab_edit, tab_intel, tab_view = st.tabs(["✏️ Inhalt", "🧠 Intelligence", "👁️ Vorschau"])
|
||||||
|
|
||||||
|
with tab_edit:
|
||||||
|
st.text_area("Body", key=widget_body_key, height=600, on_change=_sync_body, label_visibility="collapsed")
|
||||||
|
|
||||||
|
with tab_intel:
|
||||||
|
st.info("Analysiert den Text auf Verknüpfungsmöglichkeiten.")
|
||||||
|
if st.button("🔍 Analyse starten", key=f"{key_base}_analyze"):
|
||||||
|
st.session_state[data_sugg_key] = []
|
||||||
|
text_to_analyze = st.session_state.get(widget_body_key, st.session_state.get(data_body_key, ""))
|
||||||
|
with st.spinner("Analysiere..."):
|
||||||
|
analysis = analyze_draft_text(text_to_analyze, st.session_state.get(f"{key_base}_wdg_type", "concept"))
|
||||||
|
if "error" in analysis:
|
||||||
|
st.error(f"Fehler: {analysis['error']}")
|
||||||
|
else:
|
||||||
|
suggestions = analysis.get("suggestions", [])
|
||||||
|
st.session_state[data_sugg_key] = suggestions
|
||||||
|
if not suggestions: st.warning("Keine Vorschläge.")
|
||||||
|
else: st.success(f"{len(suggestions)} Vorschläge gefunden.")
|
||||||
|
|
||||||
|
suggestions = st.session_state[data_sugg_key]
|
||||||
|
if suggestions:
|
||||||
|
current_text = st.session_state.get(widget_body_key, "")
|
||||||
|
for idx, sugg in enumerate(suggestions):
|
||||||
|
link_text = sugg.get('suggested_markdown', '')
|
||||||
|
is_inserted = link_text in current_text
|
||||||
|
bg_color = "#e6fffa" if is_inserted else "#ffffff"
|
||||||
|
border = "3px solid #28a745" if is_inserted else "3px solid #1a73e8"
|
||||||
|
st.markdown(f"<div style='border-left: {border}; background-color: {bg_color}; padding: 10px; margin-bottom: 8px;'><b>{sugg.get('target_title')}</b> <small>({sugg.get('type')})</small><br><i>{sugg.get('reason')}</i><br><code>{link_text}</code></div>", unsafe_allow_html=True)
|
||||||
|
if is_inserted:
|
||||||
|
st.button("❌ Entfernen", key=f"del_{idx}_{key_base}", on_click=_remove_text, args=(link_text,))
|
||||||
|
else:
|
||||||
|
st.button("➕ Einfügen", key=f"add_{idx}_{key_base}", on_click=_insert_text, args=(link_text,))
|
||||||
|
|
||||||
|
# Save Logic Preparation
|
||||||
|
final_tags = [t.strip() for t in st.session_state.get(f"{key_base}_wdg_tags", "").split(",") if t.strip()]
|
||||||
|
final_meta = {
|
||||||
|
"id": "generated_on_save",
|
||||||
|
"type": st.session_state.get(f"{key_base}_wdg_type", "default"),
|
||||||
|
"title": st.session_state.get(f"{key_base}_wdg_title", "").strip(),
|
||||||
|
"status": "draft",
|
||||||
|
"tags": final_tags
|
||||||
|
}
|
||||||
|
if "origin_note_id" in msg:
|
||||||
|
final_meta["id"] = msg["origin_note_id"]
|
||||||
|
|
||||||
|
final_body = st.session_state.get(widget_body_key, st.session_state[data_body_key])
|
||||||
|
if not final_meta["title"]:
|
||||||
|
h1_match = re.search(r"^#\s+(.*)$", final_body, re.MULTILINE)
|
||||||
|
if h1_match: final_meta["title"] = h1_match.group(1).strip()
|
||||||
|
|
||||||
|
final_doc = build_markdown_doc(final_meta, final_body)
|
||||||
|
|
||||||
|
with tab_view:
|
||||||
|
st.markdown('<div class="preview-box">', unsafe_allow_html=True)
|
||||||
|
st.markdown(final_doc)
|
||||||
|
st.markdown('</div>', unsafe_allow_html=True)
|
||||||
|
|
||||||
|
st.markdown("---")
|
||||||
|
|
||||||
|
# Save Actions
|
||||||
|
b1, b2 = st.columns([1, 1])
|
||||||
|
with b1:
|
||||||
|
save_label = "💾 Update speichern" if origin_fname else "💾 Neu anlegen & Indizieren"
|
||||||
|
|
||||||
|
if st.button(save_label, type="primary", key=f"{key_base}_save"):
|
||||||
|
with st.spinner("Speichere im Vault..."):
|
||||||
|
if origin_fname:
|
||||||
|
# UPDATE: Ziel ist der exakte Pfad
|
||||||
|
target_file = origin_fname
|
||||||
|
else:
|
||||||
|
# CREATE: Neuer Dateiname
|
||||||
|
raw_title = final_meta.get("title", "draft")
|
||||||
|
target_file = f"{datetime.now().strftime('%Y%m%d')}-{slugify(raw_title)[:60]}.md"
|
||||||
|
|
||||||
|
result = save_draft_to_vault(final_doc, filename=target_file)
|
||||||
|
if "error" in result:
|
||||||
|
st.error(f"Fehler: {result['error']}")
|
||||||
|
else:
|
||||||
|
st.success(f"Gespeichert: {result.get('file_path')}")
|
||||||
|
st.balloons()
|
||||||
|
with b2:
|
||||||
|
if st.button("📋 Code anzeigen", key=f"{key_base}_btn_copy"):
|
||||||
|
st.code(final_doc, language="markdown")
|
||||||
|
|
||||||
|
st.markdown("</div>", unsafe_allow_html=True)
|
||||||
|
|
||||||
|
def render_manual_editor():
|
||||||
|
"""
|
||||||
|
Rendert den manuellen Editor.
|
||||||
|
PRÜFT, ob eine Edit-Anfrage aus dem Graphen vorliegt!
|
||||||
|
"""
|
||||||
|
|
||||||
|
target_msg = None
|
||||||
|
|
||||||
|
# 1. Prüfen: Gibt es Nachrichten im Verlauf?
|
||||||
|
if st.session_state.messages:
|
||||||
|
last_msg = st.session_state.messages[-1]
|
||||||
|
|
||||||
|
# 2. Ist die letzte Nachricht eine Edit-Anfrage? (Erkennbar am query_id prefix 'edit_')
|
||||||
|
qid = str(last_msg.get("query_id", ""))
|
||||||
|
if qid.startswith("edit_"):
|
||||||
|
target_msg = last_msg
|
||||||
|
|
||||||
|
# 3. Fallback: Leeres Template, falls keine Edit-Anfrage vorliegt
|
||||||
|
if not target_msg:
|
||||||
|
target_msg = {
|
||||||
|
"content": "---\ntype: concept\ntitle: Neue Notiz\nstatus: draft\ntags: []\n---\n# Titel\n",
|
||||||
|
"query_id": f"manual_{uuid.uuid4()}" # Eigene ID, damit neuer State entsteht
|
||||||
|
}
|
||||||
|
|
||||||
|
render_draft_editor(target_msg)
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
import streamlit as st
|
||||||
|
from streamlit_agraph import agraph, Config
|
||||||
|
from qdrant_client import models
|
||||||
|
from ui_config import COLLECTION_PREFIX, GRAPH_COLORS
|
||||||
|
from ui_callbacks import switch_to_editor_callback
|
||||||
|
|
||||||
|
def render_graph_explorer(graph_service):
|
||||||
|
st.header("🕸️ Graph Explorer")
|
||||||
|
|
||||||
|
# Session State initialisieren
|
||||||
|
if "graph_center_id" not in st.session_state:
|
||||||
|
st.session_state.graph_center_id = None
|
||||||
|
|
||||||
|
# Defaults für View & Physik setzen
|
||||||
|
st.session_state.setdefault("graph_depth", 2)
|
||||||
|
st.session_state.setdefault("graph_show_labels", True)
|
||||||
|
# Höhere Default-Werte für Abstand
|
||||||
|
st.session_state.setdefault("graph_spacing", 250)
|
||||||
|
st.session_state.setdefault("graph_gravity", -4000)
|
||||||
|
|
||||||
|
col_ctrl, col_graph = st.columns([1, 4])
|
||||||
|
|
||||||
|
# --- LINKE SPALTE: CONTROLS ---
|
||||||
|
with col_ctrl:
|
||||||
|
st.subheader("Fokus")
|
||||||
|
|
||||||
|
# Sucheingabe
|
||||||
|
search_term = st.text_input("Suche Notiz", placeholder="Titel eingeben...")
|
||||||
|
|
||||||
|
# Suchlogik Qdrant
|
||||||
|
if search_term:
|
||||||
|
hits, _ = graph_service.client.scroll(
|
||||||
|
collection_name=f"{COLLECTION_PREFIX}_notes",
|
||||||
|
scroll_filter=models.Filter(must=[models.FieldCondition(key="title", match=models.MatchText(text=search_term))]),
|
||||||
|
limit=10
|
||||||
|
)
|
||||||
|
options = {h.payload['title']: h.payload['note_id'] for h in hits}
|
||||||
|
|
||||||
|
if options:
|
||||||
|
selected_title = st.selectbox("Ergebnisse:", list(options.keys()))
|
||||||
|
if st.button("Laden", use_container_width=True):
|
||||||
|
st.session_state.graph_center_id = options[selected_title]
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
st.divider()
|
||||||
|
|
||||||
|
# Layout & Physik Einstellungen
|
||||||
|
with st.expander("👁️ Ansicht & Layout", expanded=True):
|
||||||
|
st.session_state.graph_depth = st.slider("Tiefe (Tier)", 1, 3, st.session_state.graph_depth)
|
||||||
|
st.session_state.graph_show_labels = st.checkbox("Kanten-Beschriftung", st.session_state.graph_show_labels)
|
||||||
|
|
||||||
|
st.markdown("**Physik (BarnesHut)**")
|
||||||
|
st.session_state.graph_spacing = st.slider("Federlänge (Abstand)", 50, 800, st.session_state.graph_spacing)
|
||||||
|
st.session_state.graph_gravity = st.slider("Abstoßung (Gravity)", -20000, -500, st.session_state.graph_gravity)
|
||||||
|
|
||||||
|
if st.button("Reset Layout"):
|
||||||
|
st.session_state.graph_spacing = 250
|
||||||
|
st.session_state.graph_gravity = -4000
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
st.divider()
|
||||||
|
st.caption("Legende (Top Typen)")
|
||||||
|
for k, v in list(GRAPH_COLORS.items())[:8]:
|
||||||
|
st.markdown(f"<span style='color:{v}'>●</span> {k}", unsafe_allow_html=True)
|
||||||
|
|
||||||
|
# --- RECHTE SPALTE: GRAPH & ACTION BAR ---
|
||||||
|
with col_graph:
|
||||||
|
center_id = st.session_state.graph_center_id
|
||||||
|
|
||||||
|
if center_id:
|
||||||
|
# Action Container oben fixieren (Layout Fix)
|
||||||
|
action_container = st.container()
|
||||||
|
|
||||||
|
# Graph und Daten laden
|
||||||
|
with st.spinner(f"Lade Graph..."):
|
||||||
|
nodes, edges = graph_service.get_ego_graph(
|
||||||
|
center_id,
|
||||||
|
depth=st.session_state.graph_depth,
|
||||||
|
show_labels=st.session_state.graph_show_labels
|
||||||
|
)
|
||||||
|
|
||||||
|
# WICHTIG: Daten für Editor holen (inkl. Pfad)
|
||||||
|
note_data = graph_service.get_note_with_full_content(center_id)
|
||||||
|
|
||||||
|
# Action Bar rendern
|
||||||
|
with action_container:
|
||||||
|
c1, c2 = st.columns([3, 1])
|
||||||
|
with c1:
|
||||||
|
st.caption(f"Aktives Zentrum: **{center_id}**")
|
||||||
|
with c2:
|
||||||
|
if note_data:
|
||||||
|
st.button("📝 Bearbeiten",
|
||||||
|
use_container_width=True,
|
||||||
|
on_click=switch_to_editor_callback,
|
||||||
|
args=(note_data,))
|
||||||
|
else:
|
||||||
|
st.error("Datenfehler: Note nicht gefunden")
|
||||||
|
|
||||||
|
# Debug Inspector
|
||||||
|
with st.expander("🕵️ Data Inspector", expanded=False):
|
||||||
|
if note_data:
|
||||||
|
st.json(note_data)
|
||||||
|
if 'path' in note_data:
|
||||||
|
st.success(f"Pfad OK: {note_data['path']}")
|
||||||
|
else:
|
||||||
|
st.error("Pfad fehlt!")
|
||||||
|
else:
|
||||||
|
st.info("Leer.")
|
||||||
|
|
||||||
|
if not nodes:
|
||||||
|
st.warning("Keine Daten gefunden.")
|
||||||
|
else:
|
||||||
|
# --- CONFIGURATION (BarnesHut) ---
|
||||||
|
# Height-Trick für Re-Render (da key-Parameter manchmal crasht)
|
||||||
|
dyn_height = 800 + (abs(st.session_state.graph_gravity) % 5)
|
||||||
|
|
||||||
|
config = Config(
|
||||||
|
width=1000,
|
||||||
|
height=dyn_height,
|
||||||
|
directed=True,
|
||||||
|
physics={
|
||||||
|
"enabled": True,
|
||||||
|
"solver": "barnesHut",
|
||||||
|
"barnesHut": {
|
||||||
|
"gravitationalConstant": st.session_state.graph_gravity,
|
||||||
|
"centralGravity": 0.005, # Extrem wichtig für die Ausbreitung!
|
||||||
|
"springLength": st.session_state.graph_spacing,
|
||||||
|
"springConstant": 0.04,
|
||||||
|
"damping": 0.09,
|
||||||
|
"avoidOverlap": 0.1
|
||||||
|
},
|
||||||
|
"stabilization": {"enabled": True, "iterations": 600}
|
||||||
|
},
|
||||||
|
hierarchical=False,
|
||||||
|
nodeHighlightBehavior=True,
|
||||||
|
highlightColor="#F7A7A6",
|
||||||
|
collapsible=False
|
||||||
|
)
|
||||||
|
|
||||||
|
return_value = agraph(nodes=nodes, edges=edges, config=config)
|
||||||
|
|
||||||
|
# Interaktions-Logik (Klick auf Node)
|
||||||
|
if return_value:
|
||||||
|
if return_value != center_id:
|
||||||
|
# Navigation: Neues Zentrum setzen
|
||||||
|
st.session_state.graph_center_id = return_value
|
||||||
|
st.rerun()
|
||||||
|
else:
|
||||||
|
# Klick auf das Zentrum selbst
|
||||||
|
st.toast(f"Zentrum: {return_value}")
|
||||||
|
|
||||||
|
else:
|
||||||
|
st.info("👈 Bitte wähle links eine Notiz aus, um den Graphen zu starten.")
|
||||||
@@ -0,0 +1,325 @@
|
|||||||
|
import streamlit as st
|
||||||
|
from st_cytoscape import cytoscape
|
||||||
|
from qdrant_client import models
|
||||||
|
from ui_config import COLLECTION_PREFIX, GRAPH_COLORS
|
||||||
|
from ui_callbacks import switch_to_editor_callback
|
||||||
|
|
||||||
|
def update_url_params():
|
||||||
|
"""Callback: Schreibt Slider-Werte in die URL und synchronisiert den State."""
|
||||||
|
# Werte aus den Slider-Keys in die Logik-Variablen übertragen
|
||||||
|
if "cy_depth_slider" in st.session_state:
|
||||||
|
st.session_state.cy_depth = st.session_state.cy_depth_slider
|
||||||
|
if "cy_len_slider" in st.session_state:
|
||||||
|
st.session_state.cy_ideal_edge_len = st.session_state.cy_len_slider
|
||||||
|
if "cy_rep_slider" in st.session_state:
|
||||||
|
st.session_state.cy_node_repulsion = st.session_state.cy_rep_slider
|
||||||
|
|
||||||
|
# In URL schreiben
|
||||||
|
st.query_params["depth"] = st.session_state.cy_depth
|
||||||
|
st.query_params["len"] = st.session_state.cy_ideal_edge_len
|
||||||
|
st.query_params["rep"] = st.session_state.cy_node_repulsion
|
||||||
|
|
||||||
|
def render_graph_explorer_cytoscape(graph_service):
|
||||||
|
st.header("🕸️ Graph Explorer (Cytoscape)")
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# 1. STATE & PERSISTENZ
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
if "graph_center_id" not in st.session_state:
|
||||||
|
st.session_state.graph_center_id = None
|
||||||
|
|
||||||
|
if "graph_inspected_id" not in st.session_state:
|
||||||
|
st.session_state.graph_inspected_id = None
|
||||||
|
|
||||||
|
# Lade Einstellungen aus der URL (falls vorhanden), sonst Defaults
|
||||||
|
params = st.query_params
|
||||||
|
|
||||||
|
# Helper um sicher int zu parsen
|
||||||
|
def get_param(key, default):
|
||||||
|
try: return int(params.get(key, default))
|
||||||
|
except: return default
|
||||||
|
|
||||||
|
# Initialisiere Session State Variablen, falls noch nicht vorhanden
|
||||||
|
if "cy_depth" not in st.session_state:
|
||||||
|
st.session_state.cy_depth = get_param("depth", 2)
|
||||||
|
|
||||||
|
if "cy_ideal_edge_len" not in st.session_state:
|
||||||
|
st.session_state.cy_ideal_edge_len = get_param("len", 150)
|
||||||
|
|
||||||
|
if "cy_node_repulsion" not in st.session_state:
|
||||||
|
st.session_state.cy_node_repulsion = get_param("rep", 1000000)
|
||||||
|
|
||||||
|
col_ctrl, col_graph = st.columns([1, 4])
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# 2. LINKES PANEL (Steuerung)
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
with col_ctrl:
|
||||||
|
st.subheader("Fokus")
|
||||||
|
|
||||||
|
search_term = st.text_input("Suche Notiz", placeholder="Titel eingeben...", key="cy_search")
|
||||||
|
|
||||||
|
if search_term:
|
||||||
|
hits, _ = graph_service.client.scroll(
|
||||||
|
collection_name=f"{COLLECTION_PREFIX}_notes",
|
||||||
|
limit=10,
|
||||||
|
scroll_filter=models.Filter(must=[models.FieldCondition(key="title", match=models.MatchText(text=search_term))])
|
||||||
|
)
|
||||||
|
options = {h.payload['title']: h.payload['note_id'] for h in hits}
|
||||||
|
|
||||||
|
if options:
|
||||||
|
selected_title = st.selectbox("Ergebnisse:", list(options.keys()), key="cy_select")
|
||||||
|
if st.button("Laden", use_container_width=True, key="cy_load"):
|
||||||
|
new_id = options[selected_title]
|
||||||
|
st.session_state.graph_center_id = new_id
|
||||||
|
st.session_state.graph_inspected_id = new_id
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
st.divider()
|
||||||
|
|
||||||
|
# LAYOUT EINSTELLUNGEN (Mit URL Sync)
|
||||||
|
with st.expander("👁️ Layout Einstellungen", expanded=True):
|
||||||
|
st.slider("Tiefe (Tier)", 1, 3,
|
||||||
|
value=st.session_state.cy_depth,
|
||||||
|
key="cy_depth_slider",
|
||||||
|
on_change=update_url_params)
|
||||||
|
|
||||||
|
st.markdown("**COSE Layout**")
|
||||||
|
st.slider("Kantenlänge", 50, 600,
|
||||||
|
value=st.session_state.cy_ideal_edge_len,
|
||||||
|
key="cy_len_slider",
|
||||||
|
on_change=update_url_params)
|
||||||
|
|
||||||
|
st.slider("Knoten-Abstoßung", 100000, 5000000, step=100000,
|
||||||
|
value=st.session_state.cy_node_repulsion,
|
||||||
|
key="cy_rep_slider",
|
||||||
|
on_change=update_url_params)
|
||||||
|
|
||||||
|
if st.button("Neu berechnen", key="cy_rerun"):
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
st.divider()
|
||||||
|
st.caption("Legende")
|
||||||
|
for k, v in list(GRAPH_COLORS.items())[:8]:
|
||||||
|
st.markdown(f"<span style='color:{v}'>●</span> {k}", unsafe_allow_html=True)
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# 3. RECHTES PANEL (GRAPH & INSPECTOR)
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
with col_graph:
|
||||||
|
center_id = st.session_state.graph_center_id
|
||||||
|
|
||||||
|
# Fallback Init
|
||||||
|
if not center_id and st.session_state.graph_inspected_id:
|
||||||
|
center_id = st.session_state.graph_inspected_id
|
||||||
|
st.session_state.graph_center_id = center_id
|
||||||
|
|
||||||
|
if center_id:
|
||||||
|
# Sync Inspection
|
||||||
|
if not st.session_state.graph_inspected_id:
|
||||||
|
st.session_state.graph_inspected_id = center_id
|
||||||
|
|
||||||
|
inspected_id = st.session_state.graph_inspected_id
|
||||||
|
|
||||||
|
# --- DATEN LADEN ---
|
||||||
|
with st.spinner(f"Lade Graph (Tiefe {st.session_state.cy_depth})..."):
|
||||||
|
# 1. Graph Daten
|
||||||
|
nodes_data, edges_data = graph_service.get_ego_graph(
|
||||||
|
center_id,
|
||||||
|
depth=st.session_state.cy_depth
|
||||||
|
)
|
||||||
|
# 2. Detail Daten (Inspector)
|
||||||
|
inspected_data = graph_service.get_note_with_full_content(inspected_id)
|
||||||
|
|
||||||
|
# --- ACTION BAR ---
|
||||||
|
action_container = st.container()
|
||||||
|
with action_container:
|
||||||
|
c1, c2, c3 = st.columns([2, 1, 1])
|
||||||
|
|
||||||
|
with c1:
|
||||||
|
title_show = inspected_data.get('title', inspected_id) if inspected_data else inspected_id
|
||||||
|
st.info(f"**Ausgewählt:** {title_show}")
|
||||||
|
|
||||||
|
with c2:
|
||||||
|
# NAVIGATION
|
||||||
|
if inspected_id != center_id:
|
||||||
|
if st.button("🎯 Als Zentrum setzen", use_container_width=True, key="cy_nav_btn"):
|
||||||
|
st.session_state.graph_center_id = inspected_id
|
||||||
|
st.rerun()
|
||||||
|
else:
|
||||||
|
st.caption("_(Ist aktuelles Zentrum)_")
|
||||||
|
|
||||||
|
with c3:
|
||||||
|
# EDITIEREN
|
||||||
|
if inspected_data:
|
||||||
|
st.button("📝 Bearbeiten",
|
||||||
|
use_container_width=True,
|
||||||
|
on_click=switch_to_editor_callback,
|
||||||
|
args=(inspected_data,),
|
||||||
|
key="cy_edit_btn")
|
||||||
|
|
||||||
|
# --- DATA INSPECTOR ---
|
||||||
|
with st.expander("🕵️ Data Inspector (Details)", expanded=False):
|
||||||
|
if inspected_data:
|
||||||
|
col_i1, col_i2 = st.columns(2)
|
||||||
|
with col_i1:
|
||||||
|
st.markdown(f"**ID:** `{inspected_data.get('note_id')}`")
|
||||||
|
st.markdown(f"**Typ:** `{inspected_data.get('type')}`")
|
||||||
|
with col_i2:
|
||||||
|
st.markdown(f"**Tags:** {', '.join(inspected_data.get('tags', []))}")
|
||||||
|
path_check = "✅" if inspected_data.get('path') else "❌"
|
||||||
|
st.markdown(f"**Pfad:** {path_check}")
|
||||||
|
|
||||||
|
st.caption("Inhalt (Vorschau):")
|
||||||
|
st.text_area("Content Preview", inspected_data.get('fulltext', '')[:1000], height=200, disabled=True, label_visibility="collapsed")
|
||||||
|
|
||||||
|
with st.expander("📄 Raw JSON anzeigen"):
|
||||||
|
st.json(inspected_data)
|
||||||
|
else:
|
||||||
|
st.warning("Keine Daten geladen.")
|
||||||
|
|
||||||
|
# --- GRAPH ELEMENTS ---
|
||||||
|
cy_elements = []
|
||||||
|
|
||||||
|
for n in nodes_data:
|
||||||
|
is_center = (n.id == center_id)
|
||||||
|
is_inspected = (n.id == inspected_id)
|
||||||
|
|
||||||
|
tooltip_text = n.title if n.title else n.label
|
||||||
|
display_label = n.label
|
||||||
|
if len(display_label) > 15 and " " in display_label:
|
||||||
|
display_label = display_label.replace(" ", "\n", 1)
|
||||||
|
|
||||||
|
cy_node = {
|
||||||
|
"data": {
|
||||||
|
"id": n.id,
|
||||||
|
"label": display_label,
|
||||||
|
"bg_color": n.color,
|
||||||
|
"tooltip": tooltip_text
|
||||||
|
},
|
||||||
|
# Wir steuern das Aussehen rein über Klassen (.inspected / .center)
|
||||||
|
"classes": " ".join([c for c in ["center" if is_center else "", "inspected" if is_inspected else ""] if c]),
|
||||||
|
"selected": False
|
||||||
|
}
|
||||||
|
cy_elements.append(cy_node)
|
||||||
|
|
||||||
|
for e in edges_data:
|
||||||
|
target_id = getattr(e, "to", getattr(e, "target", None))
|
||||||
|
if target_id:
|
||||||
|
cy_edge = {
|
||||||
|
"data": {
|
||||||
|
"source": e.source,
|
||||||
|
"target": target_id,
|
||||||
|
"label": e.label,
|
||||||
|
"line_color": e.color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cy_elements.append(cy_edge)
|
||||||
|
|
||||||
|
# --- STYLESHEET ---
|
||||||
|
stylesheet = [
|
||||||
|
{
|
||||||
|
"selector": "node",
|
||||||
|
"style": {
|
||||||
|
"label": "data(label)",
|
||||||
|
"width": "30px", "height": "30px",
|
||||||
|
"background-color": "data(bg_color)",
|
||||||
|
"color": "#333", "font-size": "12px",
|
||||||
|
"text-valign": "center", "text-halign": "center",
|
||||||
|
"text-wrap": "wrap", "text-max-width": "90px",
|
||||||
|
"border-width": 2, "border-color": "#fff",
|
||||||
|
"title": "data(tooltip)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
# Inspiziert (Gelber Rahmen)
|
||||||
|
{
|
||||||
|
"selector": ".inspected",
|
||||||
|
"style": {
|
||||||
|
"border-width": 6,
|
||||||
|
"border-color": "#FFC300",
|
||||||
|
"width": "50px", "height": "50px",
|
||||||
|
"font-weight": "bold",
|
||||||
|
"z-index": 999
|
||||||
|
}
|
||||||
|
},
|
||||||
|
# Zentrum (Roter Rahmen)
|
||||||
|
{
|
||||||
|
"selector": ".center",
|
||||||
|
"style": {
|
||||||
|
"border-width": 4,
|
||||||
|
"border-color": "#FF5733",
|
||||||
|
"width": "40px", "height": "40px"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
# Mix
|
||||||
|
{
|
||||||
|
"selector": ".center.inspected",
|
||||||
|
"style": {
|
||||||
|
"border-width": 6,
|
||||||
|
"border-color": "#FF5733",
|
||||||
|
"width": "55px", "height": "55px"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
# Default Selection unterdrücken
|
||||||
|
{
|
||||||
|
"selector": "node:selected",
|
||||||
|
"style": {
|
||||||
|
"border-width": 0,
|
||||||
|
"overlay-opacity": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"selector": "edge",
|
||||||
|
"style": {
|
||||||
|
"width": 2,
|
||||||
|
"line-color": "data(line_color)",
|
||||||
|
"target-arrow-color": "data(line_color)",
|
||||||
|
"target-arrow-shape": "triangle",
|
||||||
|
"curve-style": "bezier",
|
||||||
|
"label": "data(label)",
|
||||||
|
"font-size": "10px", "color": "#666",
|
||||||
|
"text-background-opacity": 0.8, "text-background-color": "#fff"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
# --- RENDER ---
|
||||||
|
graph_key = f"cy_{center_id}_{st.session_state.cy_depth}_{st.session_state.cy_ideal_edge_len}"
|
||||||
|
|
||||||
|
clicked_elements = cytoscape(
|
||||||
|
elements=cy_elements,
|
||||||
|
stylesheet=stylesheet,
|
||||||
|
layout={
|
||||||
|
"name": "cose",
|
||||||
|
"idealEdgeLength": st.session_state.cy_ideal_edge_len,
|
||||||
|
"nodeOverlap": 20,
|
||||||
|
"refresh": 20,
|
||||||
|
"fit": True,
|
||||||
|
"padding": 50,
|
||||||
|
"randomize": False,
|
||||||
|
"componentSpacing": 100,
|
||||||
|
"nodeRepulsion": st.session_state.cy_node_repulsion,
|
||||||
|
"edgeElasticity": 100,
|
||||||
|
"nestingFactor": 5,
|
||||||
|
"gravity": 80,
|
||||||
|
"numIter": 1000,
|
||||||
|
"initialTemp": 200,
|
||||||
|
"coolingFactor": 0.95,
|
||||||
|
"minTemp": 1.0,
|
||||||
|
"animate": False
|
||||||
|
},
|
||||||
|
key=graph_key,
|
||||||
|
height="700px"
|
||||||
|
)
|
||||||
|
|
||||||
|
# --- EVENT HANDLING ---
|
||||||
|
if clicked_elements:
|
||||||
|
clicked_nodes = clicked_elements.get("nodes", [])
|
||||||
|
if clicked_nodes:
|
||||||
|
clicked_id = clicked_nodes[0]
|
||||||
|
|
||||||
|
if clicked_id != st.session_state.graph_inspected_id:
|
||||||
|
st.session_state.graph_inspected_id = clicked_id
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
else:
|
||||||
|
st.info("👈 Bitte wähle links eine Notiz aus.")
|
||||||
@@ -0,0 +1,312 @@
|
|||||||
|
import re
|
||||||
|
from qdrant_client import QdrantClient, models
|
||||||
|
from streamlit_agraph import Node, Edge
|
||||||
|
from ui_config import GRAPH_COLORS, get_edge_color, SYSTEM_EDGES
|
||||||
|
|
||||||
|
class GraphExplorerService:
|
||||||
|
def __init__(self, url, api_key=None, prefix="mindnet"):
|
||||||
|
self.client = QdrantClient(url=url, api_key=api_key)
|
||||||
|
self.prefix = prefix
|
||||||
|
self.notes_col = f"{prefix}_notes"
|
||||||
|
self.chunks_col = f"{prefix}_chunks"
|
||||||
|
self.edges_col = f"{prefix}_edges"
|
||||||
|
self._note_cache = {}
|
||||||
|
|
||||||
|
def get_note_with_full_content(self, note_id):
|
||||||
|
"""
|
||||||
|
Lädt die Metadaten der Note und rekonstruiert den gesamten Text
|
||||||
|
aus den Chunks (Stitching). Wichtig für den Editor-Fallback.
|
||||||
|
"""
|
||||||
|
# 1. Metadaten holen
|
||||||
|
meta = self._fetch_note_cached(note_id)
|
||||||
|
if not meta: return None
|
||||||
|
|
||||||
|
# 2. Volltext aus Chunks bauen
|
||||||
|
full_text = self._fetch_full_text_stitched(note_id)
|
||||||
|
|
||||||
|
# 3. Ergebnis kombinieren (Wir überschreiben das 'fulltext' Feld mit dem frischen Stitching)
|
||||||
|
# Wir geben eine Kopie zurück, um den Cache nicht zu verfälschen
|
||||||
|
complete_note = meta.copy()
|
||||||
|
if full_text:
|
||||||
|
complete_note['fulltext'] = full_text
|
||||||
|
|
||||||
|
return complete_note
|
||||||
|
|
||||||
|
def get_ego_graph(self, center_note_id: str, depth=2, show_labels=True):
|
||||||
|
"""
|
||||||
|
Erstellt den Ego-Graphen um eine zentrale Notiz.
|
||||||
|
Lädt Volltext für das Zentrum und Snippets für Nachbarn.
|
||||||
|
"""
|
||||||
|
nodes_dict = {}
|
||||||
|
unique_edges = {}
|
||||||
|
|
||||||
|
# 1. Center Note laden
|
||||||
|
center_note = self._fetch_note_cached(center_note_id)
|
||||||
|
if not center_note: return [], []
|
||||||
|
self._add_node_to_dict(nodes_dict, center_note, level=0)
|
||||||
|
|
||||||
|
# Initialset für Suche
|
||||||
|
level_1_ids = {center_note_id}
|
||||||
|
|
||||||
|
# Suche Kanten für Center (L1)
|
||||||
|
l1_edges = self._find_connected_edges([center_note_id], center_note.get("title"))
|
||||||
|
|
||||||
|
for edge_data in l1_edges:
|
||||||
|
src_id, tgt_id = self._process_edge(edge_data, nodes_dict, unique_edges, current_depth=1)
|
||||||
|
if src_id: level_1_ids.add(src_id)
|
||||||
|
if tgt_id: level_1_ids.add(tgt_id)
|
||||||
|
|
||||||
|
# Level 2 Suche (begrenzt für Performance)
|
||||||
|
if depth > 1 and len(level_1_ids) > 1 and len(level_1_ids) < 80:
|
||||||
|
l1_subset = list(level_1_ids - {center_note_id})
|
||||||
|
if l1_subset:
|
||||||
|
l2_edges = self._find_connected_edges_batch(l1_subset)
|
||||||
|
for edge_data in l2_edges:
|
||||||
|
self._process_edge(edge_data, nodes_dict, unique_edges, current_depth=2)
|
||||||
|
|
||||||
|
# --- SMART CONTENT LOADING ---
|
||||||
|
|
||||||
|
# A. Fulltext für Center Node holen (Chunks zusammenfügen)
|
||||||
|
center_text = self._fetch_full_text_stitched(center_note_id)
|
||||||
|
if center_note_id in nodes_dict:
|
||||||
|
orig_title = nodes_dict[center_note_id].title
|
||||||
|
clean_full = self._clean_markdown(center_text[:2000])
|
||||||
|
# Wir packen den Text in den Tooltip (title attribute)
|
||||||
|
nodes_dict[center_note_id].title = f"{orig_title}\n\n📄 INHALT:\n{clean_full}..."
|
||||||
|
|
||||||
|
# B. Previews für alle Nachbarn holen (Batch)
|
||||||
|
all_ids = list(nodes_dict.keys())
|
||||||
|
previews = self._fetch_previews_for_nodes(all_ids)
|
||||||
|
|
||||||
|
for nid, node_obj in nodes_dict.items():
|
||||||
|
if nid != center_note_id:
|
||||||
|
prev_raw = previews.get(nid, "Kein Vorschau-Text.")
|
||||||
|
clean_prev = self._clean_markdown(prev_raw[:600])
|
||||||
|
node_obj.title = f"{node_obj.title}\n\n🔍 VORSCHAU:\n{clean_prev}..."
|
||||||
|
|
||||||
|
# Graphen bauen (Nodes & Edges finalisieren)
|
||||||
|
final_edges = []
|
||||||
|
for (src, tgt), data in unique_edges.items():
|
||||||
|
kind = data['kind']
|
||||||
|
prov = data['provenance']
|
||||||
|
color = get_edge_color(kind)
|
||||||
|
is_smart = (prov != "explicit" and prov != "rule")
|
||||||
|
|
||||||
|
# Label Logik
|
||||||
|
label_text = kind if show_labels else " "
|
||||||
|
|
||||||
|
final_edges.append(Edge(
|
||||||
|
source=src, target=tgt, label=label_text, color=color, dashes=is_smart,
|
||||||
|
title=f"Relation: {kind}\nProvenance: {prov}"
|
||||||
|
))
|
||||||
|
|
||||||
|
return list(nodes_dict.values()), final_edges
|
||||||
|
|
||||||
|
def _clean_markdown(self, text):
|
||||||
|
"""Entfernt Markdown-Sonderzeichen für saubere Tooltips im Browser."""
|
||||||
|
if not text: return ""
|
||||||
|
# Entferne Header Marker (## )
|
||||||
|
text = re.sub(r'#+\s', '', text)
|
||||||
|
# Entferne Bold/Italic (** oder *)
|
||||||
|
text = re.sub(r'\*\*|__|\*|_', '', text)
|
||||||
|
# Entferne Links [Text](Url) -> Text
|
||||||
|
text = re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', text)
|
||||||
|
# Entferne Wikilinks [[Link]] -> Link
|
||||||
|
text = re.sub(r'\[\[([^\]]+)\]\]', r'\1', text)
|
||||||
|
return text
|
||||||
|
|
||||||
|
def _fetch_full_text_stitched(self, note_id):
|
||||||
|
"""Lädt alle Chunks einer Note und baut den Text zusammen."""
|
||||||
|
try:
|
||||||
|
scroll_filter = models.Filter(
|
||||||
|
must=[models.FieldCondition(key="note_id", match=models.MatchValue(value=note_id))]
|
||||||
|
)
|
||||||
|
# Limit hoch genug setzen
|
||||||
|
chunks, _ = self.client.scroll(self.chunks_col, scroll_filter=scroll_filter, limit=100, with_payload=True)
|
||||||
|
# Sortieren nach 'ord' (Reihenfolge im Dokument)
|
||||||
|
chunks.sort(key=lambda x: x.payload.get('ord', 999))
|
||||||
|
|
||||||
|
full_text = []
|
||||||
|
for c in chunks:
|
||||||
|
# 'text' ist der reine Inhalt ohne Overlap
|
||||||
|
txt = c.payload.get('text', '')
|
||||||
|
if txt: full_text.append(txt)
|
||||||
|
|
||||||
|
return "\n\n".join(full_text)
|
||||||
|
except:
|
||||||
|
return "Fehler beim Laden des Volltexts."
|
||||||
|
|
||||||
|
def _fetch_previews_for_nodes(self, node_ids):
|
||||||
|
"""Holt Batch-weise den ersten Chunk für eine Liste von Nodes."""
|
||||||
|
if not node_ids: return {}
|
||||||
|
previews = {}
|
||||||
|
try:
|
||||||
|
scroll_filter = models.Filter(must=[models.FieldCondition(key="note_id", match=models.MatchAny(any=node_ids))])
|
||||||
|
# Limit = Anzahl Nodes * 3 (Puffer)
|
||||||
|
chunks, _ = self.client.scroll(self.chunks_col, scroll_filter=scroll_filter, limit=len(node_ids)*3, with_payload=True)
|
||||||
|
|
||||||
|
for c in chunks:
|
||||||
|
nid = c.payload.get("note_id")
|
||||||
|
# Nur den ersten gefundenen Chunk pro Note nehmen
|
||||||
|
if nid and nid not in previews:
|
||||||
|
previews[nid] = c.payload.get("window") or c.payload.get("text") or ""
|
||||||
|
except: pass
|
||||||
|
return previews
|
||||||
|
|
||||||
|
def _find_connected_edges(self, note_ids, note_title=None):
|
||||||
|
"""Findet eingehende und ausgehende Kanten."""
|
||||||
|
|
||||||
|
results = []
|
||||||
|
|
||||||
|
# 1. OUTGOING EDGES (Der "Owner"-Fix)
|
||||||
|
# Wir suchen Kanten, die im Feld 'note_id' (Owner) eine unserer Notizen haben.
|
||||||
|
# Das findet ALLE ausgehenden Kanten, egal ob sie an einem Chunk oder der Note hängen.
|
||||||
|
if note_ids:
|
||||||
|
out_filter = models.Filter(must=[
|
||||||
|
models.FieldCondition(key="note_id", match=models.MatchAny(any=note_ids)),
|
||||||
|
models.FieldCondition(key="kind", match=models.MatchExcept(**{"except": SYSTEM_EDGES}))
|
||||||
|
])
|
||||||
|
# Limit hoch, um alles zu finden
|
||||||
|
res_out, _ = self.client.scroll(self.edges_col, scroll_filter=out_filter, limit=500, with_payload=True)
|
||||||
|
results.extend(res_out)
|
||||||
|
|
||||||
|
# 2. INCOMING EDGES (Ziel = Chunk ID oder Titel oder Note ID)
|
||||||
|
# Hier müssen wir Chunks auflösen, um Treffer auf Chunks zu finden.
|
||||||
|
|
||||||
|
# Chunk IDs der aktuellen Notes holen
|
||||||
|
chunk_ids = []
|
||||||
|
if note_ids:
|
||||||
|
c_filter = models.Filter(must=[models.FieldCondition(key="note_id", match=models.MatchAny(any=note_ids))])
|
||||||
|
chunks, _ = self.client.scroll(self.chunks_col, scroll_filter=c_filter, limit=300)
|
||||||
|
chunk_ids = [c.id for c in chunks]
|
||||||
|
|
||||||
|
shoulds = []
|
||||||
|
# Case A: Edge zeigt auf einen unserer Chunks
|
||||||
|
if chunk_ids:
|
||||||
|
shoulds.append(models.FieldCondition(key="target_id", match=models.MatchAny(any=chunk_ids)))
|
||||||
|
|
||||||
|
# Case B: Edge zeigt direkt auf unsere Note ID
|
||||||
|
if note_ids:
|
||||||
|
shoulds.append(models.FieldCondition(key="target_id", match=models.MatchAny(any=note_ids)))
|
||||||
|
|
||||||
|
# Case C: Edge zeigt auf unseren Titel (Wikilinks)
|
||||||
|
if note_title:
|
||||||
|
shoulds.append(models.FieldCondition(key="target_id", match=models.MatchValue(value=note_title)))
|
||||||
|
|
||||||
|
if shoulds:
|
||||||
|
in_filter = models.Filter(
|
||||||
|
must=[models.FieldCondition(key="kind", match=models.MatchExcept(**{"except": SYSTEM_EDGES}))],
|
||||||
|
should=shoulds
|
||||||
|
)
|
||||||
|
res_in, _ = self.client.scroll(self.edges_col, scroll_filter=in_filter, limit=500, with_payload=True)
|
||||||
|
results.extend(res_in)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def _find_connected_edges_batch(self, note_ids):
|
||||||
|
# Wrapper für Level 2 Suche
|
||||||
|
return self._find_connected_edges(note_ids)
|
||||||
|
|
||||||
|
def _process_edge(self, record, nodes_dict, unique_edges, current_depth):
|
||||||
|
"""Verarbeitet eine rohe Edge, löst IDs auf und fügt sie den Dictionaries hinzu."""
|
||||||
|
payload = record.payload
|
||||||
|
src_ref = payload.get("source_id")
|
||||||
|
tgt_ref = payload.get("target_id")
|
||||||
|
kind = payload.get("kind")
|
||||||
|
provenance = payload.get("provenance", "explicit")
|
||||||
|
|
||||||
|
# IDs zu Notes auflösen
|
||||||
|
src_note = self._resolve_note_from_ref(src_ref)
|
||||||
|
tgt_note = self._resolve_note_from_ref(tgt_ref)
|
||||||
|
|
||||||
|
if src_note and tgt_note:
|
||||||
|
src_id = src_note['note_id']
|
||||||
|
tgt_id = tgt_note['note_id']
|
||||||
|
|
||||||
|
if src_id != tgt_id:
|
||||||
|
# Nodes hinzufügen
|
||||||
|
self._add_node_to_dict(nodes_dict, src_note, level=current_depth)
|
||||||
|
self._add_node_to_dict(nodes_dict, tgt_note, level=current_depth)
|
||||||
|
|
||||||
|
# Kante hinzufügen (mit Deduplizierung)
|
||||||
|
key = (src_id, tgt_id)
|
||||||
|
existing = unique_edges.get(key)
|
||||||
|
|
||||||
|
should_update = True
|
||||||
|
# Bevorzuge explizite Kanten vor Smart Kanten
|
||||||
|
is_current_explicit = (provenance in ["explicit", "rule"])
|
||||||
|
if existing:
|
||||||
|
is_existing_explicit = (existing['provenance'] in ["explicit", "rule"])
|
||||||
|
if is_existing_explicit and not is_current_explicit:
|
||||||
|
should_update = False
|
||||||
|
|
||||||
|
if should_update:
|
||||||
|
unique_edges[key] = {"source": src_id, "target": tgt_id, "kind": kind, "provenance": provenance}
|
||||||
|
return src_id, tgt_id
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
def _fetch_note_cached(self, note_id):
|
||||||
|
if note_id in self._note_cache: return self._note_cache[note_id]
|
||||||
|
res, _ = self.client.scroll(
|
||||||
|
collection_name=self.notes_col,
|
||||||
|
scroll_filter=models.Filter(must=[models.FieldCondition(key="note_id", match=models.MatchValue(value=note_id))]),
|
||||||
|
limit=1, with_payload=True
|
||||||
|
)
|
||||||
|
if res:
|
||||||
|
self._note_cache[note_id] = res[0].payload
|
||||||
|
return res[0].payload
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _resolve_note_from_ref(self, ref_str):
|
||||||
|
"""Löst eine ID (Chunk, Note oder Titel) zu einer Note Payload auf."""
|
||||||
|
if not ref_str: return None
|
||||||
|
|
||||||
|
# Fall A: Chunk ID (enthält #)
|
||||||
|
if "#" in ref_str:
|
||||||
|
try:
|
||||||
|
# Versuch 1: Chunk ID direkt
|
||||||
|
res = self.client.retrieve(self.chunks_col, ids=[ref_str], with_payload=True)
|
||||||
|
if res: return self._fetch_note_cached(res[0].payload.get("note_id"))
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
# Versuch 2: NoteID#Section (Hash abtrennen)
|
||||||
|
possible_note_id = ref_str.split("#")[0]
|
||||||
|
if self._fetch_note_cached(possible_note_id): return self._fetch_note_cached(possible_note_id)
|
||||||
|
|
||||||
|
# Fall B: Note ID direkt
|
||||||
|
if self._fetch_note_cached(ref_str): return self._fetch_note_cached(ref_str)
|
||||||
|
|
||||||
|
# Fall C: Titel
|
||||||
|
res, _ = self.client.scroll(
|
||||||
|
collection_name=self.notes_col,
|
||||||
|
scroll_filter=models.Filter(must=[models.FieldCondition(key="title", match=models.MatchValue(value=ref_str))]),
|
||||||
|
limit=1, with_payload=True
|
||||||
|
)
|
||||||
|
if res:
|
||||||
|
self._note_cache[res[0].payload['note_id']] = res[0].payload
|
||||||
|
return res[0].payload
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _add_node_to_dict(self, node_dict, note_payload, level=1):
|
||||||
|
nid = note_payload.get("note_id")
|
||||||
|
if nid in node_dict: return
|
||||||
|
|
||||||
|
ntype = note_payload.get("type", "default")
|
||||||
|
color = GRAPH_COLORS.get(ntype, GRAPH_COLORS["default"])
|
||||||
|
|
||||||
|
# Basis-Tooltip (wird später erweitert)
|
||||||
|
tooltip = f"Titel: {note_payload.get('title')}\nTyp: {ntype}"
|
||||||
|
|
||||||
|
if level == 0: size = 45
|
||||||
|
elif level == 1: size = 25
|
||||||
|
else: size = 15
|
||||||
|
|
||||||
|
node_dict[nid] = Node(
|
||||||
|
id=nid,
|
||||||
|
label=note_payload.get('title', nid),
|
||||||
|
size=size,
|
||||||
|
color=color,
|
||||||
|
shape="dot" if level > 0 else "diamond",
|
||||||
|
title=tooltip,
|
||||||
|
font={'color': 'black', 'face': 'arial', 'size': 14 if level < 2 else 0}
|
||||||
|
)
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import streamlit as st
|
||||||
|
from ui_utils import load_history_from_logs
|
||||||
|
from ui_config import HISTORY_FILE
|
||||||
|
|
||||||
|
def render_sidebar():
|
||||||
|
with st.sidebar:
|
||||||
|
st.title("🧠 mindnet")
|
||||||
|
st.caption("v2.6 | WP-19 Graph View")
|
||||||
|
|
||||||
|
if "sidebar_mode_selection" not in st.session_state:
|
||||||
|
st.session_state["sidebar_mode_selection"] = "💬 Chat"
|
||||||
|
|
||||||
|
mode = st.radio(
|
||||||
|
"Modus",
|
||||||
|
[
|
||||||
|
"💬 Chat",
|
||||||
|
"📝 Manueller Editor",
|
||||||
|
"🕸️ Graph (Agraph)",
|
||||||
|
"🕸️ Graph (Cytoscape)" # <-- Neuer Punkt
|
||||||
|
],
|
||||||
|
key="sidebar_mode_selection"
|
||||||
|
)
|
||||||
|
|
||||||
|
st.divider()
|
||||||
|
st.subheader("⚙️ Settings")
|
||||||
|
top_k = st.slider("Quellen (Top-K)", 1, 10, 5)
|
||||||
|
explain = st.toggle("Explanation Layer", True)
|
||||||
|
|
||||||
|
st.divider()
|
||||||
|
st.subheader("🕒 Verlauf")
|
||||||
|
for q in load_history_from_logs(HISTORY_FILE, 8):
|
||||||
|
if st.button(f"🔎 {q[:25]}...", key=f"hist_{q}", use_container_width=True):
|
||||||
|
st.session_state.messages.append({"role": "user", "content": q})
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
return mode, top_k, explain
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
import re
|
||||||
|
import yaml
|
||||||
|
import unicodedata
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def slugify(value):
|
||||||
|
if not value: return ""
|
||||||
|
value = str(value).lower()
|
||||||
|
replacements = {'ä': 'ae', 'ö': 'oe', 'ü': 'ue', 'ß': 'ss', '&': 'und', '+': 'und'}
|
||||||
|
for k, v in replacements.items():
|
||||||
|
value = value.replace(k, v)
|
||||||
|
|
||||||
|
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
|
||||||
|
value = re.sub(r'[^\w\s-]', '', value).strip()
|
||||||
|
return re.sub(r'[-\s]+', '-', value)
|
||||||
|
|
||||||
|
def normalize_meta_and_body(meta, body):
|
||||||
|
ALLOWED_KEYS = {"title", "type", "status", "tags", "id", "created", "updated", "aliases", "lang"}
|
||||||
|
clean_meta = {}
|
||||||
|
extra_content = []
|
||||||
|
|
||||||
|
if "titel" in meta and "title" not in meta:
|
||||||
|
meta["title"] = meta.pop("titel")
|
||||||
|
|
||||||
|
tag_candidates = ["tags", "emotionale_keywords", "keywords", "schluesselwoerter"]
|
||||||
|
all_tags = []
|
||||||
|
for key in tag_candidates:
|
||||||
|
if key in meta:
|
||||||
|
val = meta[key]
|
||||||
|
if isinstance(val, list): all_tags.extend(val)
|
||||||
|
elif isinstance(val, str): all_tags.extend([t.strip() for t in val.split(",")])
|
||||||
|
|
||||||
|
for key, val in meta.items():
|
||||||
|
if key in ALLOWED_KEYS:
|
||||||
|
clean_meta[key] = val
|
||||||
|
elif key in tag_candidates:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if val and isinstance(val, str):
|
||||||
|
header = key.replace("_", " ").title()
|
||||||
|
extra_content.append(f"## {header}\n{val}\n")
|
||||||
|
|
||||||
|
if all_tags:
|
||||||
|
clean_tags = []
|
||||||
|
for t in all_tags:
|
||||||
|
t_clean = str(t).replace("#", "").strip()
|
||||||
|
if t_clean: clean_tags.append(t_clean)
|
||||||
|
clean_meta["tags"] = list(set(clean_tags))
|
||||||
|
|
||||||
|
if extra_content:
|
||||||
|
new_section = "\n".join(extra_content)
|
||||||
|
final_body = f"{new_section}\n{body}"
|
||||||
|
else:
|
||||||
|
final_body = body
|
||||||
|
|
||||||
|
return clean_meta, final_body
|
||||||
|
|
||||||
|
def parse_markdown_draft(full_text):
|
||||||
|
clean_text = full_text.strip()
|
||||||
|
pattern_block = r"```(?:markdown|md|yaml)?\s*(.*?)\s*```"
|
||||||
|
match_block = re.search(pattern_block, clean_text, re.DOTALL | re.IGNORECASE)
|
||||||
|
if match_block:
|
||||||
|
clean_text = match_block.group(1).strip()
|
||||||
|
|
||||||
|
meta = {}
|
||||||
|
body = clean_text
|
||||||
|
yaml_str = ""
|
||||||
|
|
||||||
|
parts = re.split(r"^---+\s*$", clean_text, maxsplit=2, flags=re.MULTILINE)
|
||||||
|
|
||||||
|
if len(parts) >= 3:
|
||||||
|
yaml_str = parts[1]
|
||||||
|
body = parts[2]
|
||||||
|
elif clean_text.startswith("---"):
|
||||||
|
fallback_match = re.search(r"^---\s*(.*?)(?=\n#)", clean_text, re.DOTALL | re.MULTILINE)
|
||||||
|
if fallback_match:
|
||||||
|
yaml_str = fallback_match.group(1)
|
||||||
|
body = clean_text.replace(f"---{yaml_str}", "", 1).strip()
|
||||||
|
|
||||||
|
if yaml_str:
|
||||||
|
yaml_str_clean = yaml_str.replace("#", "")
|
||||||
|
try:
|
||||||
|
parsed = yaml.safe_load(yaml_str_clean)
|
||||||
|
if isinstance(parsed, dict):
|
||||||
|
meta = parsed
|
||||||
|
except Exception as e:
|
||||||
|
print(f"YAML Parsing Warning: {e}")
|
||||||
|
|
||||||
|
if not meta.get("title"):
|
||||||
|
h1_match = re.search(r"^#\s+(.*)$", body, re.MULTILINE)
|
||||||
|
if h1_match:
|
||||||
|
meta["title"] = h1_match.group(1).strip()
|
||||||
|
|
||||||
|
if meta.get("type") == "draft":
|
||||||
|
meta["status"] = "draft"
|
||||||
|
meta["type"] = "experience"
|
||||||
|
|
||||||
|
return normalize_meta_and_body(meta, body)
|
||||||
|
|
||||||
|
def build_markdown_doc(meta, body):
|
||||||
|
if "id" not in meta or meta["id"] == "generated_on_save":
|
||||||
|
raw_title = meta.get('title', 'note')
|
||||||
|
clean_slug = slugify(raw_title)[:50] or "note"
|
||||||
|
meta["id"] = f"{datetime.now().strftime('%Y%m%d')}-{clean_slug}"
|
||||||
|
|
||||||
|
meta["updated"] = datetime.now().strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
ordered_meta = {}
|
||||||
|
prio_keys = ["id", "type", "title", "status", "tags"]
|
||||||
|
for k in prio_keys:
|
||||||
|
if k in meta: ordered_meta[k] = meta.pop(k)
|
||||||
|
ordered_meta.update(meta)
|
||||||
|
|
||||||
|
try:
|
||||||
|
yaml_str = yaml.dump(ordered_meta, default_flow_style=None, sort_keys=False, allow_unicode=True).strip()
|
||||||
|
except:
|
||||||
|
yaml_str = "error: generating_yaml"
|
||||||
|
|
||||||
|
return f"---\n{yaml_str}\n---\n\n{body}"
|
||||||
|
|
||||||
|
def load_history_from_logs(filepath, limit=10):
|
||||||
|
queries = []
|
||||||
|
if filepath.exists():
|
||||||
|
try:
|
||||||
|
with open(filepath, "r", encoding="utf-8") as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
for line in reversed(lines):
|
||||||
|
try:
|
||||||
|
entry = json.loads(line)
|
||||||
|
q = entry.get("query_text")
|
||||||
|
if q and q not in queries:
|
||||||
|
queries.append(q)
|
||||||
|
if len(queries) >= limit: break
|
||||||
|
except: continue
|
||||||
|
except: pass
|
||||||
|
return queries
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
# Mindnet v2.6 – Documentation Map & Governance
|
||||||
|
**Status:** Active
|
||||||
|
**Context:** Central Navigation & Maintenance Guide
|
||||||
|
|
||||||
|
## 1. Zweck dieses Dokuments
|
||||||
|
|
||||||
|
Diese Karte dient Entwicklern, dem Mindmaster und KI-Agenten als **zentraler Einstiegspunkt**. Sie beantwortet zwei Fragen:
|
||||||
|
1. **Navigation:** In welcher Datei finde ich Informationen zu Thema X?
|
||||||
|
2. **Wartung:** Ich arbeite an Feature Y – welche Dateien muss ich aktualisieren?
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Verzeichnisstruktur & Inhalte
|
||||||
|
|
||||||
|
Das Repository ist in **logische Domänen** unterteilt.
|
||||||
|
|
||||||
|
### 📂 00_General (Grundlagen)
|
||||||
|
*Zielgruppe: Alle*
|
||||||
|
| Datei | Inhalt & Zweck |
|
||||||
|
| :--- | :--- |
|
||||||
|
| `00_vision_and_strategy.md` | **Strategie.** Warum bauen wir das? Prinzipien (Privacy, Local-First), High-Level Architektur. |
|
||||||
|
| `00_glossary.md` | **Definitionen.** Was bedeutet "Smart Edge", "Traffic Control", "Chunk"? Verhindert Begriffsverwirrung. |
|
||||||
|
| `00_documentation_map.md` | **Dieser Index.** Navigationshilfe. |
|
||||||
|
|
||||||
|
### 📂 01_User_Manual (Anwendung)
|
||||||
|
*Zielgruppe: Mindmaster, Autoren, Power-User*
|
||||||
|
| Datei | Inhalt & Zweck |
|
||||||
|
| :--- | :--- |
|
||||||
|
| `01_chat_usage_guide.md` | **Bedienung.** Wie steuere ich die Personas (Berater, Spiegel)? Wie nutze ich das Feedback? |
|
||||||
|
| `01_knowledge_design.md` | **Content-Regeln.** Die "Bibel" für den Vault. Erklärt Note-Typen, Matrix-Logik und Markdown-Syntax. |
|
||||||
|
|
||||||
|
### 📂 02_Concepts (Fachliche Logik)
|
||||||
|
*Zielgruppe: Architekten, Product Owner*
|
||||||
|
| Datei | Inhalt & Zweck |
|
||||||
|
| :--- | :--- |
|
||||||
|
| `02_concept_graph_logic.md` | **Graph-Theorie.** Abstrakte Erklärung von Knoten, Kanten, Provenance und Idempotenz. |
|
||||||
|
| `02_concept_ai_personality.md`| **KI-Verhalten.** Konzepte hinter dem Hybrid Router, Empathie-Modell und "Teach-the-AI". |
|
||||||
|
|
||||||
|
### 📂 03_Technical_Reference (Technik & Code)
|
||||||
|
*Zielgruppe: Entwickler, DevOps. (Enthält JSON/YAML Beispiele)*
|
||||||
|
| Datei | Inhalt & Zweck |
|
||||||
|
| :--- | :--- |
|
||||||
|
| `03_tech_data_model.md` | **Datenbank.** Exakte Qdrant-Schemas (Payloads) und Index-Anforderungen. |
|
||||||
|
| `03_tech_ingestion_pipeline.md`| **Import.** Ablauflogik (13 Schritte), Chunker-Profile, Smart Edge Allocation. |
|
||||||
|
| `03_tech_retrieval_scoring.md` | **Suche.** Die mathematischen Formeln für Scoring, Hybrid Search und Explanation Layer. |
|
||||||
|
| `03_tech_chat_backend.md` | **API & LLM.** Implementation des Routers, Traffic Control (Semaphore) und Feedback-Traceability. |
|
||||||
|
| `03_tech_frontend.md` | **UI & Graph.** Architektur des Streamlit-Frontends, State-Management, Cytoscape-Integration und Editor-Logik. |
|
||||||
|
| `03_tech_configuration.md` | **Config.** Referenztabellen für `.env`, `types.yaml` und `retriever.yaml`. |
|
||||||
|
|
||||||
|
### 📂 04_Operations (Betrieb)
|
||||||
|
*Zielgruppe: Administratoren*
|
||||||
|
| Datei | Inhalt & Zweck |
|
||||||
|
| :--- | :--- |
|
||||||
|
| `04_admin_operations.md` | **Runbook.** Installation, Docker-Setup, Backup/Restore, Troubleshooting Guide. |
|
||||||
|
|
||||||
|
### 📂 05_Development (Code)
|
||||||
|
*Zielgruppe: Entwickler*
|
||||||
|
| Datei | Inhalt & Zweck |
|
||||||
|
| :--- | :--- |
|
||||||
|
| `05_developer_guide.md` | **Workflow.** Hardware-Setup (Win/Pi/Beelink), Git-Flow, Test-Befehle, Modul-Interna. |
|
||||||
|
|
||||||
|
### 📂 06_Roadmap & 99_Archive
|
||||||
|
*Zielgruppe: Projektleitung*
|
||||||
|
| Datei | Inhalt & Zweck |
|
||||||
|
| :--- | :--- |
|
||||||
|
| `06_active_roadmap.md` | **Zukunft.** Aktive Workpackages (WP16+), Release-Planung und WP-Historie (Tabelle). |
|
||||||
|
| `99_legacy_workpackages.md` | **Vergangenheit.** Detaillierte Archivdaten zu abgeschlossenen WPs (WP01–WP15). |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Maintenance Guide: "Welche Datei muss ich ändern?"
|
||||||
|
|
||||||
|
Nutze diese Matrix, wenn du ein Workpackage bearbeitest, um die Dokumentation konsistent zu halten.
|
||||||
|
|
||||||
|
| Wenn du arbeitest an... | ...aktualisiere diese Dateien: |
|
||||||
|
| :--- | :--- |
|
||||||
|
| **Neuen Note-Typen** | 1. `01_knowledge_design.md` (Für Autoren)<br>2. `03_tech_configuration.md` (Technische Referenz)<br>3. `05_developer_guide.md` (Erweiterungs-How-To) |
|
||||||
|
| **Importer / Parsing** | `03_tech_ingestion_pipeline.md` |
|
||||||
|
| **Datenbank-Schema** | `03_tech_data_model.md` (Payloads anpassen) |
|
||||||
|
| **Retrieval / Scoring** | `03_tech_retrieval_scoring.md` (Formeln anpassen) |
|
||||||
|
| **Frontend / Visualisierung** | 1. `03_tech_frontend.md` (Technische Details)<br>2. `01_chat_usage_guide.md` (Bedienung) |
|
||||||
|
| **Chat-Logik / Prompts**| 1. `02_concept_ai_personality.md` (Konzept)<br>2. `03_tech_chat_backend.md` (Tech)<br>3. `01_chat_usage_guide.md` (User-Sicht) |
|
||||||
|
| **Deployment / Server** | `04_admin_operations.md` |
|
||||||
|
| **Neuen Features (Allg.)**| `06_active_roadmap.md` (Status Update) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Prinzipien für die Dokumentation (Governance)
|
||||||
|
|
||||||
|
Damit dieses System wartbar bleibt (auch für KI-Agenten wie NotebookLM), gelten folgende Regeln:
|
||||||
|
|
||||||
|
1. **Single Source of Truth:**
|
||||||
|
Kopiere keine Informationen. Referenziere sie.
|
||||||
|
* *Ausnahme:* Konkrete JSON-Beispiele in `03_Technical_Reference`. Diese müssen dort stehen, damit Entwickler nicht suchen müssen.
|
||||||
|
|
||||||
|
2. **Konkrete Beispiele:**
|
||||||
|
Technische Dokumente (`03_*`) müssen **immer** Code-Snippets (JSON, YAML, Shell) enthalten. Abstrakte Beschreibungen reichen nicht für die Implementierung.
|
||||||
|
|
||||||
|
3. **Human Readable:**
|
||||||
|
User Manuals (`01_*`) müssen Narrative und Szenarien enthalten ("Stell dir vor..."), keine technischen Auflistungen.
|
||||||
|
|
||||||
|
4. **KI-Optimiert (Context Header):**
|
||||||
|
Jede Datei muss mit einem YAML-Frontmatter beginnen, der `context`, `audience` und `scope` definiert. Dies hilft RAG-Systemen, den Inhalt korrekt einzuordnen.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
doc_type: technical_reference
|
||||||
|
audience: developer
|
||||||
|
context: "Beschreibung der Scoring-Formel."
|
||||||
|
---
|
||||||
|
```
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
---
|
||||||
|
doc_type: glossary
|
||||||
|
audience: all
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Definitionen zentraler Begriffe und Entitäten im Mindnet-System."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Mindnet Glossar
|
||||||
|
|
||||||
|
**Quellen:** `appendix.md`, `Overview.md`
|
||||||
|
|
||||||
|
## Kern-Entitäten
|
||||||
|
|
||||||
|
* **Note:** Repräsentiert eine Markdown-Datei. Die fachliche Haupteinheit.
|
||||||
|
* **Chunk:** Ein Textabschnitt einer Note (meist 512 Tokens). Die technische Sucheinheit (Vektor).
|
||||||
|
* **Edge:** Eine gerichtete Verbindung zwischen zwei Knoten (Chunks oder Notes).
|
||||||
|
* **Vault:** Der lokale Ordner mit den Markdown-Dateien (Source of Truth).
|
||||||
|
* **Frontmatter:** Der YAML-Header am Anfang einer Notiz (enthält `id`, `type`, `title`).
|
||||||
|
|
||||||
|
## Komponenten
|
||||||
|
|
||||||
|
* **Importer:** Das Python-Skript (`ingestion.py`), das Markdown liest und in Qdrant schreibt.
|
||||||
|
* **Retriever:** Die Komponente, die sucht. Nutzt hybrides Scoring (Semantik + Graph).
|
||||||
|
* **Decision Engine:** Teil des Routers, der entscheidet, wie auf eine Anfrage reagiert wird (z.B. Strategie wählen).
|
||||||
|
* **Hybrid Router v5:** Die Logik, die erkennt, ob der User eine Frage stellt (`RAG`) oder einen Befehl gibt (`INTERVIEW`).
|
||||||
|
* **Draft Editor:** Die Web-UI-Komponente, in der generierte Notizen bearbeitet werden.
|
||||||
|
* **Traffic Control:** Ein Mechanismus im `LLMService`, der Chat-Anfragen priorisiert und Hintergrund-Jobs (wie Import) drosselt.
|
||||||
|
|
||||||
|
## Konzepte & Features
|
||||||
|
|
||||||
|
* **Active Intelligence:** Feature im Web-Editor, das während des Schreibens automatisch Links vorschlägt.
|
||||||
|
* **Smart Edge Allocation (WP15):** Ein KI-Verfahren, das prüft, ob ein Link in einer Notiz für einen spezifischen Textabschnitt relevant ist.
|
||||||
|
* **Healing Parser:** UI-Funktion, die fehlerhaften Output des LLMs (z.B. defektes YAML) automatisch repariert.
|
||||||
|
* **Explanation Layer:** Die Schicht, die dem Nutzer erklärt, *warum* ein Suchergebnis gefunden wurde (z.B. "Weil Projekt X davon abhängt").
|
||||||
|
* **Provenance:** Die Herkunft einer Kante.
|
||||||
|
* `explicit`: Vom Mensch geschrieben.
|
||||||
|
* `smart`: Vom LLM validiert.
|
||||||
|
* `rule`: Durch Config-Regel erzeugt.
|
||||||
|
* **Matrix Logic:** Regelwerk, das den Typ einer Kante basierend auf Quell- und Ziel-Typ bestimmt (z.B. Erfahrung -> Wert = `based_on`).
|
||||||
|
* **Idempotenz:** Die Eigenschaft des Importers, bei mehrfacher Ausführung dasselbe Ergebnis zu liefern ohne Duplikate.
|
||||||
|
* **Resurrection Pattern:** UI-Technik, um User-Eingaben beim Tab-Wechsel zu erhalten.
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
---
|
||||||
|
doc_type: strategy
|
||||||
|
audience: all
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Vision, Mission und Architekturprinzipien von Mindnet."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Mindnet Vision & Strategie
|
||||||
|
|
||||||
|
**Quellen:** `Programmplan_V2.2.md`
|
||||||
|
|
||||||
|
## 1. Programmauftrag
|
||||||
|
|
||||||
|
Mindnet v2.6 entwickelt ein persönliches, wachsendes KI-Gedächtnis. Es ist ein **Digitaler Zwilling**, der:
|
||||||
|
- Wissen, Erfahrungen und Werte speichert.
|
||||||
|
- Semantisch verknüpft (Graphen-basiert).
|
||||||
|
- Als Dialogpartner agiert (RAG-Chat).
|
||||||
|
- **Lokal und privat** läuft (Privacy First).
|
||||||
|
|
||||||
|
Es ist **kein statisches Archiv**, sondern ein lebendes System, das durch Interaktion (Feedback, Smart Edges) besser wird.
|
||||||
|
|
||||||
|
## 2. Vision
|
||||||
|
|
||||||
|
> „Ein persönliches semantisches Gedächtnis, das mit mir wächst, meine Persönlichkeit spiegelt und mir als intelligenter, erklärbarer, lernender Begleiter dient.“
|
||||||
|
|
||||||
|
**Kernprinzipien der Vision:**
|
||||||
|
* **Erklärbarkeit:** Jede Antwort muss begründbar sein ("Why-Layer").
|
||||||
|
* **Wachstum:** Das System startet klein und verdichtet sich.
|
||||||
|
* **Autonomie:** Es schlägt fehlende Kanten selbstständig vor (Smart Edges).
|
||||||
|
* **Persönlichkeit:** Es entscheidet basierend auf *deinen* Werten.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Architekturprinzipien
|
||||||
|
|
||||||
|
Die folgenden Prinzipien steuern jede technische Entscheidung:
|
||||||
|
|
||||||
|
1. **Late Binding (Späte Semantik):**
|
||||||
|
Struktur und Interpretation werden in Konfigurationen (`types.yaml`, `prompts.yaml`) definiert, nicht direkt in den Vault-Dateien. Die "Persönlichkeit" ist Config, kein Code.
|
||||||
|
|
||||||
|
2. **Virtual Schema Layer:**
|
||||||
|
Markdown-Dateien benötigen nur minimale, robuste Angaben (Frontmatter). Komplexität (Chunk-Größe, Gewichte) wird zur Laufzeit injiziert.
|
||||||
|
|
||||||
|
3. **Self-Healing Graph:**
|
||||||
|
Der Graph wird regelmäßig auf Konsistenz geprüft. "Dangling Edges" werden bereinigt, fehlende Links durch Smart Edges ergänzt.
|
||||||
|
|
||||||
|
4. **Deterministische IDs:**
|
||||||
|
Notes und Chunks erhalten stabile IDs (UUIDv5). Der Graph ist jederzeit aus dem Markdown wiederaufbaubar.
|
||||||
|
|
||||||
|
5. **Full Explainability:**
|
||||||
|
Keine Blackbox. Jede Antwort liefert Metadaten (`[DECISION]`, `[PROJECT]`) und Begründungen.
|
||||||
|
|
||||||
|
6. **Persistence First:**
|
||||||
|
Obsidian (Markdown) bleibt die **einzige Quelle der Wahrheit**. Die Datenbank ist nur ein abgeleiteter Cache.
|
||||||
|
|
||||||
|
7. **Minimalinvasives Schreiben:**
|
||||||
|
Mindnet schreibt nie ungefragt in deine Notizen. Änderungen erfolgen nur über den Draft Editor oder mit expliziter Zustimmung.
|
||||||
|
|
||||||
|
8. **Incremental Growth:**
|
||||||
|
Das System muss bereits mit wenigen Notizen nützlich sein.
|
||||||
|
|
||||||
|
9. **Observability:**
|
||||||
|
Jeder Importlauf und jede Retriever-Anfrage ist logbar.
|
||||||
|
|
||||||
|
10. **Local First & Privacy:**
|
||||||
|
Nutzung lokaler LLMs (Ollama) für Inference. Keine Daten verlassen den Server.
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
---
|
||||||
|
doc_type: user_manual
|
||||||
|
audience: user, mindmaster
|
||||||
|
scope: chat, ui, feedback, graph
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Anleitung zur Nutzung der Web-Oberfläche, der Chat-Personas und des Graph Explorers."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Chat & Graph Usage Guide
|
||||||
|
|
||||||
|
**Quellen:** `user_guide.md`
|
||||||
|
|
||||||
|
## 1. Was Mindnet für dich tut
|
||||||
|
|
||||||
|
Mindnet ist ein **assoziatives Gedächtnis** mit Persönlichkeit. Es unterscheidet sich von einer reinen Suche dadurch, dass es **kontextsensitiv** agiert.
|
||||||
|
|
||||||
|
**Das Gedächtnis (Der Graph):**
|
||||||
|
Wenn du nach "Projekt Alpha" suchst, findet Mindnet auch:
|
||||||
|
* **Abhängigkeiten:** "Technologie X wird benötigt".
|
||||||
|
* **Entscheidungen:** "Warum nutzen wir X?".
|
||||||
|
* **Ähnliches:** "Projekt Beta war ähnlich".
|
||||||
|
|
||||||
|
**Der Zwilling (Die Personas):**
|
||||||
|
Mindnet passt seinen Charakter an: Mal ist es der neutrale Bibliothekar, mal der strategische Berater, mal der empathische Spiegel.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Die Oberfläche (Web UI)
|
||||||
|
|
||||||
|
Seit Version 2.3.1 bedienst du Mindnet über eine grafische Oberfläche im Browser.
|
||||||
|
|
||||||
|
### 2.1 Der Chat-Bereich
|
||||||
|
* **Intent-Badge:** Über jeder Antwort siehst du ein Label (z.B. **⚖️ Intent: DECISION**).
|
||||||
|
* **Quellen-Karten:** Unter der Antwort findest du ausklappbare Karten ("Expanders").
|
||||||
|
* **Grüner Punkt:** Hohe Relevanz (Score > 0.8).
|
||||||
|
* **Klick darauf:** Zeigt den Textauszug und die **Begründung** (Explanation Layer).
|
||||||
|
|
||||||
|
### 2.2 Modus: 🕸️ Graph Explorer (Cytoscape)
|
||||||
|
*Neu in v2.6*: Eine interaktive Karte deines Wissens.
|
||||||
|
|
||||||
|
**Die Farb-Logik:**
|
||||||
|
* 🔴 **Roter Rahmen:** Das aktuelle **Zentrum** (Ego). Alle geladenen Knoten sind Nachbarn dieses Knotens.
|
||||||
|
* 🟡 **Gelber Rahmen:** Der **inspizierte** Knoten. Dessen Details siehst du im "Data Inspector" und in der Action-Bar.
|
||||||
|
|
||||||
|
**Bedienung:**
|
||||||
|
1. **Klick auf einen Knoten:** Wählt ihn aus (Gelb). Der Graph bleibt stabil, aber die Info-Leiste oben aktualisiert sich.
|
||||||
|
2. **Button "🎯 Als Zentrum setzen":** Lädt den Graphen neu und macht den ausgewählten Knoten zum roten Zentrum.
|
||||||
|
3. **Button "📝 Bearbeiten":** Springt mit dem Inhalt dieses Knotens direkt in den Editor.
|
||||||
|
|
||||||
|
**Layout & Persistenz:**
|
||||||
|
Du kannst in der linken Spalte die Physik (Abstoßung, Kantenlänge) einstellen. Diese Einstellungen werden in der **URL gespeichert**. Du kannst den Link als Lesezeichen speichern, um genau diese Ansicht wiederzufinden.
|
||||||
|
|
||||||
|
### 2.3 Modus: 📝 Manueller Editor
|
||||||
|
Ein Editor mit **"File System First"** Garantie.
|
||||||
|
* Wenn du eine Datei bearbeitest, liest Mindnet sie direkt von der Festplatte.
|
||||||
|
* **Resurrection:** Wenn du zwischendurch in den Graph wechselst und zurückkommst, ist dein getippter Text noch da.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Den Chat steuern (Intents)
|
||||||
|
|
||||||
|
Du steuerst die Persönlichkeit von Mindnet durch deine Wortwahl. Der **Hybrid Router v5** unterscheidet intelligent:
|
||||||
|
|
||||||
|
### 3.1 Frage-Modus (Wissen abrufen)
|
||||||
|
Ausgelöst durch `?` oder W-Wörter.
|
||||||
|
|
||||||
|
* **Entscheidung ("Soll ich?"):** Der **Berater**.
|
||||||
|
* Mindnet lädt deine Werte (`type: value`) und Ziele (`type: goal`).
|
||||||
|
* *Beispiel:* "Soll ich Tool X nutzen?" -> "Nein, Tool X speichert Daten in den USA. Das verstößt gegen dein Prinzip 'Privacy First'."
|
||||||
|
* **Empathie ("Ich fühle..."):** Der **Spiegel**.
|
||||||
|
* Mindnet lädt deine Erfahrungen (`type: experience`).
|
||||||
|
* *Beispiel:* "Ich bin frustriert." -> "Das erinnert mich an Projekt Y, da ging es uns ähnlich..."
|
||||||
|
* **Fakten ("Was ist?"):** Der **Bibliothekar**.
|
||||||
|
* Liefert präzise Definitionen.
|
||||||
|
|
||||||
|
### 3.2 Befehls-Modus (Interview)
|
||||||
|
Ausgelöst durch Aussagen wie "Neues Projekt", "Ich will festhalten".
|
||||||
|
|
||||||
|
* **Was passiert:** Mindnet sucht nicht, sondern öffnet den **Draft-Editor**.
|
||||||
|
* **Beispiel:** "Neue Erfahrung: Streit am Recyclinghof." -> Das System erstellt sofort eine strukturierte Notiz mit den Feldern "Situation", "Reaktion" und "Learning".
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Ergebnisse interpretieren (Explanation Layer)
|
||||||
|
|
||||||
|
Mindnet liefert eine **Begründung** ("Reasons"), warum es etwas gefunden hat.
|
||||||
|
Öffne eine Quellen-Karte, um zu sehen:
|
||||||
|
* *"Hohe textuelle Übereinstimmung."* (Semantik)
|
||||||
|
* *"Bevorzugt aufgrund des Typs 'decision'."* (Wichtigkeit)
|
||||||
|
* *"Verweist auf 'Projekt X' via 'depends_on'."* (Graph-Kontext)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Feedback & Lernen
|
||||||
|
|
||||||
|
Mindnet wird schlauer, wenn du es pflegst.
|
||||||
|
|
||||||
|
* **Globales Feedback (Sterne):** Bewertet die generierte Antwort (Prompting, Tonfall).
|
||||||
|
* **Granulares Feedback (Smileys):** Bewertet die einzelne Quelle.
|
||||||
|
* 😞 (Sad): Irrelevant. (Senkt das Gewicht dieser Verbindung).
|
||||||
|
* 😀 (Grin): Perfekter Treffer! (Stärkt diesen Typ/Kante).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Neues Wissen beisteuern (Authoring & Intelligence)
|
||||||
|
|
||||||
|
Mindnet lebt von deinem Input. Du hast drei Wege, Wissen einzugeben:
|
||||||
|
|
||||||
|
### 6.1 Weg A: Der Interview-Assistent (Auto-Drafting)
|
||||||
|
1. **Start:** Schreibe im Chat: *"Ich möchte ein neues Projekt 'Apollo' starten."*
|
||||||
|
2. **Generierung:** Mindnet erkennt `INTERVIEW`, wählt das Schema und erstellt einen Entwurf.
|
||||||
|
3. **Editor:** Die UI zeigt den Entwurf (`status: draft`).
|
||||||
|
* *Healing UI:* Falls das LLM Syntax-Fehler gemacht hat, hat der Editor sie bereits repariert.
|
||||||
|
4. **Speichern:** Klicke auf "💾 Speichern".
|
||||||
|
|
||||||
|
### 6.2 Weg B: Der Intelligence-Workflow
|
||||||
|
Wenn du im **manuellen Editor** schreibst, unterstützt dich Mindnet aktiv bei der Vernetzung:
|
||||||
|
|
||||||
|
1. **Schreiben:** Tippe deinen Text im Tab **"✏️ Inhalt"**.
|
||||||
|
2. **Analysieren:** Wechsle zum Tab **"🧠 Intelligence"** und klicke auf **"🔍 Analyse starten"**. Das System scannt deinen Text (Vektor-Suche & Exact Match).
|
||||||
|
3. **Vorschläge nutzen:**
|
||||||
|
* **Exakte Treffer:** Das System erkennt Begriffe wie "KI-Gedächtnis" als Alias für "Mindnet".
|
||||||
|
* **Semantische Treffer:** Das System findet inhaltlich verwandte Notizen.
|
||||||
|
* **Klick auf "➕ Einfügen":** Fügt den Link (z.B. `[[rel:related_to Mindnet]]`) an der Cursor-Position ein.
|
||||||
|
4. **Speichern:** Der Text wird sofort in den Vault geschrieben und indiziert.
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
---
|
||||||
|
doc_type: user_manual
|
||||||
|
audience: user, author
|
||||||
|
scope: vault, markdown, schema
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Regelwerk für das Erstellen von Notizen im Vault. Die 'Source of Truth' für Autoren."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Knowledge Design Manual
|
||||||
|
|
||||||
|
**Quellen:** `knowledge_design.md`, `TYPE_REGISTRY_MANUAL.md`
|
||||||
|
|
||||||
|
## ⚡ Die 5 Goldenen Regeln (TL;DR)
|
||||||
|
|
||||||
|
Damit Mindnet als dein Digitaler Zwilling funktioniert, beachte beim Schreiben diese Grundsätze:
|
||||||
|
|
||||||
|
1. **Atomare Gedanken:** Eine Notiz = Ein Thema. Wenn du über zwei Projekte schreibst, mach zwei Notizen draus.
|
||||||
|
2. **Explizite Typen:** Setze immer den `type` im Frontmatter. Mindnet behandelt eine `decision` ("Wir machen X") völlig anders als ein `concept` ("Was ist X").
|
||||||
|
3. **Semantische Links:** Schreibe nicht nur `[[Link]]`, sondern `[[rel:depends_on Link]]`. Sag dem System *wie* Dinge zusammenhängen.
|
||||||
|
4. **Werte & Ziele definieren:** Damit die **Decision Engine** dich beraten kann, musst du deine Kriterien (`type: value`, `type: goal`) explizit als Notizen anlegen.
|
||||||
|
5. **Emotionales Bridging:** Damit die **Empathie** funktioniert, nutze in Erfahrungsberichten (`type: experience`) emotionale Schlüsselwörter ("Krise", "Freude", "Angst").
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Zweck & Scope
|
||||||
|
|
||||||
|
Mindnet ist mehr als eine Dokumentablage. Es ist ein vernetztes System, das deine Persönlichkeit abbildet. Die Markdown-Dateien in deinem Vault sind die **einzige Quelle der Wahrheit** ("Source of Truth"). Was nicht im Markdown steht, existiert für das System nicht.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Note-Struktur & Frontmatter
|
||||||
|
|
||||||
|
Jede Notiz benötigt einen YAML-Header (Frontmatter).
|
||||||
|
|
||||||
|
**Pflichtfelder:**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
id: 20251212-projekt-alpha # Eindeutige Kennung (YYYYMMDD-slug empfohlen)
|
||||||
|
title: Projekt Alpha # Sprechender Titel
|
||||||
|
type: project # Steuert Chunking & Wichtigkeit
|
||||||
|
status: active # active, archived, draft
|
||||||
|
created: 2025-12-12 # ISO 8601
|
||||||
|
tags: [ki, entwicklung] # Taxonomie
|
||||||
|
---
|
||||||
|
```
|
||||||
|
|
||||||
|
**Optionale Felder:**
|
||||||
|
* `aliases`: [Alpha Projekt] – Wichtig für "Active Intelligence" (Exact Match).
|
||||||
|
* `visibility`: internal (default) / public.
|
||||||
|
|
||||||
|
> **Wichtig:** Felder wie `retriever_weight` oder `chunk_profile` werden zentral über `types.yaml` gesteuert und müssen nicht mehr manuell gesetzt werden (Virtual Schema Layer).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Typ-Referenz & Verhalten
|
||||||
|
|
||||||
|
Wähle den Typ, der die **Rolle** der Notiz am besten beschreibt. Der Typ steuert Chunking, Gewichtung und Kanten-Logik.
|
||||||
|
|
||||||
|
| Typ | Beschreibung & Einsatzzweck | Rolle im Chat (Intent) | Matrix-Logik |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| **`concept`** | Fachbegriffe, Theorien. Zeitloses Wissen. | **FACT** | Ziel für `uses` |
|
||||||
|
| **`project`** | Ein Vorhaben mit Ziel, Dauer und Aufgaben. | **FACT / DECISION** | Quelle für `depends_on` |
|
||||||
|
| **`experience`** | Persönliche Erfahrung, Lektion oder Erkenntnis. | **EMPATHY** | Quelle für `based_on` |
|
||||||
|
| **`decision`** | Eine bewusst getroffene Entscheidung (ADR). | **DECISION** | Quelle für `caused_by` |
|
||||||
|
| **`value`** | Ein persönlicher Wert oder ein Prinzip. | **DECISION** | Ziel für `based_on` |
|
||||||
|
| **`principle`** | Handlungsleitlinie. | **DECISION** | Quelle für `derived_from` |
|
||||||
|
| **`goal`** | Ein strategisches Ziel. | **DECISION** | Ziel für `related_to` |
|
||||||
|
| **`risk`** | Ein identifiziertes Risiko. | **DECISION** | Quelle für `blocks` |
|
||||||
|
| **`journal`** | Zeitbezogener Log-Eintrag. | **FACT** | - |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Edges & Verlinkung
|
||||||
|
|
||||||
|
Mindnet versteht Zusammenhänge durch Kanten.
|
||||||
|
|
||||||
|
### 4.1 Inline-Relationen (Semantische Verknüpfung)
|
||||||
|
Dies ist die **mächtigste** Methode. Du sagst dem System explizit, **wie** Dinge zusammenhängen.
|
||||||
|
|
||||||
|
> "Daher [[rel:depends_on Qdrant]]."
|
||||||
|
> "Dieses Konzept ist [[rel:similar_to Pinecone]]."
|
||||||
|
|
||||||
|
**Gültige Relationen:**
|
||||||
|
* `depends_on`: Hängt ab von / Benötigt.
|
||||||
|
* `blocks`: Blockiert oder gefährdet (z.B. Risiko -> Projekt).
|
||||||
|
* `caused_by`: Wurde verursacht durch (Kausalität).
|
||||||
|
* `similar_to`: Ähnelt / Ist vergleichbar mit.
|
||||||
|
* `solves`: Löst (Problem).
|
||||||
|
* `based_on`: Basiert auf (Fundament).
|
||||||
|
|
||||||
|
### 4.2 Callout-Edges
|
||||||
|
Für Zusammenfassungen am Ende einer Notiz:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
> [!edge] related_to: [[Vector Embeddings]] [[AI Agents]]
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Schreiben für den KI-Zwilling (Szenarien)
|
||||||
|
|
||||||
|
Damit der **RAG-Chat** dich berät, musst du "Futter" für die Decision Engine liefern.
|
||||||
|
|
||||||
|
### Szenario A: Decision Engine (`DECISION`)
|
||||||
|
* **Ziel:** Das System soll abwägen: "Passt Tool X zu mir?"
|
||||||
|
* **Vorgehen:** Erstelle Notizen mit `type: value` oder `type: goal`.
|
||||||
|
|
||||||
|
**Beispiel Notiz:**
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
type: value
|
||||||
|
title: Prinzip: Datensparsamkeit
|
||||||
|
---
|
||||||
|
Wir speichern nur das Minimum an Daten. Cloud-Uploads persönlicher Daten sind verboten, es sei denn, sie sind E2E-verschlüsselt.
|
||||||
|
```
|
||||||
|
|
||||||
|
* **Effekt:** Wenn du fragst "Soll ich Notion nutzen?", lädt die Engine diese Notiz und antwortet: *"Nein, Notion ist SaaS ohne E2E. Das verletzt dein Prinzip der Datensparsamkeit."*
|
||||||
|
|
||||||
|
### Szenario B: Empathie (`EMPATHY`)
|
||||||
|
* **Ziel:** Das System soll dich verstehen.
|
||||||
|
* **Vorgehen:** Erstelle `type: experience` mit **emotionalen Brückenwörtern**.
|
||||||
|
|
||||||
|
**Beispiel Notiz:**
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
type: experience
|
||||||
|
title: Erfahrung: Der Durchbruch nach der Krise
|
||||||
|
tags: [krise, hoffnung, grau, angst]
|
||||||
|
---
|
||||||
|
Es gibt Projektphasen, da wirkt alles **sinnlos** und **grau**.
|
||||||
|
Ich habe gelernt: Das ist oft das Zeichen kurz vor dem Durchbruch.
|
||||||
|
```
|
||||||
|
* **Effekt:** Bei "Alles ist grau" findet das System diese Notiz und spiegelt die Lektion zurück.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Best Practices & Beispiele (Klassik)
|
||||||
|
|
||||||
|
Hier sind vollständige Vorlagen für häufige Typen.
|
||||||
|
|
||||||
|
### 6.1 Beispiel: Projekt-Notiz
|
||||||
|
Projekte profitieren von `depends_on`, um Abhängigkeiten zu klären.
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
---
|
||||||
|
id: 20251115-proj-mindnet
|
||||||
|
title: Mindnet Implementierung
|
||||||
|
type: project
|
||||||
|
status: active
|
||||||
|
---
|
||||||
|
|
||||||
|
# Mindnet Implementierung
|
||||||
|
|
||||||
|
Wir bauen ein persönliches Wissensnetz.
|
||||||
|
|
||||||
|
## Tech Stack
|
||||||
|
Wir nutzen [[rel:depends_on Qdrant]] für die Vektorsuche und [[rel:depends_on FastAPI]] für das Backend.
|
||||||
|
|
||||||
|
## Architektur
|
||||||
|
Das Konzept basiert auf [[RAG Architecture]]. (Automatisch 'depends_on' durch Typ-Default, falls konfiguriert).
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6.2 Beispiel: Entscheidung (Decision Record)
|
||||||
|
Entscheidungen sind hoch gewichtet (`retriever_weight: 1.0`).
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
---
|
||||||
|
id: 20251120-adr-vektordb
|
||||||
|
title: ADR: Wahl von Qdrant
|
||||||
|
type: decision
|
||||||
|
status: final
|
||||||
|
tags: [architektur, db]
|
||||||
|
---
|
||||||
|
|
||||||
|
# Entscheidung: Qdrant
|
||||||
|
|
||||||
|
Wir haben uns für Qdrant entschieden.
|
||||||
|
|
||||||
|
## Alternativen
|
||||||
|
Wir haben auch [[rel:similar_to Pinecone]] und [[rel:similar_to Weaviate]] betrachtet.
|
||||||
|
|
||||||
|
## Begründung
|
||||||
|
Qdrant erlaubt lokalen Betrieb und [[rel:solves Payload Filtering Requirements]].
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Langfristige Stabilität
|
||||||
|
|
||||||
|
Wir nutzen das Prinzip des **Virtual Schema Layers**. Wir kodieren keine Logik (wie `chunk_size`) in die Notizen. Das wird zentral in der `types.yaml` verwaltet. Das bedeutet für dich: Du kannst dich rein auf den Inhalt konzentrieren. Wenn wir die Chunking-Strategie ändern, müssen wir nicht 1000 Markdown-Dateien anfassen.
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
---
|
||||||
|
doc_type: concept
|
||||||
|
audience: architect, product_owner
|
||||||
|
scope: ai, router, personas
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Fachkonzept der KI-Persönlichkeit, der Decision Engine und Erweiterungsstrategien."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Konzept: KI-Persönlichkeit & Router
|
||||||
|
|
||||||
|
**Quellen:** `mindnet_functional_architecture.md`, `Programmplan_V2.2.md`
|
||||||
|
|
||||||
|
Mindnet soll nicht wie eine Suchmaschine wirken, sondern wie ein **Digitaler Zwilling**. Dazu muss das System erkennen, **was** der Nutzer will, und seine "Persönlichkeit" anpassen.
|
||||||
|
|
||||||
|
## 1. Der Hybrid Router (Das Gehirn)
|
||||||
|
|
||||||
|
Jede Eingabe durchläuft den **Hybrid Router**. Er entscheidet über die Strategie.
|
||||||
|
|
||||||
|
### Modus A: RAG (Retrieval Augmented Generation)
|
||||||
|
* *Intent:* Der Nutzer hat eine Frage oder ein Problem (`FACT`, `DECISION`, `EMPATHY`).
|
||||||
|
* *Aktion:* Das System sucht im Gedächtnis und generiert eine Antwort.
|
||||||
|
|
||||||
|
### Modus B: Interview (Knowledge Capture)
|
||||||
|
* *Intent:* Der Nutzer will Wissen speichern (`INTERVIEW`).
|
||||||
|
* *Aktion:* Das System sucht **nicht**, sondern fragt ab und erstellt einen Draft.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Die Personas (Strategien)
|
||||||
|
|
||||||
|
Mindnet wechselt den Hut, je nach Situation.
|
||||||
|
|
||||||
|
### 2.1 Der Berater (Strategy: DECISION)
|
||||||
|
* **Auslöser:** Fragen wie "Soll ich...?", "Was ist besser?".
|
||||||
|
* **Strategic Retrieval:** Lädt aktiv Notizen der Typen `value` (Werte), `goal` (Ziele) und `risk` (Risiken), auch wenn sie im Text nicht direkt vorkommen.
|
||||||
|
* **Reasoning:** *"Wäge die Fakten gegen meine Werte ab. Sei strikt bei Risiken."*
|
||||||
|
|
||||||
|
### 2.2 Der Spiegel (Strategy: EMPATHY)
|
||||||
|
* **Auslöser:** Emotionale Aussagen ("Ich bin frustriert").
|
||||||
|
* **Strategic Retrieval:** Lädt `experience` (Erfahrungen) und `belief` (Glaubenssätze).
|
||||||
|
* **Reasoning:** *"Nutze meine eigenen Erfahrungen, um die Situation einzuordnen."*
|
||||||
|
|
||||||
|
### 2.3 Der Bibliothekar (Strategy: FACT)
|
||||||
|
* **Auslöser:** Sachfragen ("Was ist Qdrant?").
|
||||||
|
* **Behavior:** Präzise, neutral, kurz.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Future Concepts: The Empathic Digital Twin
|
||||||
|
|
||||||
|
Um Mindnet von einer Maschine zu einem echten Spiegel der Persönlichkeit zu entwickeln, sind folgende Konzepte in der Architektur angelegt:
|
||||||
|
|
||||||
|
### 3.1 Antizipation durch Erfahrung
|
||||||
|
* **Konzept:** Das System soll Konsequenzen vorhersagen ("Was passiert, wenn...?").
|
||||||
|
* **Logik:** *"In einer ähnlichen Situation (Projekt A) hat Entscheidung X zu Ergebnis Y geführt."* (Analogie-Schluss).
|
||||||
|
|
||||||
|
### 3.2 Empathie & "Ich"-Modus
|
||||||
|
* **Konzept:** Das System antwortet im Tonfall des Nutzers.
|
||||||
|
* **Umsetzung:** Few-Shot Prompting mit eigenen E-Mails/Texten als Stilvorlage.
|
||||||
|
|
||||||
|
### 3.3 Glaubenssätze & Rituale
|
||||||
|
* **Konzept:** Berücksichtigung weicher Faktoren.
|
||||||
|
* **Szenario:** Bei Terminplanungen werden Rituale ("Keine Meetings vor 10 Uhr") automatisch als harte Restriktion gegen Anfragen geprüft.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Erweiterbarkeit: Das "Teach-the-AI" Paradigma
|
||||||
|
|
||||||
|
Mindnet lernt nicht durch Training (Fine-Tuning), sondern durch **Konfiguration** und **Vernetzung**. Wenn du dem System ein neues Konzept beibringen willst, musst du an drei Stellen eingreifen.
|
||||||
|
|
||||||
|
**Beispiel: Du willst den Typ `risk` einführen.**
|
||||||
|
|
||||||
|
**1. Daten-Ebene (Physik)**
|
||||||
|
In `types.yaml`: Definiere Gewicht und Verhalten.
|
||||||
|
```yaml
|
||||||
|
risk:
|
||||||
|
retriever_weight: 0.90 # Hohe Priorität
|
||||||
|
edge_defaults: ["blocks"] # Automatische Kante zu Projekten
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. Strategie-Ebene (Router)**
|
||||||
|
In `decision_engine.yaml`: Wann soll das geladen werden?
|
||||||
|
```yaml
|
||||||
|
DECISION:
|
||||||
|
inject_types: ["value", "risk"] # Füge 'risk' hinzu
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. Kognitive Ebene (Verständnis)**
|
||||||
|
In `prompts.yaml`: Erkläre dem LLM, was ein Risiko ist.
|
||||||
|
|
||||||
|
**Fazit:** Nur wenn **Daten** (Vault), **Physik** (Config) und **Semantik** (Prompt) zusammenspielen, entsteht ein intelligenter Zwilling.
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
---
|
||||||
|
doc_type: concept
|
||||||
|
audience: architect, product_owner
|
||||||
|
scope: graph, logic, provenance
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Fachliche Beschreibung des Wissensgraphen: Knoten, Kanten, Provenance und Matrix-Logik."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Konzept: Die Graph-Logik
|
||||||
|
|
||||||
|
**Quellen:** `mindnet_functional_architecture.md`, `chunking_strategy.md`
|
||||||
|
|
||||||
|
Mindnet ist keine reine Dokumentablage, sondern ein **semantischer Graph**. Dieses Dokument beschreibt, wie aus statischen Textdateien ein vernetztes Wissensobjekt wird.
|
||||||
|
|
||||||
|
## 1. Die Knoten (Nodes)
|
||||||
|
|
||||||
|
Der Graph besteht aus zwei Ebenen von Knoten.
|
||||||
|
|
||||||
|
### 1.1 Die Note (Das Fachobjekt)
|
||||||
|
Eine Note repräsentiert ein atomares Konzept (z.B. "Projekt Alpha").
|
||||||
|
* **Eigenschaften:** Titel, Typ, Tags, Erstellungsdatum.
|
||||||
|
* **Rolle:** Sie ist der Container für Metadaten und steuert via `type`, wie der Inhalt verarbeitet wird (siehe `types.yaml`).
|
||||||
|
* **Identität:** Definiert durch eine deterministische UUIDv5.
|
||||||
|
|
||||||
|
### 1.2 Der Chunk (Das Suchobjekt)
|
||||||
|
Da LLMs (Large Language Models) nicht unendlich viel Text auf einmal lesen können, werden Notes in kleinere Segmente (**Chunks**) zerlegt.
|
||||||
|
* **Eigenschaften:** Vektor (Embedding 768d), Textfenster, Link zum Vorgänger/Nachfolger.
|
||||||
|
* **Rolle:** Dies sind die eigentlichen Treffer bei einer Suche.
|
||||||
|
* **Hierarchie:** Jeder Chunk gehört streng zu einer Note (`belongs_to`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Die Kanten (Edges)
|
||||||
|
|
||||||
|
Kanten machen aus isolierten Informationen Wissen. Mindnet nutzt gerichtete Kanten mit semantischer Bedeutung.
|
||||||
|
|
||||||
|
### 2.1 Semantische Typen
|
||||||
|
|
||||||
|
| Kanten-Typ | Frage, die er beantwortet | Beispiel |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `references` | Worüber wird gesprochen? | Text erwähnt "Python". |
|
||||||
|
| `depends_on` | Was ist Voraussetzung? | Projekt braucht "Budget". |
|
||||||
|
| `caused_by` | Warum ist das passiert? | Bug durch "Commit X". |
|
||||||
|
| `blocks` | Was steht im Weg? | Risiko blockiert "Release". |
|
||||||
|
| `based_on` | Worauf fußt das? | Erfahrung basiert auf "Wert Y". |
|
||||||
|
| `derived_from` | Woher kommt das? | Prinzip stammt aus "Buch Z". |
|
||||||
|
| `related_to` | Was ist ähnlich? | "Hund" ist verwandt mit "Wolf". |
|
||||||
|
| `solves` | Was ist die Lösung? | "Qdrant" löst "Vektorsuche". |
|
||||||
|
|
||||||
|
### 2.2 Provenance (Herkunft & Vertrauen)
|
||||||
|
|
||||||
|
Nicht alle Kanten sind gleich viel wert. Mindnet unterscheidet in v2.6 drei Qualitätsstufen (**Provenance**), um Konflikte aufzulösen.
|
||||||
|
|
||||||
|
**1. Explicit (Der Mensch hat es gesagt)**
|
||||||
|
* *Quelle:* Inline-Links (`[[rel:...]]`) oder Wikilinks im Text.
|
||||||
|
* *Vertrauen:* **Hoch (1.0)**.
|
||||||
|
* *Bedeutung:* Dies ist hartes Faktenwissen. "Ich habe diesen Link bewusst gesetzt."
|
||||||
|
|
||||||
|
**2. Smart (Die KI hat es bestätigt)**
|
||||||
|
* *Quelle:* Smart Edge Allocation (WP15).
|
||||||
|
* *Vertrauen:* **Mittel (0.9)**.
|
||||||
|
* *Bedeutung:* Ein LLM hat geprüft, ob der Link im Kontext dieses Textabschnitts wirklich relevant ist. Dies filtert "Rauschen" heraus (z.B. Links im Footer, die nichts mit dem Absatz zu tun haben).
|
||||||
|
|
||||||
|
**3. Rule (Die Regel hat es vermutet)**
|
||||||
|
* *Quelle:* `types.yaml` Defaults.
|
||||||
|
* *Vertrauen:* **Niedrig (0.7)**.
|
||||||
|
* *Bedeutung:* Eine Heuristik. "Weil es ein Projekt ist, nehmen wir an, dass es von allen erwähnten Technologien abhängt."
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Matrix-Logik (Kontext-Sensitivität)
|
||||||
|
|
||||||
|
Mit WP11 wurde eine Intelligenz eingeführt, die Kanten-Typen nicht nur anhand des Quell-Typs, sondern auch anhand des Ziel-Typs bestimmt ("Matrix").
|
||||||
|
|
||||||
|
**Logik-Beispiele:**
|
||||||
|
|
||||||
|
* **Quelle `experience` → Ziel `value`**
|
||||||
|
* *Standard:* `references`
|
||||||
|
* *Matrix:* `based_on` (Erfahrungen basieren auf Werten).
|
||||||
|
|
||||||
|
* **Quelle `principle` → Ziel `source` (Buch)**
|
||||||
|
* *Standard:* `references`
|
||||||
|
* *Matrix:* `derived_from` (Prinzipien stammen aus Quellen).
|
||||||
|
|
||||||
|
* **Quelle `project` → Ziel `tool`**
|
||||||
|
* *Standard:* `references`
|
||||||
|
* *Matrix:* `uses` (Projekte nutzen Tools).
|
||||||
|
|
||||||
|
*Nutzen:* Dies erlaubt im Chat präzise Fragen wie: *"Auf welchen Werten basiert diese Entscheidung?"* (Suche nach eingehenden `based_on` Kanten).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Idempotenz & Konsistenz
|
||||||
|
|
||||||
|
Das System garantiert fachliche Konsistenz auch bei mehrfachen Importen.
|
||||||
|
* **Stabile IDs:** Importiert man dieselbe Datei zweimal, ändern sich die IDs der Knoten nicht.
|
||||||
|
* **Keine Duplikate:** Kanten werden dedupliziert. Die "stärkere" Quelle (Explicit > Smart > Rule) gewinnt.
|
||||||
|
* **Lösch-Garantie:** Wenn eine Notiz gelöscht wird, verschwinden auch alle ihre Chunks und ausgehenden Kanten (via `--sync-deletes`).
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
---
|
||||||
|
doc_type: technical_reference
|
||||||
|
audience: developer, architect
|
||||||
|
scope: backend, chat, ollama, traffic_control
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Technische Implementierung des FastAPI-Routers, der Decision Engine und des Traffic Control Systems."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Chat Backend & Traffic Control
|
||||||
|
|
||||||
|
## 1. Hybrid Router (Decision Engine)
|
||||||
|
|
||||||
|
Der zentrale Einstiegspunkt für jede Chatanfrage ist der **Hybrid Router** (`app/routers/chat.py`). Er entscheidet dynamisch, welche Strategie gewählt wird, basierend auf dem User-Input.
|
||||||
|
|
||||||
|
### 1.1 Intent-Erkennung (Logik)
|
||||||
|
|
||||||
|
Der Router prüft den Input in drei Stufen (Wasserfall-Prinzip):
|
||||||
|
|
||||||
|
1. **Question Detection (Regelbasiert):**
|
||||||
|
* Prüfung auf Vorhandensein von `?` oder W-Wörtern (Wer, Wie, Was, Soll ich).
|
||||||
|
* Wenn positiv: **RAG Modus** (Interview wird blockiert).
|
||||||
|
2. **Keyword Scan (Fast Path):**
|
||||||
|
* Lädt `types.yaml` (Objekte, z.B. "Projekt") und `decision_engine.yaml` (Handlungen, z.B. "neu").
|
||||||
|
* Wenn Match (z.B. "Projekt" + "neu"): **INTERVIEW Modus**.
|
||||||
|
3. **LLM Fallback (Slow Path):**
|
||||||
|
* Wenn unklar: Anfrage an LLM zur Klassifizierung.
|
||||||
|
|
||||||
|
### 1.2 RAG Flow (Technisch)
|
||||||
|
|
||||||
|
Wenn der Intent `FACT` oder `DECISION` ist, wird folgender Flow ausgeführt:
|
||||||
|
|
||||||
|
1. **Pre-Processing:** Query Rewriting (optional).
|
||||||
|
2. **Context Enrichment:**
|
||||||
|
* Abruf via `retriever.py` (Hybrid Search).
|
||||||
|
* Injection von Metadaten (`[TYPE]`, `[SCORE]`) in den Prompt.
|
||||||
|
3. **Prompt Construction:** Assembly aus System-Prompt (Persona) + Context + Query.
|
||||||
|
4. **Streaming:** LLM-Antwort wird via **SSE (Server-Sent Events)** an den Client gestreamt.
|
||||||
|
5. **Post-Processing:** Anhängen des `Explanation` Layers (JSON-Breakdown) an das Ende des Streams.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Traffic Control (WP-15)
|
||||||
|
|
||||||
|
Das Traffic Control System (`app/core/llm_service.py`) schützt das System vor Überlastung, wenn rechenintensive Hintergrundprozesse (Smart Edge Import) und Latenz-kritische Chat-Anfragen gleichzeitig laufen.
|
||||||
|
|
||||||
|
### 2.1 Prioritäts-Semaphor
|
||||||
|
|
||||||
|
Jeder LLM-Request muss ein `priority`-Flag setzen.
|
||||||
|
|
||||||
|
**Prioritäten-Levels:**
|
||||||
|
|
||||||
|
| Priority | Verwendung | Limitierung |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| **realtime** | Chat-Anfragen | Keine (Hardware-Limit) |
|
||||||
|
| **background** | Smart Edge Allocation, Drafts | `MINDNET_LLM_BACKGROUND_LIMIT` |
|
||||||
|
|
||||||
|
**Funktionsweise:**
|
||||||
|
* Hintergrund-Tasks nutzen `asyncio.Semaphore`.
|
||||||
|
* Wenn das Limit (Default: 2) erreicht ist, warten weitere Import-Tasks.
|
||||||
|
* Chat-Tasks umgehen die Semaphore und werden sofort bearbeitet.
|
||||||
|
|
||||||
|
### 2.2 Timeout-Konfiguration
|
||||||
|
|
||||||
|
Deadlocks werden durch strikte Timeouts verhindert, die in der `.env` definiert sind.
|
||||||
|
|
||||||
|
* **Chat:** `MINDNET_LLM_TIMEOUT` (Default: 300s).
|
||||||
|
* **Frontend:** `MINDNET_API_TIMEOUT` (Default: 300s).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Feedback Traceability
|
||||||
|
|
||||||
|
Unterstützt das geplante Self-Tuning (WP08).
|
||||||
|
|
||||||
|
1. **Query ID:** Generiert bei jedem `/query` Call eine `UUIDv4`.
|
||||||
|
2. **Logging:** Speichert einen Snapshot in `data/logs/query_snapshot.jsonl` (Input + Retrieved Context).
|
||||||
|
3. **Feedback:** Der `/feedback` Endpoint verknüpft das User-Rating (1-5) mit der `query_id`.
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
---
|
||||||
|
doc_type: technical_reference
|
||||||
|
audience: developer, admin
|
||||||
|
scope: configuration, env
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Referenztabellen für Umgebungsvariablen und YAML-Konfigurationen."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Konfigurations-Referenz
|
||||||
|
|
||||||
|
Dieses Dokument beschreibt die Steuerungsdateien von Mindnet.
|
||||||
|
|
||||||
|
## 1. Environment Variablen (`.env`)
|
||||||
|
|
||||||
|
Diese Variablen steuern die Infrastruktur, Timeouts und Feature-Flags.
|
||||||
|
|
||||||
|
| Variable | Default | Beschreibung |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| `QDRANT_URL` | `http://localhost:6333` | URL zur Vektor-DB API. |
|
||||||
|
| `QDRANT_API_KEY` | *(leer)* | Optionaler Key für Absicherung. |
|
||||||
|
| `COLLECTION_PREFIX` | `mindnet` | Namensraum für Collections (erzeugt `{prefix}_notes` etc). |
|
||||||
|
| `VECTOR_DIM` | `768` | **Muss 768 sein** (für Nomic Embeddings). |
|
||||||
|
| `MINDNET_TYPES_FILE` | `config/types.yaml` | Pfad zur Typ-Registry. |
|
||||||
|
| `MINDNET_RETRIEVER_CONFIG`| `config/retriever.yaml`| Pfad zur Scoring-Konfiguration. |
|
||||||
|
| `MINDNET_DECISION_CONFIG` | `config/decision_engine.yaml` | Pfad zur Router & Intent Config. |
|
||||||
|
| `MINDNET_PROMPTS_PATH` | `config/prompts.yaml` | Pfad zu LLM Prompts. |
|
||||||
|
| `MINDNET_LLM_MODEL` | `phi3:mini` | Name des Chat-Modells (Ollama). |
|
||||||
|
| `MINDNET_EMBEDDING_MODEL` | `nomic-embed-text` | Name des Embedding-Modells (Ollama). |
|
||||||
|
| `MINDNET_OLLAMA_URL` | `http://127.0.0.1:11434`| URL zum LLM-Server. |
|
||||||
|
| `MINDNET_LLM_TIMEOUT` | `300.0` | Timeout in Sekunden (Erhöht für CPU Cold-Starts). |
|
||||||
|
| `MINDNET_API_TIMEOUT` | `300.0` | Frontend Timeout (Erhöht für Smart Edge Wartezeiten). |
|
||||||
|
| `MINDNET_LLM_BACKGROUND_LIMIT`| `2` | **Traffic Control:** Max. parallele Import-Tasks. |
|
||||||
|
| `MINDNET_VAULT_ROOT` | `./vault` | Pfad für Write-Back Operationen (Drafts). |
|
||||||
|
| `MINDNET_HASH_COMPARE` | `Body` | Import-Strategie: `Body`, `Frontmatter` oder `Full`. |
|
||||||
|
| `MINDNET_HASH_SOURCE` | `parsed` | Hash-Quelle: `parsed`, `raw` oder `file`. |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Typ-Registry (`types.yaml`)
|
||||||
|
|
||||||
|
Steuert das Import-Verhalten, Chunking und die Kanten-Logik pro Typ.
|
||||||
|
|
||||||
|
**Referenztabelle (Stand v2.6):**
|
||||||
|
|
||||||
|
| Typ (`type`) | Chunk Profile | Retriever Weight | Smart Edges? | Beschreibung |
|
||||||
|
| :--- | :--- | :--- | :--- | :--- |
|
||||||
|
| **concept** | `sliding_smart_edges` | 0.60 | Ja | Abstrakte Begriffe. |
|
||||||
|
| **project** | `sliding_smart_edges` | 0.97 | Ja | Aktive Vorhaben. |
|
||||||
|
| **decision** | `structured_smart_edges` | 1.00 | Ja | Entscheidungen (ADRs). |
|
||||||
|
| **experience** | `sliding_smart_edges` | 0.90 | Ja | Persönliche Learnings. |
|
||||||
|
| **journal** | `sliding_standard` | 0.80 | Nein | Logs / Dailies. |
|
||||||
|
| **value** | `structured_smart_edges` | 1.00 | Ja | Werte/Prinzipien. |
|
||||||
|
| **risk** | `sliding_short` | 0.90 | Nein | Risiken. |
|
||||||
|
| **person** | `sliding_standard` | 0.50 | Nein | Profile. |
|
||||||
|
| **source** | `sliding_standard` | 0.50 | Nein | Externe Quellen. |
|
||||||
|
| **event** | `sliding_standard` | 0.60 | Nein | Meetings. |
|
||||||
|
| **goal** | `sliding_standard` | 0.95 | Nein | Strategische Ziele. |
|
||||||
|
| **belief** | `sliding_short` | 0.90 | Nein | Glaubenssätze. |
|
||||||
|
| **default** | `sliding_standard` | 1.00 | Nein | Fallback. |
|
||||||
|
|
||||||
|
*Hinweis: `Smart Edges?` entspricht dem YAML-Key `enable_smart_edge_allocation: true`.*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Retriever Config (`retriever.yaml`)
|
||||||
|
|
||||||
|
Steuert die Gewichtung der Scoring-Formel (WP04a).
|
||||||
|
|
||||||
|
**Beispielkonfiguration:**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
scoring:
|
||||||
|
semantic_weight: 1.0 # Basis-Relevanz (Cosine Similarity)
|
||||||
|
edge_weight: 0.7 # Einfluss des Graphen (Bonus)
|
||||||
|
centrality_weight: 0.5 # Einfluss von Hubs
|
||||||
|
|
||||||
|
edge_weights:
|
||||||
|
# Multiplikatoren für den Edge-Bonus
|
||||||
|
depends_on: 1.5 # Harte Abhängigkeiten stark gewichten
|
||||||
|
blocks: 1.5 # Risiken stark gewichten
|
||||||
|
caused_by: 1.2 # Kausalitäten stärken
|
||||||
|
related_to: 0.5 # Weiche Themen schwächer gewichten
|
||||||
|
references: 0.8 # Standard-Referenzen
|
||||||
|
based_on: 1.3 # Werte-Bezug
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Edge Typen Referenz
|
||||||
|
|
||||||
|
Definiert die Semantik der `kind`-Felder in der Edge-Collection.
|
||||||
|
|
||||||
|
| Kind | Symmetrisch? | Herkunft (Primär) | Bedeutung |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `references` | Nein | Wikilink | Standard-Verweis. "Erwähnt X". |
|
||||||
|
| `belongs_to` | Nein | Struktur | Chunk gehört zu Note. |
|
||||||
|
| `next` / `prev` | Ja | Struktur | Lesereihenfolge. |
|
||||||
|
| `depends_on` | Nein | Inline / Default | Harte Abhängigkeit. |
|
||||||
|
| `related_to` | Ja | Callout / Default | Thematische Nähe. |
|
||||||
|
| `similar_to` | Ja | Inline | Inhaltliche Ähnlichkeit. |
|
||||||
|
| `caused_by` | Nein | Inline | Kausalität. |
|
||||||
|
| `solves` | Nein | Inline | Lösung für ein Problem. |
|
||||||
|
| `blocks` | Nein | Inline | Blockade / Risiko. |
|
||||||
|
| `derived_from` | Nein | Matrix | Herkunft (z.B. Prinzip -> Buch). |
|
||||||
|
| `based_on` | Nein | Matrix | Fundament (z.B. Erfahrung -> Wert). |
|
||||||
|
| `uses` | Nein | Matrix | Nutzung (z.B. Projekt -> Tool). |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Decision Engine (`decision_engine.yaml`)
|
||||||
|
|
||||||
|
Steuert den Hybrid Router (WP06). Definiert, welche Keywords welche Strategie auslösen.
|
||||||
|
|
||||||
|
**Beispielauszug:**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# Strategie-Definitionen
|
||||||
|
strategies:
|
||||||
|
DECISION:
|
||||||
|
description: "Hilfe bei Entscheidungen"
|
||||||
|
inject_types: ["value", "principle", "goal", "risk"] # Strategic Retrieval
|
||||||
|
llm_fallback_enabled: true
|
||||||
|
|
||||||
|
INTERVIEW:
|
||||||
|
description: "Wissenserfassung"
|
||||||
|
trigger_keywords: ["erstellen", "neu", "anlegen", "festhalten"]
|
||||||
|
|
||||||
|
EMPATHY:
|
||||||
|
description: "Emotionaler Support"
|
||||||
|
inject_types: ["experience", "belief"]
|
||||||
|
```
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
---
|
||||||
|
doc_type: technical_reference
|
||||||
|
audience: developer, architect
|
||||||
|
scope: database, qdrant, schema
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Exakte Definition der Datenmodelle (Payloads) in Qdrant und Index-Anforderungen."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Technisches Datenmodell (Qdrant Schema)
|
||||||
|
|
||||||
|
## 1. Collections & Namenskonvention
|
||||||
|
|
||||||
|
Mindnet speichert Daten in drei getrennten Qdrant-Collections. Der Prefix ist via ENV `COLLECTION_PREFIX` konfigurierbar (Default: `mindnet`).
|
||||||
|
|
||||||
|
Das System nutzt folgende drei Collections:
|
||||||
|
* `{prefix}_notes`: Metadaten der Dateien.
|
||||||
|
* `{prefix}_chunks`: Vektorisierte Textsegmente.
|
||||||
|
* `{prefix}_edges`: Gerichtete Graph-Kanten.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Note Payload (`mindnet_notes`)
|
||||||
|
|
||||||
|
Repräsentiert die Metadaten einer Markdown-Datei (1:1 Beziehung).
|
||||||
|
|
||||||
|
**JSON-Schema:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"note_id": "string (keyword)", // UUIDv5 (deterministisch) oder Slug
|
||||||
|
"title": "string (text)", // Titel aus Frontmatter
|
||||||
|
"type": "string (keyword)", // Logischer Typ (z.B. 'project', 'concept')
|
||||||
|
"retriever_weight": "float", // Numerische Wichtigkeit (0.0-1.0), aus types.yaml
|
||||||
|
"chunk_profile": "string", // Genutztes Profil (z.B. 'sliding_smart_edges')
|
||||||
|
"edge_defaults": ["string"], // Liste der aktiven Default-Kanten
|
||||||
|
"tags": ["string"], // Liste von Tags aus Frontmatter
|
||||||
|
"created": "string (iso-date)", // Erstellungsdatum
|
||||||
|
"updated": "integer", // Timestamp (File Modification Time)
|
||||||
|
"fulltext": "string (no-index)" // Gesamter Text (nur für Recovery/Export)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Erforderliche Indizes:**
|
||||||
|
Es müssen Payload-Indizes für folgende Felder existieren:
|
||||||
|
* `note_id`
|
||||||
|
* `type`
|
||||||
|
* `tags`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Chunk Payload (`mindnet_chunks`)
|
||||||
|
|
||||||
|
Die atomare Sucheinheit. Enthält den Vektor.
|
||||||
|
|
||||||
|
**Vektor-Konfiguration:**
|
||||||
|
* Modell: `nomic-embed-text`
|
||||||
|
* Dimension: **768**
|
||||||
|
* Metrik: Cosine Similarity
|
||||||
|
|
||||||
|
**JSON-Schema:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"chunk_id": "string (keyword)", // Format: {note_id}#c{index} (z.B. 'abc-123#c01')
|
||||||
|
"note_id": "string (keyword)", // Foreign Key zur Note
|
||||||
|
"type": "string (keyword)", // Kopie aus Note (Denormalisiert für Filterung)
|
||||||
|
"text": "string (text)", // Reintext für Anzeige (ohne Overlap)
|
||||||
|
"window": "string (text)", // Text + Overlap (Basis für Embedding)
|
||||||
|
"ord": "integer", // Laufende Nummer (1..N) für Sortierung
|
||||||
|
"retriever_weight": "float", // Kopie aus Note (für Query-Speed)
|
||||||
|
"chunk_profile": "string", // Vererbt von Note
|
||||||
|
"neighbors_prev": ["string"], // ID des Vorgängers (Linked List)
|
||||||
|
"neighbors_next": ["string"] // ID des Nachfolgers
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Erforderliche Indizes:**
|
||||||
|
Es müssen Payload-Indizes für folgende Felder existieren:
|
||||||
|
* `note_id`
|
||||||
|
* `chunk_id`
|
||||||
|
* `type`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Edge Payload (`mindnet_edges`)
|
||||||
|
|
||||||
|
Gerichtete Kanten zwischen Knoten. Stark erweitert in v2.6 für Provenienz-Tracking.
|
||||||
|
|
||||||
|
**JSON-Schema:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"edge_id": "string (keyword)", // Deterministischer Hash aus (src, dst, kind)
|
||||||
|
"source_id": "string (keyword)", // Chunk-ID (Start)
|
||||||
|
"target_id": "string (keyword)", // Chunk-ID oder Note-Titel (bei Unresolved)
|
||||||
|
"kind": "string (keyword)", // Beziehungsart (z.B. 'depends_on')
|
||||||
|
"scope": "string (keyword)", // Immer 'chunk' (Legacy-Support: 'note')
|
||||||
|
"note_id": "string (keyword)", // Owner Note ID (Ursprung der Kante)
|
||||||
|
|
||||||
|
// Provenance & Quality (WP03/WP15)
|
||||||
|
"provenance": "keyword", // 'explicit', 'rule', 'smart' (NEU)
|
||||||
|
"rule_id": "string (keyword)", // Traceability: 'inline:rel', 'explicit:wikilink', 'smart:llm'
|
||||||
|
"confidence": "float" // Vertrauenswürdigkeit (0.0 - 1.0)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Erforderliche Indizes:**
|
||||||
|
Es müssen Payload-Indizes für folgende Felder existieren:
|
||||||
|
* `source_id`
|
||||||
|
* `target_id`
|
||||||
|
* `kind`
|
||||||
|
* `scope`
|
||||||
|
* `note_id`
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
---
|
||||||
|
doc_type: technical_reference
|
||||||
|
audience: developer, frontend_architect
|
||||||
|
scope: architecture, graph_viz, state_management
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Technische Dokumentation des modularen Streamlit-Frontends, der Graph-Engines und des Editors."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Technical Reference: Frontend & Visualization
|
||||||
|
|
||||||
|
**Kontext:** Mindnet nutzt Streamlit nicht nur als einfaches UI, sondern als komplexe Applikation mit eigenem State-Management, Routing und Persistenz.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Architektur & Modularisierung (WP19)
|
||||||
|
|
||||||
|
Seit Version 2.6 ist das Frontend (`app/frontend/`) kein Monolith mehr, sondern in funktionale Module unterteilt.
|
||||||
|
|
||||||
|
### 1.1 Dateistruktur & Aufgaben
|
||||||
|
|
||||||
|
| Modul | Funktion |
|
||||||
|
| :--- | :--- |
|
||||||
|
| `ui.py` | **Router.** Der Entrypoint. Initialisiert Session-State und entscheidet anhand der Sidebar-Auswahl, welche View gerendert wird. |
|
||||||
|
| `ui_config.py` | **Konstanten.** Zentraler Ort für Farben (`GRAPH_COLORS`), API-Endpunkte und Timeouts. |
|
||||||
|
| `ui_api.py` | **Backend-Bridge.** Kapselt alle `requests`-Aufrufe an die FastAPI. |
|
||||||
|
| `ui_callbacks.py` | **State Transitions.** Logik für View-Wechsel (z.B. Sprung vom Graph in den Editor). |
|
||||||
|
| `ui_utils.py` | **Helper.** Markdown-Parsing (`parse_markdown_draft`) und String-Normalisierung. |
|
||||||
|
| `ui_graph_service.py`| **Data Logic.** Holt Daten aus Qdrant und bereitet Nodes/Edges auf (unabhängig von der Vis-Library). |
|
||||||
|
| `ui_graph_cytoscape.py`| **View: Graph.** Implementierung mit `st-cytoscape` (COSE Layout). |
|
||||||
|
| `ui_editor.py` | **View: Editor.** Logik für Drafts und manuelles Editieren. |
|
||||||
|
|
||||||
|
### 1.2 Konfiguration (`ui_config.py`)
|
||||||
|
|
||||||
|
Zentrale Steuerung der visuellen Semantik.
|
||||||
|
|
||||||
|
# Mapping von Node-Typen zu Farben (Hex)
|
||||||
|
GRAPH_COLORS = {
|
||||||
|
"project": "#ff9f43", # Orange
|
||||||
|
"decision": "#5f27cd", # Lila
|
||||||
|
"experience": "#feca57", # Gelb (Empathie)
|
||||||
|
"concept": "#54a0ff", # Blau
|
||||||
|
"risk": "#ff6b6b" # Rot
|
||||||
|
}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Graph Visualisierung
|
||||||
|
|
||||||
|
Mindnet nutzt primär **Cytoscape** für Stabilität bei großen Graphen.
|
||||||
|
|
||||||
|
### 2.1 Engine: Cytoscape (`st-cytoscape`)
|
||||||
|
* **Algorithmus:** `COSE` (Compound Spring Embedder).
|
||||||
|
* **Vorteil:** Verhindert Überlappungen aktiv (`nodeRepulsion`).
|
||||||
|
|
||||||
|
### 2.2 Architektur-Pattern: "Active Inspector, Passive Graph"
|
||||||
|
Ein häufiges Problem bei Streamlit-Graphen ist das "Flackern" (Re-Render) bei Klicks. Wir lösen das durch Entkopplung:
|
||||||
|
|
||||||
|
1. **Stable Key:** Der React-Key der Komponente hängt *nicht* von der Selektion ab, sondern nur vom Zentrum (`center_id`) und Layout-Settings.
|
||||||
|
2. **CSS-Selektion:** Wir nutzen **nicht** den nativen `:selected` State (buggy bei Single-Select), sondern injizieren eine CSS-Klasse `.inspected`.
|
||||||
|
|
||||||
|
**Stylesheet Implementierung (`ui_graph_cytoscape.py`):**
|
||||||
|
|
||||||
|
stylesheet = [
|
||||||
|
{
|
||||||
|
"selector": "node",
|
||||||
|
"style": { "background-color": "data(bg_color)" }
|
||||||
|
},
|
||||||
|
# Wir steuern das Highlight manuell über eine Klasse
|
||||||
|
{
|
||||||
|
"selector": ".inspected",
|
||||||
|
"style": {
|
||||||
|
"border-width": 6,
|
||||||
|
"border-color": "#FFC300", # Gelb/Gold
|
||||||
|
"z-index": 999
|
||||||
|
}
|
||||||
|
},
|
||||||
|
# Native Selektion wird unterdrückt/unsichtbar gemacht
|
||||||
|
{
|
||||||
|
"selector": "node:selected",
|
||||||
|
"style": { "overlay-opacity": 0, "border-width": 0 }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Editor & Single Source of Truth
|
||||||
|
|
||||||
|
Ein kritisches Design-Pattern ist der Umgang mit Datenkonsistenz beim Editieren ("File System First").
|
||||||
|
|
||||||
|
### 3.1 Das Problem
|
||||||
|
Qdrant speichert Metadaten und Chunks, aber das Feld `fulltext` im Payload kann veraltet sein oder Formatierungen verlieren.
|
||||||
|
|
||||||
|
### 3.2 Die Lösung (Logic Flow)
|
||||||
|
Der `switch_to_editor_callback` in `ui_callbacks.py` implementiert folgende Kaskade:
|
||||||
|
|
||||||
|
def switch_to_editor_callback(note_payload):
|
||||||
|
# 1. Pfad aus Qdrant Payload lesen
|
||||||
|
origin_fname = note_payload.get('path')
|
||||||
|
|
||||||
|
content = ""
|
||||||
|
# 2. Versuch: Hard Read von der Festplatte (Source of Truth)
|
||||||
|
if origin_fname and os.path.exists(origin_fname):
|
||||||
|
with open(origin_fname, "r", encoding="utf-8") as f:
|
||||||
|
content = f.read()
|
||||||
|
else:
|
||||||
|
# 3. Fallback: Rekonstruktion aus der DB ("Stitching")
|
||||||
|
# Nur Notfall, falls Docker-Volume fehlt
|
||||||
|
content = note_payload.get('fulltext', '')
|
||||||
|
|
||||||
|
# State setzen (Transport via Message-Bus)
|
||||||
|
st.session_state.messages.append({
|
||||||
|
"role": "assistant",
|
||||||
|
"intent": "INTERVIEW",
|
||||||
|
"content": content,
|
||||||
|
"origin_filename": origin_fname
|
||||||
|
})
|
||||||
|
st.session_state["sidebar_mode_selection"] = "📝 Manueller Editor"
|
||||||
|
|
||||||
|
Dies garantiert, dass der Editor immer den **echten, aktuellen Stand** der Markdown-Datei anzeigt.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. State Management Patterns
|
||||||
|
|
||||||
|
### 4.1 URL Persistenz (Deep Linking)
|
||||||
|
Layout-Einstellungen werden in der URL gespeichert, damit sie einen Page-Refresh (F5) überleben.
|
||||||
|
|
||||||
|
# ui_graph_cytoscape.py
|
||||||
|
def update_url_params():
|
||||||
|
st.query_params["depth"] = st.session_state.cy_depth
|
||||||
|
st.query_params["rep"] = st.session_state.cy_node_repulsion
|
||||||
|
|
||||||
|
# Init
|
||||||
|
if "cy_depth" not in st.session_state:
|
||||||
|
st.session_state.cy_depth = int(st.query_params.get("depth", 2))
|
||||||
|
|
||||||
|
### 4.2 Resurrection Pattern
|
||||||
|
Verhindert Datenverlust, wenn der Nutzer während des Tippens den Tab wechselt. Der Editor-Inhalt wird bei jedem Keystroke (`on_change`) in `st.session_state` gespiegelt und beim Neuladen der Komponente von dort wiederhergestellt.
|
||||||
|
|
||||||
|
### 4.3 Healing Parser (`ui_utils.py`)
|
||||||
|
Das LLM liefert oft invalides YAML oder Markdown. Der Parser (`parse_markdown_draft`):
|
||||||
|
* Repariert fehlende Frontmatter-Trenner (`---`).
|
||||||
|
* Extrahiert JSON/YAML aus Code-Blöcken.
|
||||||
|
* Normalisiert Tags (entfernt `#`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Constraints & Security (Known Limitations)
|
||||||
|
|
||||||
|
### 5.1 File System Security
|
||||||
|
Der Editor ("File System First") vertraut dem Pfad im Qdrant-Feld `path`.
|
||||||
|
* **Risiko:** Path Traversal (z.B. `../../etc/passwd`).
|
||||||
|
* **Mitigation:** Aktuell findet keine strikte Prüfung statt, ob der Pfad innerhalb des `./vault` Ordners liegt. Das System setzt voraus, dass die Vektor-Datenbank eine **Trusted Source** ist und nur vom internen Importer befüllt wird.
|
||||||
|
* **ToDo:** Bei Öffnung der API für Dritte muss hier eine `Path.resolve().is_relative_to(VAULT_ROOT)` Prüfung implementiert werden.
|
||||||
|
|
||||||
|
### 5.2 Browser Performance
|
||||||
|
Die Graph-Visualisierung (`st-cytoscape`) rendert Client-seitig im Browser.
|
||||||
|
* **Limit:** Ab ca. **500 Knoten/Kanten** kann das Rendering träge werden.
|
||||||
|
* **Design-Entscheidung:** Das UI ist auf **Ego-Graphen** (Nachbarn eines Knotens) und gefilterte Ansichten ausgelegt, nicht auf die Darstellung des gesamten Knowledge-Graphs ("Whole Brain Visualization").
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
---
|
||||||
|
doc_type: technical_reference
|
||||||
|
audience: developer, devops
|
||||||
|
scope: backend, ingestion, smart_edges
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Detaillierte technische Beschreibung der Import-Pipeline, Quality Gates und CLI-Befehle."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Ingestion Pipeline & Smart Processing
|
||||||
|
|
||||||
|
**Quellen:** `pipeline_playbook.md`, `Handbuch.md`
|
||||||
|
|
||||||
|
Die Ingestion transformiert Markdown in den Graphen. Entrypoint: `scripts/import_markdown.py`.
|
||||||
|
|
||||||
|
## 1. Der Import-Prozess (13-Schritte-Workflow)
|
||||||
|
|
||||||
|
Der Prozess ist **asynchron** und **idempotent**.
|
||||||
|
|
||||||
|
1. **Markdown lesen:** Rekursives Scannen des Vaults.
|
||||||
|
2. **Frontmatter extrahieren:** Validierung von Pflichtfeldern (`id`, `type`, `title`).
|
||||||
|
3. **Typauflösung:** Bestimmung des `type` via `types.yaml`.
|
||||||
|
4. **Note-Payload generieren:** Erstellen des JSON-Objekts für `mindnet_notes`.
|
||||||
|
5. **Chunking anwenden:** Zerlegung des Textes basierend auf dem `chunk_profile` (siehe unten).
|
||||||
|
6. **Smart Edge Allocation (WP15):**
|
||||||
|
* Wenn `enable_smart_edge_allocation: true`: Der `SemanticAnalyzer` sendet Chunks an das LLM.
|
||||||
|
* **Traffic Control:** Request nutzt `priority="background"`. Semaphore (Limit: 2) drosselt die Last.
|
||||||
|
* **Resilienz:** Bei Timeout (Ollama) greift ein Fallback (Broadcasting an alle Chunks).
|
||||||
|
7. **Inline-Kanten finden:** Parsing von `[[rel:...]]`.
|
||||||
|
8. **Callout-Kanten finden:** Parsing von `> [!edge]`.
|
||||||
|
9. **Default-Edges erzeugen:** Anwendung der `edge_defaults` aus Registry.
|
||||||
|
10. **Strukturkanten erzeugen:** `belongs_to`, `next`, `prev`.
|
||||||
|
11. **Embedding (Async):** Generierung via `nomic-embed-text` (768d).
|
||||||
|
12. **Strict Mode:** Abbruch bei leeren Embeddings oder Dimension 0.
|
||||||
|
13. **Diagnose:** Integritäts-Check nach dem Lauf.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Betrieb & CLI Befehle
|
||||||
|
|
||||||
|
### 2.1 Standard-Betrieb (Inkrementell)
|
||||||
|
Für regelmäßige Updates (Cronjob). Erkennt Änderungen via Hash.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export QDRANT_URL="http://localhost:6333"
|
||||||
|
export COLLECTION_PREFIX="mindnet"
|
||||||
|
|
||||||
|
# Nutzt das Venv der Produktionsumgebung
|
||||||
|
/home/llmadmin/mindnet/.venv/bin/python3 -m scripts.import_markdown \
|
||||||
|
--vault ./vault \
|
||||||
|
--prefix "$COLLECTION_PREFIX" \
|
||||||
|
--apply \
|
||||||
|
--purge-before-upsert \
|
||||||
|
--sync-deletes
|
||||||
|
```
|
||||||
|
|
||||||
|
> **[!WARNING] Purge-Before-Upsert**
|
||||||
|
> Das Flag `--purge-before-upsert` ist kritisch. Es löscht vor dem Schreiben einer Note ihre alten Chunks/Edges. Ohne dieses Flag entstehen **"Geister-Chunks"** (alte Textabschnitte, die im Markdown gelöscht wurden, aber im Index verbleiben).
|
||||||
|
|
||||||
|
### 2.2 Full Rebuild (Clean Slate)
|
||||||
|
Notwendig bei Änderungen an `types.yaml` oder Modell-Wechsel.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 0. Modell sicherstellen
|
||||||
|
ollama pull nomic-embed-text
|
||||||
|
|
||||||
|
# 1. Qdrant Collections löschen (Wipe)
|
||||||
|
python3 -m scripts.reset_qdrant --mode wipe --prefix "mindnet" --yes
|
||||||
|
|
||||||
|
# 2. Vollständiger Import (Force)
|
||||||
|
python3 -m scripts.import_markdown --vault ./vault --prefix "mindnet" --apply --force
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Chunking & Payload
|
||||||
|
|
||||||
|
Das Chunking ist profilbasiert.
|
||||||
|
|
||||||
|
| Profil | Max Token | Overlap | Einsatz |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `sliding_short` | 128 | 20 | Logs, Chats. |
|
||||||
|
| `sliding_standard` | 512 | 50 | Massendaten. |
|
||||||
|
| `sliding_smart_edges`| 512 | 50 | Wichtige Inhalte (Experience, Project). |
|
||||||
|
| `structured_smart` | n/a | n/a | Trennt strikt an Headings (für ADRs). |
|
||||||
|
|
||||||
|
**Payload-Felder:**
|
||||||
|
* `text`: Der reine Inhalt (Anzeige).
|
||||||
|
* `window`: Inhalt plus Overlap (für Embedding).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Edge-Erzeugung & Prioritäten
|
||||||
|
|
||||||
|
Kanten werden nach Vertrauenswürdigkeit (`provenance`) priorisiert. Die höhere Prio gewinnt.
|
||||||
|
|
||||||
|
| Prio | Quelle | Rule ID | Confidence |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| **1** | Inline | `inline:rel` | 0.95 |
|
||||||
|
| **2** | Callout | `callout:edge` | 0.90 |
|
||||||
|
| **3** | Wikilink | `explicit:wikilink` | 1.00 |
|
||||||
|
| **4** | Smart Edge | `smart:llm_filter` | 0.90 |
|
||||||
|
| **5** | Type Default | `edge_defaults` | 0.70 |
|
||||||
|
| **6** | Struktur | `structure` | 1.00 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Quality Gates & Tests
|
||||||
|
|
||||||
|
Diese Tests garantieren die Stabilität der Pipeline.
|
||||||
|
|
||||||
|
**1. Payload Dryrun (Schema-Check):**
|
||||||
|
Simuliert Import, prüft JSON-Schema Konformität.
|
||||||
|
```bash
|
||||||
|
python3 -m scripts.payload_dryrun --vault ./test_vault
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. Full Edge Check (Graph-Integrität):**
|
||||||
|
Prüft Invarianten (z.B. `next` muss reziprok zu `prev` sein).
|
||||||
|
```bash
|
||||||
|
python3 -m scripts.edges_full_check
|
||||||
|
```
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
---
|
||||||
|
doc_type: technical_reference
|
||||||
|
audience: developer, data_scientist
|
||||||
|
scope: backend, retrieval, scoring
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Formeln und Algorithmen des Hybrid Retrievers und Explanation Layer."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Retrieval & Scoring Algorithmen
|
||||||
|
|
||||||
|
Der Retriever (`app/core/retriever.py`) unterstützt **Semantic Search** und **Hybrid Search**. Seit v2.4 (WP04a) nutzt Mindnet ein gewichtetes Scoring-Modell, das Semantik, Graphentheorie und Metadaten kombiniert.
|
||||||
|
|
||||||
|
## 1. Scoring Formel (WP04a)
|
||||||
|
|
||||||
|
Der Gesamtscore eines Treffers berechnet sich als gewichtete Summe. Alle Gewichte ($W$) sind in `retriever.yaml` konfigurierbar.
|
||||||
|
|
||||||
|
$$
|
||||||
|
TotalScore = (W_{sem} \cdot S_{sem} \cdot \max(W_{type}, 0)) + (W_{edge} \cdot B_{edge}) + (W_{cent} \cdot B_{cent})
|
||||||
|
$$
|
||||||
|
|
||||||
|
### Die Komponenten
|
||||||
|
|
||||||
|
**1. Semantic Score ($S_{sem}$):**
|
||||||
|
* **Basis:** Cosine Similarity des Vektors.
|
||||||
|
* **Modell:** `nomic-embed-text` (768d).
|
||||||
|
* **Wertebereich:** 0.0 bis 1.0.
|
||||||
|
|
||||||
|
**2. Type Weight ($W_{type}$):**
|
||||||
|
* **Herkunft:** Feld `retriever_weight` aus der Note/Chunk Payload.
|
||||||
|
* **Zweck:** Priorisierung bestimmter Dokumententypen unabhängig vom Inhalt.
|
||||||
|
* **Beispiel:** Eine `decision` (Gewicht 1.0) schlägt ein `concept` (Gewicht 0.6) bei gleicher textueller Ähnlichkeit.
|
||||||
|
|
||||||
|
**3. Edge Bonus ($B_{edge}$):**
|
||||||
|
* **Kontext:** Berechnet im lokalen Subgraphen (Expansion Tiefe 1).
|
||||||
|
* **Logik:** Summe der `confidence` aller eingehenden Kanten, die von Knoten stammen, die *ebenfalls* im aktuellen Result-Set (oder dem übergebenen Kontext) enthalten sind.
|
||||||
|
* **Zweck:** Belohnt Chunks, die "im Thema" vernetzt sind.
|
||||||
|
|
||||||
|
**4. Centrality Bonus ($B_{cent}$):**
|
||||||
|
* **Kontext:** Berechnet im lokalen Subgraphen.
|
||||||
|
* **Logik:** Eine vereinfachte PageRank-Metrik (Degree Centrality) im temporären Graphen.
|
||||||
|
* **Zweck:** Belohnt "Hubs", die viele Verbindungen zu anderen Treffern haben.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Hybrid Retrieval Flow
|
||||||
|
|
||||||
|
Der Hybrid-Modus ist der Standard für den Chat (`/chat`). Er läuft in drei Phasen ab:
|
||||||
|
|
||||||
|
**Phase 1: Vector Search (Seed Generation)**
|
||||||
|
* Suche die Top-K (z.B. 20) Kandidaten via Embeddings in Qdrant.
|
||||||
|
* Dies sind die "Seeds" für den Graphen.
|
||||||
|
|
||||||
|
**Phase 2: Graph Expansion**
|
||||||
|
* Nutze `graph_adapter.expand(seeds, depth=1)`.
|
||||||
|
* Lade alle direkten Nachbarn (Incoming & Outgoing) der Seeds aus der `_edges` Collection.
|
||||||
|
* Konstruiere einen temporären `NetworkX`-Graphen im Speicher (`Subgraph`).
|
||||||
|
|
||||||
|
**Phase 3: Re-Ranking**
|
||||||
|
* Berechne für jeden Knoten im Subgraphen die Boni ($B_{edge}$, $B_{cent}$).
|
||||||
|
* Wende die Scoring-Formel an.
|
||||||
|
* Sortiere die Liste neu absteigend nach `TotalScore`.
|
||||||
|
* Schneide die Liste beim finalen Limit (z.B. 5) ab.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Explanation Layer (WP04b)
|
||||||
|
|
||||||
|
Wenn der Parameter `explain=True` an die API übergeben wird, generiert der Retriever ein `Explanation` Objekt für jeden Treffer.
|
||||||
|
|
||||||
|
**JSON-Struktur der Erklärung:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"score_breakdown": {
|
||||||
|
"semantic": 0.85,
|
||||||
|
"type_boost": 1.0,
|
||||||
|
"edge_bonus": 0.4,
|
||||||
|
"centrality": 0.1
|
||||||
|
},
|
||||||
|
"reasons": [
|
||||||
|
"Hohe textuelle Übereinstimmung (>0.85).",
|
||||||
|
"Bevorzugt, da Typ 'decision' (Gewicht 1.0).",
|
||||||
|
"Wird referenziert von 'Projekt Alpha' via 'depends_on'."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Logik der Text-Generierung:**
|
||||||
|
* **Semantik:** Wenn $S_{sem} > 0.8$: "Hohe Übereinstimmung".
|
||||||
|
* **Typ:** Wenn $W_{type} > 0.8$: "Bevorzugt, da Typ X".
|
||||||
|
* **Graph:** Listet bis zu 3 eingehende Kanten mit hoher Konfidenz auf ("Wird referenziert von...").
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Konfiguration (`retriever.yaml`)
|
||||||
|
|
||||||
|
Diese Datei steuert die Balance der Formel.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
scoring:
|
||||||
|
semantic_weight: 1.0 # Basis-Relevanz (sollte immer ca. 1.0 sein)
|
||||||
|
edge_weight: 0.7 # Einfluss des Graphen (0.5 - 1.0 empfohlen)
|
||||||
|
centrality_weight: 0.5 # Einfluss der Zentralität (Hub-Bonus)
|
||||||
|
|
||||||
|
# Kanten-spezifische Gewichtung für den Edge-Bonus
|
||||||
|
edge_weights:
|
||||||
|
depends_on: 1.5 # Harte Abhängigkeiten sehr stark gewichten
|
||||||
|
blocks: 1.5 # Risiken/Blocker stark gewichten
|
||||||
|
caused_by: 1.2 # Kausalitäten moderat stärken
|
||||||
|
related_to: 0.5 # Weiche Themen schwächer gewichten
|
||||||
|
references: 0.8 # Standard-Referenzen
|
||||||
|
```
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
---
|
||||||
|
doc_type: operations_manual
|
||||||
|
audience: admin, devops
|
||||||
|
scope: deployment, maintenance, backup
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Installationsanleitung, Systemd-Units und Wartungsprozesse."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Admin Operations Guide
|
||||||
|
|
||||||
|
## 1. Installation & Setup
|
||||||
|
|
||||||
|
### 1.1 Voraussetzungen
|
||||||
|
* **OS:** Ubuntu 22.04+ (empfohlen).
|
||||||
|
* **Tools:** Python 3.10+, Docker, Ollama.
|
||||||
|
* **Hardware:** Min. 8GB RAM, 4 CPU Cores (für Async Import).
|
||||||
|
|
||||||
|
### 1.2 Qdrant (Docker)
|
||||||
|
Startet die Vektor-DB mit persistentem Storage auf Port 6333.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
--name mindnet_qdrant \
|
||||||
|
--restart always \
|
||||||
|
-p 6333:6333 \
|
||||||
|
-v $(pwd)/qdrant_storage:/qdrant/storage \
|
||||||
|
qdrant/qdrant
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1.3 Ollama (Modelle)
|
||||||
|
**Wichtig:** Seit v2.4 ist `nomic-embed-text` Pflicht für Embeddings.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Modelle laden
|
||||||
|
ollama pull phi3:mini
|
||||||
|
ollama pull nomic-embed-text
|
||||||
|
|
||||||
|
# Testen
|
||||||
|
curl http://localhost:11434/api/generate -d '{"model": "phi3:mini", "prompt":"Hi"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Deployment (Systemd Services)
|
||||||
|
|
||||||
|
Wir unterscheiden strikt zwischen **Prod** (Port 8001/8501) und **Dev** (Port 8002/8502).
|
||||||
|
|
||||||
|
### 2.1 Backend Service (`/etc/systemd/system/mindnet-prod.service`)
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[Unit]
|
||||||
|
Description=Mindnet API Prod (8001)
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=llmadmin
|
||||||
|
Group=llmadmin
|
||||||
|
WorkingDirectory=/home/llmadmin/mindnet
|
||||||
|
# Startet Uvicorn (Async Server)
|
||||||
|
ExecStart=/home/llmadmin/mindnet/.venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8001 --env-file .env
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.2 UI Service (`/etc/systemd/system/mindnet-ui-prod.service`)
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[Unit]
|
||||||
|
Description=Mindnet UI Prod (8501)
|
||||||
|
After=mindnet-prod.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=llmadmin
|
||||||
|
Group=llmadmin
|
||||||
|
WorkingDirectory=/home/llmadmin/mindnet
|
||||||
|
|
||||||
|
# Environment für Streamlit Port & API-Ziel
|
||||||
|
Environment="MINDNET_API_URL=http://localhost:8001"
|
||||||
|
Environment="MINDNET_API_TIMEOUT=300"
|
||||||
|
Environment="STREAMLIT_SERVER_PORT=8501"
|
||||||
|
Environment="STREAMLIT_SERVER_ADDRESS=0.0.0.0"
|
||||||
|
Environment="STREAMLIT_SERVER_HEADLESS=true"
|
||||||
|
|
||||||
|
# WICHTIG: Pfad zur neuen Router-Datei (ui.py)
|
||||||
|
ExecStart=/home/llmadmin/mindnet/.venv/bin/streamlit run app/frontend/ui.py
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Wartung & Cronjobs
|
||||||
|
|
||||||
|
### 3.1 Regelmäßiger Import (Cron)
|
||||||
|
Führt den Sync stündlich durch. Nutzt `--purge-before-upsert` für Sauberkeit.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Crontab Eintrag (user: llmadmin)
|
||||||
|
0 * * * * cd /home/llmadmin/mindnet && .venv/bin/python3 -m scripts.import_markdown --vault ./vault --prefix "mindnet" --apply --purge-before-upsert --sync-deletes >> ./logs/import.log 2>&1
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.2 Troubleshooting Guide
|
||||||
|
|
||||||
|
**Fehler: "ModuleNotFoundError: No module named 'st_cytoscape'"**
|
||||||
|
* Ursache: Alte Dependencies oder falsches Paket installiert.
|
||||||
|
* Lösung: Environment aktualisieren.
|
||||||
|
```bash
|
||||||
|
source .venv/bin/activate
|
||||||
|
pip uninstall streamlit-cytoscapejs
|
||||||
|
pip install st-cytoscape
|
||||||
|
# Oder sicherheitshalber:
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
**Fehler: "Vector dimension error: expected 768, got 384"**
|
||||||
|
* Ursache: Alte DB (v2.2), neues Modell (v2.4).
|
||||||
|
* Lösung: **Full Reset** (siehe Kap. 4.2).
|
||||||
|
|
||||||
|
**Fehler: Import sehr langsam**
|
||||||
|
* Ursache: Smart Edges sind aktiv und analysieren jeden Chunk.
|
||||||
|
* Lösung: `MINDNET_LLM_BACKGROUND_LIMIT` prüfen oder Feature in `types.yaml` deaktivieren.
|
||||||
|
|
||||||
|
**Fehler: UI "Read timed out"**
|
||||||
|
* Ursache: Backend braucht für Smart Edges länger als 60s.
|
||||||
|
* Lösung: `MINDNET_API_TIMEOUT=300.0` in `.env` setzen (oder im Systemd Service).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Backup & Restore
|
||||||
|
|
||||||
|
### 4.1 Qdrant Snapshot
|
||||||
|
Sichert den Vektor-Index.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker stop mindnet_qdrant
|
||||||
|
tar -czf qdrant_backup_$(date +%F).tar.gz ./qdrant_storage
|
||||||
|
docker start mindnet_qdrant
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 Notfall-Rebuild (Clean Slate)
|
||||||
|
Wenn alles inkonsistent ist oder Dimensionen sich ändern:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. DB löschen
|
||||||
|
python3 -m scripts.reset_qdrant --mode wipe --prefix "mindnet" --yes
|
||||||
|
|
||||||
|
# 2. Neu importieren (Force Hash recalculation)
|
||||||
|
python3 -m scripts.import_markdown --vault ./vault --prefix "mindnet" --apply --force
|
||||||
|
```
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
---
|
||||||
|
doc_type: developer_guide
|
||||||
|
audience: developer
|
||||||
|
scope: workflow, testing, architecture, modules
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Umfassender Guide für Entwickler: Architektur, Modul-Interna, Setup, Git-Workflow und Erweiterungs-Anleitungen."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Mindnet Developer Guide & Workflow
|
||||||
|
|
||||||
|
**Quellen:** `developer_guide.md`, `dev_workflow.md`
|
||||||
|
|
||||||
|
Dieser Guide vereint das technische Verständnis der Module mit dem operativen Workflow zwischen Windows (Dev) und Linux (Runtime).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Die physische Architektur
|
||||||
|
|
||||||
|
Mindnet läuft in einer verteilten Umgebung (Post-WP15 Setup).
|
||||||
|
|
||||||
|
* **Windows 11 (VS Code):** Hier schreibst du Code. **Nie** direkt auf `main` arbeiten!
|
||||||
|
* **Raspberry Pi (Gitea):** Der "Safe". Speichert den Code und verwaltet Versionen.
|
||||||
|
* **Beelink (Runtime):** Der Server. Hier läuft die Software. Wir nutzen **Systemd-Services**:
|
||||||
|
* **PROD:** API (8001) + UI (8501). Ordner: `~/mindnet`.
|
||||||
|
* **DEV:** API (8002) + UI (8502). Ordner: `~/mindnet_dev`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Projektstruktur & Core-Module
|
||||||
|
|
||||||
|
Der Code ist modular in `app` (Logik), `scripts` (CLI) und `config` (Steuerung) getrennt.
|
||||||
|
|
||||||
|
### 2.1 Verzeichnisbaum
|
||||||
|
|
||||||
|
```text
|
||||||
|
mindnet/
|
||||||
|
├── app/
|
||||||
|
│ ├── core/ # Kernlogik
|
||||||
|
│ │ ├── ingestion.py # Async Ingestion Service mit Change Detection
|
||||||
|
│ │ ├── chunker.py # Smart Chunker Orchestrator
|
||||||
|
│ │ ├── derive_edges.py # Edge-Erzeugung (WP03 Logik)
|
||||||
|
│ │ ├── retriever.py # Scoring & Hybrid Search
|
||||||
|
│ │ └── qdrant.py # DB-Verbindung
|
||||||
|
│ ├── routers/ # FastAPI Endpoints
|
||||||
|
│ │ ├── query.py # Suche
|
||||||
|
│ │ ├── chat.py # Hybrid Router v5 & Interview Logic
|
||||||
|
│ │ └── feedback.py # Feedback (WP04c)
|
||||||
|
│ ├── services/ # Interne & Externe Dienste
|
||||||
|
│ │ ├── llm_service.py # Ollama Client mit Traffic Control
|
||||||
|
│ │ ├── semantic_analyzer.py# LLM-Filter für Edges (WP15)
|
||||||
|
│ │ ├── embeddings_client.py# Async Embeddings (HTTPX)
|
||||||
|
│ │ └── discovery.py # Intelligence Logic (WP11)
|
||||||
|
│ ├── frontend/ # UI Logic (WP19 Modularisierung)
|
||||||
|
│ │ ├── ui.py # Main Entrypoint & Routing
|
||||||
|
│ │ ├── ui_config.py # Styles & Constants
|
||||||
|
│ │ ├── ui_api.py # Backend Connector
|
||||||
|
│ │ ├── ui_callbacks.py # State Transitions
|
||||||
|
│ │ ├── ui_utils.py # Helper & Parsing
|
||||||
|
│ │ ├── ui_graph_service.py # Graph Data Logic
|
||||||
|
│ │ ├── ui_graph_cytoscape.py # Modern Graph View (St-Cytoscape)
|
||||||
|
│ │ └── ui_editor.py # Editor View
|
||||||
|
│ └── main.py # Entrypoint der API
|
||||||
|
├── config/ # YAML-Konfigurationen (Single Source of Truth)
|
||||||
|
├── scripts/ # CLI-Tools (Import, Diagnose, Reset)
|
||||||
|
├── tests/ # Pytest Suite & Smoke Scripts
|
||||||
|
└── vault/ # Dein lokaler Markdown-Content
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.2 Modul-Details (Wie es funktioniert)
|
||||||
|
|
||||||
|
**Das Frontend (`app.frontend`) - *Neu in v2.6***
|
||||||
|
* **Router (`ui.py`):** Entscheidet, welche View geladen wird.
|
||||||
|
* **Service-Layer (`ui_graph_service.py`):** Kapselt die Qdrant-Abfragen. Liefert rohe Nodes/Edges, die dann von den Views visualisiert werden.
|
||||||
|
* **Graph Engine:** Wir nutzen `st-cytoscape` für das Layout. Die Logik zur Vermeidung von Re-Renders (Stable Keys, CSS-Selektion) ist essentiell.
|
||||||
|
* **Data Consistency:** Der Editor (`ui_editor.py`) liest Dateien bevorzugt direkt vom Dateisystem ("File System First"), um Datenverlust durch veraltete DB-Einträge zu vermeiden.
|
||||||
|
|
||||||
|
**Der Importer (`scripts.import_markdown`)**
|
||||||
|
* Das komplexeste Modul.
|
||||||
|
* Nutzt `app.core.chunker` und `app.services.semantic_analyzer` (Smart Edges).
|
||||||
|
* **Idempotenz:** Nutzt deterministische UUIDv5 IDs. Kann beliebig oft laufen.
|
||||||
|
* **Robustheit:** Implementiert Change Detection (Hash) und Retry-Logik.
|
||||||
|
|
||||||
|
**Der Hybrid Router (`app.routers.chat`)**
|
||||||
|
* Hier liegt die Logik für Intent Detection (WP06).
|
||||||
|
* **Question Detection:** Prüft auf `?` und W-Wörter.
|
||||||
|
* **Priority:** Ruft `llm_service` mit `priority="realtime"` auf (umgeht Import-Warteschlange).
|
||||||
|
|
||||||
|
**Der Retriever (`app.core.retriever`)**
|
||||||
|
* Implementiert die Scoring-Formel (`Semantik + Graph + Typ`).
|
||||||
|
* **Hybrid Search:** Lädt dynamisch den Subgraphen (`graph_adapter.expand`).
|
||||||
|
|
||||||
|
**Traffic Control (`app.services.llm_service`)**
|
||||||
|
* Stellt sicher, dass der Chat responsive bleibt, auch wenn ein Import läuft.
|
||||||
|
* Nutzt `asyncio.Semaphore` (`MINDNET_LLM_BACKGROUND_LIMIT`), um Hintergrund-Jobs zu drosseln.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Lokales Setup (Development)
|
||||||
|
|
||||||
|
**Voraussetzungen:** Python 3.10+, Docker, Ollama.
|
||||||
|
|
||||||
|
**Installation:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Repo & Venv
|
||||||
|
git clone <repo> mindnet
|
||||||
|
cd mindnet
|
||||||
|
python3 -m venv .venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
|
||||||
|
# 2. Dependencies (inkl. st-cytoscape)
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
# 3. Ollama (Nomic ist Pflicht!)
|
||||||
|
ollama pull phi3:mini
|
||||||
|
ollama pull nomic-embed-text
|
||||||
|
```
|
||||||
|
|
||||||
|
**Konfiguration (.env):**
|
||||||
|
|
||||||
|
```ini
|
||||||
|
QDRANT_URL="http://localhost:6333"
|
||||||
|
COLLECTION_PREFIX="mindnet_dev"
|
||||||
|
VECTOR_DIM=768
|
||||||
|
MINDNET_LLM_BACKGROUND_LIMIT=2
|
||||||
|
MINDNET_API_URL="http://localhost:8002"
|
||||||
|
MINDNET_LLM_TIMEOUT=300.0
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Der Entwicklungs-Zyklus
|
||||||
|
|
||||||
|
### Phase 1: Windows (Code)
|
||||||
|
1. **Basis holen:** `git checkout main && git pull`.
|
||||||
|
2. **Branch:** `git checkout -b feature/mein-feature`.
|
||||||
|
3. **Code & Push:** `git push origin feature/mein-feature`.
|
||||||
|
|
||||||
|
### Phase 2: Beelink (Test)
|
||||||
|
1. **SSH:** `ssh user@beelink`.
|
||||||
|
2. **Ordner:** `cd ~/mindnet_dev`.
|
||||||
|
3. **Checkout:** `git fetch && git checkout feature/mein-feature && git pull`.
|
||||||
|
4. **Dependencies:** `pip install -r requirements.txt`.
|
||||||
|
5. **Restart:** `sudo systemctl restart mindnet-dev`.
|
||||||
|
6. **Validierung (Smoke Tests):**
|
||||||
|
* **Last-Test:** Starte `python3 -m scripts.import_markdown ...` und chatte gleichzeitig im UI (Port 8502).
|
||||||
|
* **API Check:** `curl -X POST "http://localhost:8002/ingest/analyze" ...`
|
||||||
|
|
||||||
|
### Phase 3: Release & Deploy
|
||||||
|
1. **Gitea:** Pull Request erstellen und mergen.
|
||||||
|
2. **Beelink (Prod):**
|
||||||
|
```bash
|
||||||
|
cd ~/mindnet
|
||||||
|
git pull origin main
|
||||||
|
sudo systemctl restart mindnet-prod
|
||||||
|
```
|
||||||
|
3. **Cleanup:** Branch löschen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Erweiterungs-Guide: "Teach-the-AI"
|
||||||
|
|
||||||
|
Mindnet lernt durch Konfiguration, nicht durch Training.
|
||||||
|
|
||||||
|
### Workflow A: Neuen Typ implementieren (z. B. `type: risk`)
|
||||||
|
1. **Physik (`types.yaml`):**
|
||||||
|
```yaml
|
||||||
|
risk:
|
||||||
|
retriever_weight: 0.90
|
||||||
|
edge_defaults: ["blocks"]
|
||||||
|
detection_keywords: ["gefahr", "risiko"]
|
||||||
|
```
|
||||||
|
2. **Strategie (`decision_engine.yaml`):**
|
||||||
|
```yaml
|
||||||
|
DECISION:
|
||||||
|
inject_types: ["value", "risk"] # Füge 'risk' hinzu
|
||||||
|
```
|
||||||
|
3. **Visualisierung (`ui_config.py`):**
|
||||||
|
Füge dem `GRAPH_COLORS` Dictionary einen Eintrag hinzu:
|
||||||
|
```python
|
||||||
|
"risk": "#ff6b6b"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Workflow B: Interview-Schema anpassen (WP07)
|
||||||
|
Wenn Mindnet neue Fragen stellen soll (z.B. "Budget" bei Projekten):
|
||||||
|
1. **Schema (`types.yaml`):**
|
||||||
|
```yaml
|
||||||
|
project:
|
||||||
|
schema:
|
||||||
|
- "Titel"
|
||||||
|
- "Ziel"
|
||||||
|
- "Budget (Neu)"
|
||||||
|
```
|
||||||
|
2. **Kein Code nötig:** Der `One-Shot Extractor` liest dies dynamisch.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Tests & Debugging
|
||||||
|
|
||||||
|
**Unit Tests:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pytest tests/test_retriever_basic.py
|
||||||
|
pytest tests/test_chunking.py
|
||||||
|
```
|
||||||
|
|
||||||
|
**Pipeline Tests:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# JSON-Schema prüfen
|
||||||
|
python3 -m scripts.payload_dryrun --vault ./test_vault
|
||||||
|
|
||||||
|
# Graph-Integrität prüfen
|
||||||
|
python3 -m scripts.edges_full_check
|
||||||
|
```
|
||||||
|
|
||||||
|
**E2E Smoke Tests:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Decision Engine
|
||||||
|
python tests/test_wp06_decision.py -p 8002 -e DECISION -q "Soll ich X tun?"
|
||||||
|
|
||||||
|
# Feedback
|
||||||
|
python tests/test_feedback_smoke.py --url http://localhost:8002/query
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Troubleshooting & One-Liners
|
||||||
|
|
||||||
|
**DB komplett zurücksetzen (Vorsicht!):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m scripts.reset_qdrant --mode wipe --prefix "mindnet_dev" --yes
|
||||||
|
```
|
||||||
|
|
||||||
|
**Einen einzelnen File inspizieren (Parser-Sicht):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 tests/inspect_one_note.py --file ./vault/MeinFile.md
|
||||||
|
```
|
||||||
|
|
||||||
|
**Live-Logs sehen:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
journalctl -u mindnet-dev -f
|
||||||
|
journalctl -u mindnet-ui-dev -f
|
||||||
|
```
|
||||||
|
|
||||||
|
**"Read timed out" im Frontend:**
|
||||||
|
* Ursache: Backend braucht für Smart Edges länger als 60s.
|
||||||
|
* Lösung: `MINDNET_API_TIMEOUT=300.0` in `.env` setzen.
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
---
|
||||||
|
doc_type: roadmap
|
||||||
|
audience: product_owner, developer
|
||||||
|
status: active
|
||||||
|
version: 2.6
|
||||||
|
context: "Aktuelle Planung für kommende Features (ab WP16), Release-Strategie und Historie der abgeschlossenen WPs."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Mindnet Active Roadmap
|
||||||
|
|
||||||
|
**Aktueller Stand:** v2.6.0 (Post-WP19)
|
||||||
|
**Fokus:** Visualisierung, Exploration & Deep Search.
|
||||||
|
|
||||||
|
## 1. Programmstatus
|
||||||
|
|
||||||
|
Wir haben mit der Implementierung des Graph Explorers (WP19) einen Meilenstein in **Phase E (Maintenance & Scaling)** erreicht. Die Architektur ist nun modular. Der nächste Schritt (WP19a) vertieft die Analyse-Fähigkeiten.
|
||||||
|
|
||||||
|
| Phase | Fokus | Status |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| **Phase A** | Fundament & Import | ✅ Fertig |
|
||||||
|
| **Phase B** | Semantik & Graph | ✅ Fertig |
|
||||||
|
| **Phase C** | Persönlichkeit | ✅ Fertig |
|
||||||
|
| **Phase D** | Interaktion & Tools | ✅ Fertig |
|
||||||
|
| **Phase E** | Maintenance & Visualisierung | 🚀 Aktiv |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Historie: Abgeschlossene Workpackages
|
||||||
|
|
||||||
|
Eine Übersicht der implementierten Features zum schnellen Auffinden von Funktionen. Details siehe `99_legacy_workpackages.md`.
|
||||||
|
|
||||||
|
| WP | Titel | Ergebnis / Kern-Feature |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| **WP-01** | Knowledge Design | Definition von `types.yaml` und Note-Typen (Project, Concept, etc.). |
|
||||||
|
| **WP-02** | Chunking Strategy | Implementierung von Sliding-Window und Hash-basierter Änderungserkennung. |
|
||||||
|
| **WP-03** | Import-Pipeline | Asynchroner Importer, der Markdown in Qdrant (Notes/Edges) schreibt. |
|
||||||
|
| **WP-04a**| Retriever Scoring | Hybride Suche: `Score = Semantik + GraphBonus + TypGewicht`. |
|
||||||
|
| **WP-04b**| Explanation Layer | Transparenz: API liefert "Reasons" (Warum wurde das gefunden?). |
|
||||||
|
| **WP-04c**| Feedback Loop | Logging von User-Feedback (JSONL) als Basis für Learning. |
|
||||||
|
| **WP-05** | RAG-Chat | Integration von Ollama (`phi3`) und Context-Enrichment im Prompt. |
|
||||||
|
| **WP-06** | Decision Engine | Hybrid Router unterscheidet Frage (`RAG`) vs. Handlung (`Interview`). |
|
||||||
|
| **WP-07** | Interview-Assistent | One-Shot Extraction: Erzeugt Markdown-Drafts aus User-Input. |
|
||||||
|
| **WP-10** | Web UI | Streamlit-Frontend als Ersatz für das Terminal. |
|
||||||
|
| **WP-10a**| Draft Editor | GUI-Komponente zum Bearbeiten und Speichern generierter Notizen. |
|
||||||
|
| **WP-11** | Backend Intelligence | `nomic-embed-text` (768d) und Matrix-Logik für Kanten-Typisierung. |
|
||||||
|
| **WP-15** | Smart Edge Allocation | LLM-Filter für Kanten in Chunks + Traffic Control (Semaphore). |
|
||||||
|
| **WP-19** | Graph Visualisierung | **Frontend Modularisierung:** Umbau auf `ui_*.py`.<br>**Graph Engines:** Parallelbetrieb von Cytoscape (COSE) und Agraph.<br>**Tools:** "Single Source of Truth" Editor, Persistenz via URL. |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Offene Workpackages (Planung)
|
||||||
|
|
||||||
|
Diese Features stehen als nächstes an.
|
||||||
|
|
||||||
|
### WP-19a – Graph Intelligence & Discovery (Sprint-Fokus)
|
||||||
|
**Status:** 🚀 Startklar
|
||||||
|
**Ziel:** Vom "Anschauen" zum "Verstehen". Deep-Dive Werkzeuge für den Graphen.
|
||||||
|
* **Discovery Screen:** Neuer Tab für semantische Suche ("Finde Notizen über Vaterschaft") und Wildcard-Filter.
|
||||||
|
* **Filter-Logik:** "Zeige nur Wege, die zu `type:decision` führen".
|
||||||
|
* **Chunk Inspection:** Umschaltbare Granularität (Notiz vs. Chunk) zur Validierung des Smart Chunkers.
|
||||||
|
|
||||||
|
### WP-16 – Auto-Discovery & Enrichment
|
||||||
|
**Status:** 🟡 Geplant
|
||||||
|
**Ziel:** Automatisches Erkennen von fehlenden Kanten in "dummem" Text *vor* der Speicherung.
|
||||||
|
* **Problem:** Nutzer vergessen Wikilinks.
|
||||||
|
* **Lösung:** Ein "Enricher" scannt Text vor dem Import, findet Keywords (z.B. "Mindnet") und schlägt Links vor (`[[Mindnet]]`).
|
||||||
|
|
||||||
|
### WP-17 – Conversational Memory (Gedächtnis)
|
||||||
|
**Status:** 🟡 Geplant
|
||||||
|
**Ziel:** Echte Dialoge statt Request-Response.
|
||||||
|
* **Tech:** Erweiterung des `ChatRequest` DTO um `history`.
|
||||||
|
* **Logik:** Token-Management (Context Window Balancing zwischen RAG-Doks und Chat-Verlauf).
|
||||||
|
|
||||||
|
### WP-18 – Graph Health & Maintenance
|
||||||
|
**Status:** 🟡 Geplant (Prio 2)
|
||||||
|
**Ziel:** Konsistenzprüfung ("Garbage Collection").
|
||||||
|
* **Feature:** Cronjob `check_graph_integrity.py`.
|
||||||
|
* **Funktion:** Findet "Dangling Edges" (Links auf gelöschte Notizen) und repariert/löscht sie.
|
||||||
|
|
||||||
|
### WP-20 – Cloud Hybrid Mode (Optional)
|
||||||
|
**Status:** ⚪ Optional
|
||||||
|
**Ziel:** "Turbo-Modus" für Massen-Imports.
|
||||||
|
* **Konzept:** Switch in `.env`, um statt Ollama (Lokal) auf Google Gemini (Cloud) umzuschalten.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Abhängigkeiten & Release-Plan
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
graph TD
|
||||||
|
WP19(Graph Viz) --> WP19a(Discovery)
|
||||||
|
WP19a --> WP17(Memory)
|
||||||
|
WP15(Smart Edges) --> WP16(Auto-Discovery)
|
||||||
|
WP03(Import) --> WP18(Health Check)
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
---
|
||||||
|
doc_type: archive
|
||||||
|
audience: historian, architect
|
||||||
|
status: archived
|
||||||
|
context: "Archivierte Details zu abgeschlossenen Workpackages (WP01-WP19). Referenz für historische Design-Entscheidungen."
|
||||||
|
---
|
||||||
|
|
||||||
|
# Legacy Workpackages (Archiv)
|
||||||
|
|
||||||
|
**Quellen:** `Programmplan_V2.2.md`, `Active Roadmap`
|
||||||
|
|
||||||
|
**Status:** Abgeschlossen / Implementiert.
|
||||||
|
Dieses Dokument dient als Referenz für die Entstehungsgeschichte von Mindnet v2.6.
|
||||||
|
|
||||||
|
## Phase A: Fundament (WP01-03)
|
||||||
|
|
||||||
|
### WP-01 – Wissensdesign
|
||||||
|
* **Ziel:** Definition der Datenstruktur.
|
||||||
|
* **Ergebnis:** Entscheidung gegen komplexe Ontologien (RDF/OWL), für pragmatische Typen (`project`, `concept`). Definition der YAML-Frontmatter-Pflichtfelder.
|
||||||
|
* **Artefakt:** `01_knowledge_design.md`.
|
||||||
|
|
||||||
|
### WP-02 – Chunking & Hash-Strategie
|
||||||
|
* **Ziel:** Texte suchbar machen und Änderungen erkennen.
|
||||||
|
* **Ergebnis:** Implementierung des `SlidingWindowChunker`. Einführung von UUIDv5 für deterministische IDs.
|
||||||
|
* **Learning:** Starre Chunking-Grenzen zerschneiden oft den Kontext. Daher Einführung von Overlap (50 Tokens).
|
||||||
|
|
||||||
|
### WP-03 – Import-Pipeline & Edge-System
|
||||||
|
* **Ziel:** Markdown in Vektoren wandeln.
|
||||||
|
* **Ergebnis:** Der "Importer" (`import_markdown.py`). Entscheidung, Kanten (`_edges`) als eigene Collection zu führen statt als Payload in Chunks (für bessere Graphen-Algorithmen wie Centrality).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase B: Semantik (WP04)
|
||||||
|
|
||||||
|
### WP-04a – Retriever & Graph-Scoring
|
||||||
|
* **Ziel:** Bessere Suchergebnisse als reines Vektor-Matching.
|
||||||
|
* **Ergebnis:** Die Formel `Score = Semantik + GraphBonus + TypGewicht`.
|
||||||
|
* **Learning:** Reine Vektorsuche reichte nicht, um den Kontext ("Warum ist das wichtig?") zu erfassen. Der "Graph Bonus" war der Durchbruch für assoziatives Finden.
|
||||||
|
|
||||||
|
### WP-04b – Explanation Layer ("Why-Layer")
|
||||||
|
* **Ziel:** Transparenz.
|
||||||
|
* **Ergebnis:** `explain=True` Parameter. Die API liefert menschenlesbare Gründe ("Gefunden, weil Projekt Alpha davon abhängt").
|
||||||
|
|
||||||
|
### WP-04c – Feedback Logging
|
||||||
|
* **Ziel:** Datenbasis für zukünftiges Lernen schaffen.
|
||||||
|
* **Ergebnis:** Das "Data Flywheel". Jede Suche und Bewertung wird in JSONL-Dateien geloggt (`search_history.jsonl`, `feedback.jsonl`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase C: Persönlichkeit (WP05-07)
|
||||||
|
|
||||||
|
### WP-05 – RAG-Chat
|
||||||
|
* **Ziel:** Natürliche Sprache statt Suchergebnisse.
|
||||||
|
* **Ergebnis:** Integration von Ollama (`phi3`).
|
||||||
|
* **Tech:** Prompt-Engineering (`prompts.yaml`) statt Fine-Tuning, um flexibel zu bleiben.
|
||||||
|
|
||||||
|
### WP-06 – Decision Engine
|
||||||
|
* **Ziel:** Strategische Beratung statt nur Fakten.
|
||||||
|
* **Ergebnis:** Der Hybrid Router.
|
||||||
|
* **Konzept:** Unterscheidung von *Fragen* (RAG) und *Handlungen* (Interview). Strategisches Laden von Werten (`type: value`), um Entscheidungen moralisch zu begründen.
|
||||||
|
|
||||||
|
### WP-07 – Interview-Assistent
|
||||||
|
* **Ziel:** Bekämpfung des "Writer's Block".
|
||||||
|
* **Ergebnis:** One-Shot Extraction. Der Chatbot generiert aus einem losen Satz ("Neues Projekt Alpha") einen strukturierten Markdown-Draft.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase D: Interaktion (WP10-15)
|
||||||
|
|
||||||
|
### WP-10/10a – Web UI & Draft Editor
|
||||||
|
* **Ziel:** Usability für Nicht-Techniker.
|
||||||
|
* **Ergebnis:** Streamlit App. Ablösung des Terminals.
|
||||||
|
* **Feature:** "Healing Parser", der defektes JSON vom LLM repariert.
|
||||||
|
|
||||||
|
### WP-11 – Backend Intelligence
|
||||||
|
* **Ziel:** Automatisierung der Vernetzung.
|
||||||
|
* **Ergebnis:** AsyncIO Umstellung für Performance. Einführung von `nomic-embed-text` (768d) für präzise Semantik. Matrix-Logik für automatische Kanten-Typisierung.
|
||||||
|
|
||||||
|
### WP-15 – Smart Edge Allocation (Meilenstein)
|
||||||
|
* **Problem:** "Broadcasting". Ein Chunk erbte alle Links der Note, auch irrelevante. Das verwässerte die Suchergebnisse.
|
||||||
|
* **Lösung:** LLM prüft jeden Chunk auf Link-Relevanz.
|
||||||
|
* **Tech:** Einführung von **Traffic Control** (Semaphore), um Import und Chat zu parallelisieren, ohne die Hardware zu überlasten.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase E: Visualisierung & Maintenance (WP19)
|
||||||
|
|
||||||
|
### WP-19 – Graph Visualisierung & Modularisierung
|
||||||
|
* **Ziel:** Transparenz über die Datenstruktur schaffen und technische Schulden (Monolith) abbauen.
|
||||||
|
* **Ergebnis:**
|
||||||
|
* **Modularisierung:** Aufsplittung der `ui.py` in Router, Services und Views (`ui_*.py`).
|
||||||
|
* **Graph Explorer:** Einführung von `st-cytoscape` für stabile, nicht-überlappende Layouts (COSE) als Ergänzung zur Legacy-Engine (Agraph).
|
||||||
|
* **Single Source of Truth:** Der Editor lädt Inhalte nun direkt vom Dateisystem statt aus (potenziell veralteten) Vektor-Payloads.
|
||||||
|
* **UX:** Einführung von URL-Persistenz für Layout-Settings und CSS-basiertes Highlighting zur Vermeidung von Re-Renders.
|
||||||
File renamed without changes.
+85
-48
@@ -1,5 +1,5 @@
|
|||||||
# mindnet v2.4 — Programmplan
|
# mindnet v2.4 — Programmplan
|
||||||
**Version:** 2.6.0 (Inkl. WP-15 Smart Edge Allocation)
|
**Version:** 2.7.0 (Post-WP15: Roadmap Erweiterung für Graph-Health & Visualisierung)
|
||||||
**Stand:** 2025-12-12
|
**Stand:** 2025-12-12
|
||||||
**Status:** Aktiv
|
**Status:** Aktiv
|
||||||
|
|
||||||
@@ -36,6 +36,9 @@
|
|||||||
- [WP-15 – Smart Edge Allocation \& Chunking Strategies (abgeschlossen)](#wp-15--smart-edge-allocation--chunking-strategies-abgeschlossen)
|
- [WP-15 – Smart Edge Allocation \& Chunking Strategies (abgeschlossen)](#wp-15--smart-edge-allocation--chunking-strategies-abgeschlossen)
|
||||||
- [WP-16 – Auto-Discovery \& Enrichment (geplant)](#wp-16--auto-discovery--enrichment-geplant)
|
- [WP-16 – Auto-Discovery \& Enrichment (geplant)](#wp-16--auto-discovery--enrichment-geplant)
|
||||||
- [WP-17 – Conversational Memory (Dialog-Gedächtnis) (geplant)](#wp-17--conversational-memory-dialog-gedächtnis-geplant)
|
- [WP-17 – Conversational Memory (Dialog-Gedächtnis) (geplant)](#wp-17--conversational-memory-dialog-gedächtnis-geplant)
|
||||||
|
- [WP-18 – Graph Health \& Maintenance (NEU, geplant)](#wp-18--graph-health--maintenance-neu-geplant)
|
||||||
|
- [WP-19 – Graph Visualisierung \& Explorer (NEU, geplant)](#wp-19--graph-visualisierung--explorer-neu-geplant)
|
||||||
|
- [WP-20 – Cloud Hybrid Mode (Gemini) (NEU, geplant)](#wp-20--cloud-hybrid-mode-gemini-neu-geplant)
|
||||||
- [7. Abhängigkeiten (vereinfacht, aktualisiert)](#7-abhängigkeiten-vereinfacht-aktualisiert)
|
- [7. Abhängigkeiten (vereinfacht, aktualisiert)](#7-abhängigkeiten-vereinfacht-aktualisiert)
|
||||||
- [8. Laufzeit- \& Komplexitätsindikatoren (aktualisiert)](#8-laufzeit---komplexitätsindikatoren-aktualisiert)
|
- [8. Laufzeit- \& Komplexitätsindikatoren (aktualisiert)](#8-laufzeit---komplexitätsindikatoren-aktualisiert)
|
||||||
- [9. Programmfortschritt (Ampel, aktualisiert)](#9-programmfortschritt-ampel-aktualisiert)
|
- [9. Programmfortschritt (Ampel, aktualisiert)](#9-programmfortschritt-ampel-aktualisiert)
|
||||||
@@ -194,7 +197,7 @@ Die folgenden Prinzipien steuern alle Workpackages und Entscheidungen:
|
|||||||
Phase B – Semantik, Graph & Lernen (Fertig)
|
Phase B – Semantik, Graph & Lernen (Fertig)
|
||||||
Phase C – Persönlichkeitsmodell & KI-Zwilling (Fertig)
|
Phase C – Persönlichkeitsmodell & KI-Zwilling (Fertig)
|
||||||
Phase D – Agenten, MCP & Interaktion (Aktiv)
|
Phase D – Agenten, MCP & Interaktion (Aktiv)
|
||||||
Phase E – Review, Refactoring, Dokumentation
|
Phase E – Maintenance, Visualisierung & Scaling (Neu)
|
||||||
|
|
||||||
Alle Workpackages sind einer Phase zugeordnet. WP-01 bis WP-07 und WP-10/10a/11 sind erfolgreich abgeschlossen.
|
Alle Workpackages sind einer Phase zugeordnet. WP-01 bis WP-07 und WP-10/10a/11 sind erfolgreich abgeschlossen.
|
||||||
|
|
||||||
@@ -556,6 +559,7 @@ Automatisches Erkennen und Vorschlagen von fehlenden Kanten in "dummem" Text (oh
|
|||||||
- Komplexität: Hoch
|
- Komplexität: Hoch
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### WP-17 – Conversational Memory (Dialog-Gedächtnis) (geplant)
|
### WP-17 – Conversational Memory (Dialog-Gedächtnis) (geplant)
|
||||||
|
|
||||||
**Phase:** D
|
**Phase:** D
|
||||||
@@ -573,19 +577,76 @@ Erweiterung des Chat-Backends von einem statischen Request-Response-Modell zu ei
|
|||||||
**Aufwand / Komplexität:**
|
**Aufwand / Komplexität:**
|
||||||
- Aufwand: Mittel
|
- Aufwand: Mittel
|
||||||
- Komplexität: Mittel
|
- Komplexität: Mittel
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### WP-18 – Graph Health & Maintenance (NEU, geplant)
|
||||||
|
|
||||||
|
**Phase:** E
|
||||||
|
**Status:** 🟡 geplant (Prio 2)
|
||||||
|
|
||||||
|
**Ziel:**
|
||||||
|
Sicherstellung der Konsistenz des Wissensgraphen bei Löschungen oder Umbenennungen von Notizen ("Dangling Edges").
|
||||||
|
|
||||||
|
**Architektur-Idee:**
|
||||||
|
- **Health-Check Script:** Ein Cronjob (`scripts/check_graph_integrity.py`), der alle Kanten prüft, ob ihre `target_id` noch in `mindnet_notes` existiert.
|
||||||
|
- **Report:** Ausgabe von "Broken Links" als Liste für den User.
|
||||||
|
- **Auto-Heal (Optional):** Markieren von defekten Kanten als `broken` statt hartem Löschen.
|
||||||
|
|
||||||
|
**Aufwand / Komplexität:**
|
||||||
|
- Aufwand: Niedrig
|
||||||
|
- Komplexität: Mittel
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### WP-19 – Graph Visualisierung & Explorer (NEU, geplant)
|
||||||
|
|
||||||
|
**Phase:** E
|
||||||
|
**Status:** 🟡 geplant (Prio 1)
|
||||||
|
|
||||||
|
**Ziel:**
|
||||||
|
Schaffung von Vertrauen und Transparenz durch Visualisierung der vom "Smart Chunker" erzeugten Verbindungen.
|
||||||
|
|
||||||
|
**Architektur-Idee:**
|
||||||
|
- **Frontend-Erweiterung:** Neuer Tab "🕸️ Graph" in Streamlit.
|
||||||
|
- **Tech-Stack:** Integration von `streamlit-agraph` oder `pyvis`.
|
||||||
|
- **Feature:** Visualisierung der Nachbarschaft einer Notiz (Ego-Graph) oder eines Suchergebnisses.
|
||||||
|
- **Nutzen:** Schnelle Validierung, ob Smart Edges korrekt gesetzt wurden.
|
||||||
|
|
||||||
|
**Aufwand / Komplexität:**
|
||||||
|
- Aufwand: Mittel
|
||||||
|
- Komplexität: Mittel
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### WP-20 – Cloud Hybrid Mode (Gemini) (NEU, geplant)
|
||||||
|
|
||||||
|
**Phase:** E
|
||||||
|
**Status:** ⚪ optional
|
||||||
|
|
||||||
|
**Ziel:**
|
||||||
|
Optionale Beschleunigung ("Turbo-Modus") für Massen-Imports oder komplexe Analysen durch Nutzung externer High-Performance LLMs (Google Gemini 1.5 Flash), unter Beachtung des Datenschutzes.
|
||||||
|
|
||||||
|
**Architektur-Idee:**
|
||||||
|
- **Provider-Switch:** Erweiterung des `LLMService` um einen Provider-Parameter (`ollama` vs. `gemini`).
|
||||||
|
- **Konfiguration:** `types.yaml` oder `.env` erlaubt Umschalten pro Umgebung (z.B. Dev=Cloud, Prod=Local).
|
||||||
|
- **Privacy:** Warnhinweis im UI, wenn Daten die lokale Umgebung verlassen.
|
||||||
|
|
||||||
|
**Aufwand / Komplexität:**
|
||||||
|
- Aufwand: Mittel
|
||||||
|
- Komplexität: Niedrig
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 7. Abhängigkeiten (vereinfacht, aktualisiert)
|
## 7. Abhängigkeiten (vereinfacht, aktualisiert)
|
||||||
|
|
||||||
WP01 → WP02 → WP03 → WP04a
|
WP01-03 → WP04-06 (Core)
|
||||||
WP04a → WP04b → WP04c → WP08
|
WP11 → WP15 (Smart Edges)
|
||||||
WP03 → WP05 → WP06 → WP07
|
WP15 → WP19 (Visualisierung - zur Kontrolle)
|
||||||
WP07 → WP10a
|
WP15 → WP16 (Auto-Discovery)
|
||||||
WP03 → WP09
|
WP03 → WP18 (Maintenance)
|
||||||
WP01/WP03 → WP10 → WP11 → WP12
|
WP10 → WP17 (Memory)
|
||||||
WP10 → WP17
|
WP20 (Cloud) ist unabhängig/optional.
|
||||||
WP11 → WP15 → WP16
|
|
||||||
WP03/WP04 → WP13
|
|
||||||
Alles → WP14
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -593,50 +654,26 @@ Erweiterung des Chat-Backends von einem statischen Request-Response-Modell zu ei
|
|||||||
|
|
||||||
| WP | Aufwand | Komplexität |
|
| WP | Aufwand | Komplexität |
|
||||||
|-------|----------------|------------------|
|
|-------|----------------|------------------|
|
||||||
| WP04b | Mittel | Hoch |
|
|
||||||
| WP04c | Mittel | Mittel/Hoch |
|
|
||||||
| WP05 | Mittel | Mittel |
|
|
||||||
| WP06 | Mittel | Hoch |
|
|
||||||
| WP07 | Niedrig/Mittel | Mittel |
|
|
||||||
| WP08 | Hoch | Hoch |
|
|
||||||
| WP09 | Mittel | Niedrig/Mittel |
|
|
||||||
| WP10 | Hoch | Hoch |
|
|
||||||
| WP10a | Mittel | Mittel |
|
|
||||||
| WP11 | Hoch | Hoch |
|
|
||||||
| WP12 | Niedrig/Mittel | Mittel |
|
|
||||||
| WP13 | Mittel | Mittel |
|
|
||||||
| WP14 | Mittel | Niedrig/Mittel |
|
|
||||||
| WP15 | Mittel | Hoch |
|
| WP15 | Mittel | Hoch |
|
||||||
| WP16 | Mittel | Hoch |
|
| WP16 | Mittel | Hoch |
|
||||||
| WP17 | Mittel | Mittel |
|
| WP17 | Mittel | Mittel |
|
||||||
|
| WP18 | Niedrig | Mittel |
|
||||||
|
| WP19 | Mittel | Mittel |
|
||||||
|
| WP20 | Mittel | Niedrig |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 9. Programmfortschritt (Ampel, aktualisiert)
|
## 9. Programmfortschritt (Ampel, aktualisiert)
|
||||||
|
|
||||||
| WP | Status |
|
| WP | Status | Titel |
|
||||||
|-------|--------|
|
|-------|--------|-------|
|
||||||
| WP01 | 🟢 |
|
| WP01-14| 🟢 | (Basis-System) |
|
||||||
| WP02 | 🟢 |
|
| WP15 | 🟢 | Smart Edge Allocation |
|
||||||
| WP03 | 🟢 |
|
| WP16 | 🟡 | Auto-Discovery |
|
||||||
| WP04a | 🟢 |
|
| WP17 | 🟡 | Conversational Memory |
|
||||||
| WP04b | 🟢 |
|
| WP18 | 🟡 | Graph Health (Neu) |
|
||||||
| WP04c | 🟢 |
|
| WP19 | 🟡 | Visualization (Neu) |
|
||||||
| WP05 | 🟢 |
|
| WP20 | ⚪ | Cloud Mode (Neu) |
|
||||||
| WP05b | ⚪ |
|
|
||||||
| WP06 | 🟢 |
|
|
||||||
| WP07 | 🟢 |
|
|
||||||
| WP08 | 🟡 |
|
|
||||||
| WP09 | 🟡 |
|
|
||||||
| WP10 | 🟢 |
|
|
||||||
| WP10a | 🟢 |
|
|
||||||
| WP11 | 🟢 |
|
|
||||||
| WP12 | 🟡 |
|
|
||||||
| WP13 | 🟡 |
|
|
||||||
| WP14 | 🟡 |
|
|
||||||
| WP15 | 🟢 |
|
|
||||||
| WP16 | 🟡 |
|
|
||||||
| WP17 | 🟡 |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -194,9 +194,12 @@ Damit das Chaos nicht wächst, löschen wir den fertigen Branch.
|
|||||||
| Wo? | Befehl | Was tut es? |
|
| Wo? | Befehl | Was tut es? |
|
||||||
| :--- | :--- | :--- |
|
| :--- | :--- | :--- |
|
||||||
| **Beelink** | `sudo systemctl restart mindnet-dev` | **Neustart Dev-Backend (Port 8002).** |
|
| **Beelink** | `sudo systemctl restart mindnet-dev` | **Neustart Dev-Backend (Port 8002).** |
|
||||||
|
| **Beelink** | `sudo systemctl restart mindnet-ui-dev` | **Neustart Dev-Frontend (Port 8002).** |
|
||||||
| **Beelink** | `journalctl -u mindnet-dev -f` | **Live-Logs Backend.** |
|
| **Beelink** | `journalctl -u mindnet-dev -f` | **Live-Logs Backend.** |
|
||||||
| **Beelink** | `python debug_analysis.py` | **Prüft Aliases & Scores.** |
|
| **Beelink** | `python debug_analysis.py` | **Prüft Aliases & Scores.** |
|
||||||
| **Beelink** | `python -m scripts.reset_qdrant ...` | **Löscht & Repariert DB.** |
|
| **Beelink** | `python3 -m scripts.reset_qdrant --mode wipe --prefix "mindnet_dev" --yes` | **Löscht & Repariert DB.** |
|
||||||
|
| **Beelink** | `python3 -m scripts.import_markdown --vault ./vault_master --prefix "mindnet_dev" --apply --force` | **Löscht & Repariert DB.** |
|
||||||
|
| **Beelink** | `source .venv/bin/activate` | **Aktivieren des virtual environments** |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+5
-1
@@ -30,4 +30,8 @@ tqdm>=4.67.1
|
|||||||
pytest>=8.4.2
|
pytest>=8.4.2
|
||||||
|
|
||||||
# --- Frontend (WP-10) ---
|
# --- Frontend (WP-10) ---
|
||||||
streamlit>=1.39.0
|
streamlit>=1.39.0
|
||||||
|
|
||||||
|
# Visualization (Parallelbetrieb)
|
||||||
|
streamlit-agraph>=0.0.45
|
||||||
|
st-cytoscape>=1.0.0
|
||||||
Reference in new issue
Block a user