Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

Apply reviewed change

evgenyponomarev52618f075cc2
diff --git a/semantica/cli.py b/semantica/cli.py
index d05a00f1..eb875430 100644
--- a/semantica/cli.py
+++ b/semantica/cli.py
@@ -1415,6 +1415,31 @@ _INGEST_TYPES = [
]
_INGEST_FORMATS = ["pdf", "docx", "csv", "excel", "html", "json", "parquet", "xml", "rdf"]
+_GRAPH_STORE_ENV_BACKEND_HINTS = {
+ "GRAPH_STORE_NEO4J_URI": "neo4j",
+ "GRAPH_STORE_FALKORDB_HOST": "falkordb",
+ "GRAPH_STORE_NEPTUNE_ENDPOINT": "neptune",
+ "GRAPH_STORE_AGE_CONNECTION_STRING": "age",
+}
+
+
+def _configured_ingest_graph_backend(
+ cli_ctx: CLIContext, store_override: Optional[str]
+) -> Optional[str]:
+ graph_db = dict(cli_ctx.config.to_dict().get("graph_db", {}))
+ backend = store_override or cli_ctx.store_backend or graph_db.get("backend")
+ if backend:
+ return str(backend)
+
+ env_backend = os.environ.get("GRAPH_STORE_DEFAULT_BACKEND")
+ if env_backend:
+ return env_backend
+
+ for env_var, hinted_backend in _GRAPH_STORE_ENV_BACKEND_HINTS.items():
+ if os.environ.get(env_var):
+ return hinted_backend
+
+ return None
@main.command()
@@ -1452,6 +1477,12 @@ def ingest(
_dry(cli_ctx, "ingest", json_out=_is_json(cli_ctx, local_json),
source=source, type=ingestor_type, format=fmt)
return
+ graph_backend = _configured_ingest_graph_backend(cli_ctx, store_override)
+ if graph_backend and graph_backend.lower() != "memory" and not output:
+ raise click.ClickException(
+ "semantica ingest does not write to graph stores yet; use "
+ f"'semantica kg build --source {source}' to build the graph."
+ )
kwargs: Dict[str, Any] = {"batch_size": batch_size}
if ingestor_type:
kwargs["source_type"] = ingestor_type
diff --git a/tests/test_cli_commands.py b/tests/test_cli_commands.py
index 4a054be1..9b3318e8 100644
--- a/tests/test_cli_commands.py
+++ b/tests/test_cli_commands.py
@@ -336,6 +336,21 @@ class TestIngest:
assert captured["sources"] == "README.md"
assert captured["kwargs"]["method"] == "file"
+ def test_configured_graph_backend_does_not_report_false_success(
+ self, runner, monkeypatch
+ ):
+ monkeypatch.setenv("GRAPH_STORE_DEFAULT_BACKEND", "neo4j")
+ monkeypatch.setattr(
+ "semantica.ingest.methods.ingest_file",
+ lambda sources, **kwargs: [{"path": sources}],
+ )
+
+ result = runner.invoke(cli_module.main, ["ingest", "README.md"])
+
+ assert result.exit_code != 0
+ assert "does not write to graph stores" in result.output
+ assert "Ingested" not in result.output
+
def test_import_error_is_clean(self, runner, monkeypatch):
monkeypatch.setattr(cli_module, "__import__", _import_side_effect, raising=False)
original_import = __import__