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
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
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
This commit is contained in:
@@ -1,17 +1,50 @@
|
||||
"""Experimental txtai/litellm RAG interface built on the OCR pipeline.
|
||||
"""Knowledge graph + RAG interface built on the OCR pipeline.
|
||||
|
||||
This package is a prototype. The supported interface is the `ocr-pipeline` CLI
|
||||
(src/ocr_pipeline). Extra dependencies are required: `uv sync --extra kg`.
|
||||
Lightweight submodules (graph, export) import without optional deps.
|
||||
The txtai/litellm RAG pieces need: uv sync --extra kg.
|
||||
"""
|
||||
|
||||
try:
|
||||
from .ocr import get_screenshots, extract_text
|
||||
from .embeddings import create_and_index
|
||||
from .rag import retrieve, ask_wllm
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"kg_ocr is experimental and needs extra dependencies: "
|
||||
"uv sync --extra kg (or: uv pip install txtai litellm python-dotenv)"
|
||||
) from exc
|
||||
from __future__ import annotations
|
||||
|
||||
__all__ = ["get_screenshots", "extract_text", "create_and_index", "retrieve", "ask_wllm"]
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user