Files
kg-scr/kg_ocr/__init__.py
Aman Nalakath 05aed7366d
Some checks failed
tests / core (macos-latest, py3.11) (push) Has been cancelled
tests / core (macos-latest, py3.12) (push) Has been cancelled
tests / core (macos-latest, py3.13) (push) Has been cancelled
tests / core (ubuntu-latest, py3.11) (push) Has been cancelled
tests / core (ubuntu-latest, py3.12) (push) Has been cancelled
tests / core (ubuntu-latest, py3.13) (push) Has been cancelled
tests / doctor CLI smoke test (push) Has been cancelled
feat(kg): add markdown export format for knowledge graph
- Add kg_ocr/export/markdown_exporter.py with export_markdown()
- Cluster entity co-occurrences using Louvain community detection
- Wire -f markdown into `ocr-pipeline kg export` CLI command with KG_REPORT.md default
- Add unit and CLI tests in tests/test_graph.py
- Document markdown export in README.md
- Untrack pycache binaries and ignore graphify-out and KG_REPORT.md
2026-09-18 16:40:21 +02:00

52 lines
1.8 KiB
Python

"""Knowledge graph + RAG interface built on the OCR pipeline.
Lightweight submodules (graph, export) import without optional deps.
The txtai/litellm RAG pieces need: uv sync --extra kg.
"""
from __future__ import annotations
from typing import Any
_LAZY: dict[str, tuple[str, str]] = {
"get_screenshots": (".ocr", "get_screenshots"),
"extract_text": (".ocr", "extract_text"),
"create_and_index": (".embeddings", "create_and_index"),
"retrieve": (".rag", "retrieve"),
"ask_wllm": (".rag", "ask_wllm"),
"build_graph": (".graph", "build_graph"),
"build_from_directory": (".graph", "build_from_directory"),
"summary": (".graph", "summary"),
"top_entities": (".graph", "top_entities"),
"detect_anomalies": (".graph", "detect_anomalies"),
"chunks_for_entity": (".graph", "chunks_for_entity"),
"chunks_for_citation": (".graph", "chunks_for_citation"),
"related_entities": (".graph", "related_entities"),
"expand_context": (".graph", "expand_context"),
"export_json": (".export", "export_json"),
"export_graphml": (".export", "export_graphml"),
"export_markdown": (".export", "export_markdown"),
"load_json": (".export", "load_json"),
"Neo4jExporter": (".export", "Neo4jExporter"),
}
__all__ = list(_LAZY)
def __getattr__(name: str) -> Any:
if name not in _LAZY:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
module_name, attr = _LAZY[name]
try:
from importlib import import_module
module = import_module(module_name, __name__)
except ImportError as exc:
raise ImportError(
f"kg_ocr.{name} needs optional dependencies: uv sync --extra kg "
f"(graph/export only need networkx; embeddings/rag also need txtai, litellm)"
) from exc
value = getattr(module, attr)
globals()[name] = value
return value