Files
kg-scr/kg_ocr/__init__.py
Aman Nalakath 7503a441c2
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
kg: graph build, traversal queries, neo4j export - kg_ocr.graph builds a networkx graph (docs, chunks, entities, citations, co-occurrence) from chunk markdown - analyzer for summaries, top entities/citations, anomaly checks - traversal: chunks_for_entity/citation, related_entities, expand_context - export: JSON round-trip, GraphML, batched MERGE into neo4j - new CLI: ocr-pipeline kg build|stats|query|export - lazy kg_ocr imports, networkx/neo4j behind extras - dropped dead watch.py shim, added KgConfig stub - trimmed README, updated TODO
2026-07-20 19:50:38 +02:00

51 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"),
"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