app/core/type_registry.py hinzugefügt
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s

This commit is contained in:
Lars 2025-11-07 13:28:41 +01:00
parent 59fe8154f2
commit 5f358d329b

79
app/core/type_registry.py Normal file
View File

@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-
"""
app/core/type_registry.py mindnet · WP-03 (Version 1.0.0)
Zweck:
- Lädt eine optionale Typen-Registry aus config/types.yaml|json.
- Liefert pro `type` eine Konfiguration (z. B. Chunk-Profile, Standard-Edges,
Retriever-Gewichtungen). Wird in import/chunk/edges integriert.
Verhalten:
- Fehlt die Datei oder der Typ es werden Defaults genutzt.
- Registry wird gecacht (lazy-load).
"""
__version__ = "1.0.0"
import os
import json
from typing import Any, Dict
try:
import yaml # type: ignore
except Exception:
yaml = None # optional
_CACHE: Dict[str, Any] = {}
DEFAULT_REG = {
"version": "1.0",
"types": {
"concept": {
"chunk_profile": "medium",
"edge_defaults": ["references", "related_to"],
"retriever_weight": 1.0
},
"task": {
"chunk_profile": "short",
"edge_defaults": ["depends_on", "belongs_to"],
"retriever_weight": 0.8
},
"experience": {
"chunk_profile": "medium",
"edge_defaults": ["derived_from"],
"retriever_weight": 0.9
}
}
}
def load_type_registry(path: str = "config/types.yaml", silent: bool = False) -> Dict[str, Any]:
global _CACHE
if _CACHE:
return _CACHE
def load_yaml(p: str) -> Dict[str, Any]:
if yaml is None:
return {}
with open(p, "r", encoding="utf-8") as f:
return yaml.safe_load(f) or {}
def load_json(p: str) -> Dict[str, Any]:
with open(p, "r", encoding="utf-8") as f:
return json.load(f) or {}
reg: Dict[str, Any] = {}
if os.path.exists(path):
try:
if path.endswith(".yaml") or path.endswith(".yml"):
reg = load_yaml(path)
elif path.endswith(".json"):
reg = load_json(path)
except Exception as e:
if not silent:
print(f"[type_registry] WARN: failed to load {path}: {e}")
if not reg:
# Fallback
reg = DEFAULT_REG
_CACHE = reg
return _CACHE