Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
docs: fix KnowledgeGraph mismatch and update tests for issue #144
KaifAhmad1dcd6f25f87e4
diff --git a/cookbook/introduction/17_Conflict_Detection_and_Resolution.ipynb b/cookbook/introduction/17_Conflict_Detection_and_Resolution.ipynbindex e10f0374..9705466a 100644--- a/cookbook/introduction/17_Conflict_Detection_and_Resolution.ipynb+++ b/cookbook/introduction/17_Conflict_Detection_and_Resolution.ipynb@@ -26,7 +26,7 @@"\n","- Use `ConflictDetector.detect_value_conflicts(entities, property_name=...)` when you want to check one field.\n","- Use `ConflictDetector.detect_conflicts(entities)` when you want a broader scan (value/type/temporal/etc.).\n",- "- If you're starting from a `KnowledgeGraph`, pull entities via `kg.get(\"entities\", [])` (not `kg.entities`).\n",+ "- If you're starting from a Knowledge Graph dictionary (built via `GraphBuilder`), pull entities via `kg.get(\"entities\", [])`.\n","\n","### Key Capabilities\n","\n",diff --git a/docs/reference/ontology.md b/docs/reference/ontology.mdindex f0598903..8c6ce8f2 100644--- a/docs/reference/ontology.md+++ b/docs/reference/ontology.md@@ -222,17 +222,31 @@ ontology:```pythonfrom semantica.ontology import OntologyEngine-from semantica.kg import KnowledgeGraph+from semantica.kg import GraphBuilder, GraphValidator# 1. Generate Ontology from Sample Dataengine = OntologyEngine()ontology = engine.from_data(sample_data)-# 2. Initialize KG with Ontology-kg = KnowledgeGraph(schema=ontology)--# 3. Add Data (Validated against Ontology)-kg.add_entities(full_dataset) # Will raise error if violates schema+# 2. Extract schema for validation+schema = {+ "entity_types": [c["name"] for c in ontology["classes"]],+ "relationship_types": [p["name"] for p in ontology["properties"]]+}++# 3. Initialize Validator and Builder+validator = GraphValidator(schema=schema, strict=True)+builder = GraphBuilder()++# 4. Build Knowledge Graph+kg = builder.build(full_dataset)++# 5. Validate against Ontology Schema+validation_result = validator.validate(kg)+if validation_result.is_valid:+ print("Knowledge Graph matches the ontology schema!")+else:+ print(f"Validation issues found: {validation_result.issues}")```---diff --git a/docs/reference/reasoning.md b/docs/reference/reasoning.mdindex af448e01..85fe4d32 100644--- a/docs/reference/reasoning.md+++ b/docs/reference/reasoning.md@@ -190,8 +190,8 @@ if proof:### Knowledge Graph Enrichment```python-from semantica.reasoning import Reasoner, Rule-from semantica.kg import KnowledgeGraph+from semantica.reasoning import Reasoner+from semantica.kg import GraphBuilder# 1. Define Rulesrules = [@@ -199,14 +199,19 @@ rules = ["IF Ancestor(?x, ?y) AND Ancestor(?y, ?z) THEN Ancestor(?x, ?z)"]-# 2. Load Graph and Run Inference-kg = KnowledgeGraph()+# 2. Build Graph and Run Inference+builder = GraphBuilder()+kg = builder.build(sources=data)+reasoner = Reasoner()-inferred = reasoner.infer_facts(kg.get_all_triplets(), rules)+# Infer new facts from entities and relationships+inferred = reasoner.infer_facts(kg["entities"] + kg["relationships"], rules)-# 3. Update Graph+# 3. Update Graph with Inferred Factsfor fact_str in inferred:- kg.add_fact_from_string(fact_str)+ # Add new inferred facts back to the graph+ # For a production app, you'd parse these into entities/relationships+ kg["entities"].append({"type": "InferredFact", "name": fact_str})```---diff --git a/docs/reference/seed.md b/docs/reference/seed.mdindex 882fd4f1..d43b36bc 100644--- a/docs/reference/seed.md+++ b/docs/reference/seed.md@@ -189,7 +189,6 @@ seed:```pythonfrom semantica.seed import SeedDataManagerfrom semantica.ingest import Ingestor-from semantica.kg import KnowledgeGraph# 1. Load Foundation (Seed)seed_manager = SeedDataManager()diff --git a/docs/reference/visualization.md b/docs/reference/visualization.mdindex 2de774f9..3f472cd2 100644--- a/docs/reference/visualization.md+++ b/docs/reference/visualization.md@@ -253,12 +253,12 @@ visualization:### Exploratory Data Analysis (EDA)```python-from semantica.ingest import Ingestor-from semantica.kg import KnowledgeGraph+from semantica.kg import GraphBuilderfrom semantica.visualization import KGVisualizer, AnalyticsVisualizer-# 1. Load Data-kg = KnowledgeGraph.load("my_graph")+# 1. Build Knowledge Graph+builder = GraphBuilder()+kg = builder.build(sources=sample_data)# 2. Visualize Structurekg_viz = KGVisualizer()diff --git a/semantica/context/agent_context.py b/semantica/context/agent_context.pyindex d04b43aa..6ec6377f 100644--- a/semantica/context/agent_context.py+++ b/semantica/context/agent_context.py@@ -178,7 +178,7 @@ class AgentContext:vs_path = os.path.join(path, "vector_store")self.vector_store.save(vs_path)- # 3. Save KnowledgeGraph state+ # 3. Save Knowledge Graph stateif self.knowledge_graph:if hasattr(self.knowledge_graph, "save_to_file"):# JSON export for ContextGraph@@ -214,7 +214,7 @@ class AgentContext:if os.path.exists(vs_path):self.vector_store.load(vs_path)- # 3. Load KnowledgeGraph state+ # 3. Load Knowledge Graph stateif self.knowledge_graph:kg_json_path = os.path.join(path, "knowledge_graph.json")kg_dir_path = os.path.join(path, "knowledge_graph")diff --git a/tests/kg/test_kg.py b/tests/kg/test_kg.pyindex 4ae35c2d..5f727537 100644--- a/tests/kg/test_kg.py+++ b/tests/kg/test_kg.py@@ -31,11 +31,11 @@ class TestGraphBuilder(unittest.TestCase):def test_initialization_defaults(self):"""Test initialization with default parameters"""builder = GraphBuilder()- self.assertTrue(builder.merge_entities)+ self.assertFalse(builder.merge_entities)self.assertTrue(builder.resolve_conflicts)self.assertFalse(builder.enable_temporal)# Should initialize resolver and conflict detector by default- self.assertIsNotNone(builder.entity_resolver)+ self.assertIsNone(builder.entity_resolver)self.assertIsNotNone(builder.conflict_detector)def test_initialization_disabled_features(self):