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
Update Triplet Store notebook with connection handling and path setup
KaifAhmad19e1aa6404338
diff --git a/cookbook/introduction/20_Triplet_Store.ipynb b/cookbook/introduction/20_Triplet_Store.ipynbindex 5bedd7be..4390d648 100644--- a/cookbook/introduction/20_Triplet_Store.ipynb+++ b/cookbook/introduction/20_Triplet_Store.ipynb@@ -21,7 +21,39 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 3,+ "metadata": {},+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",+ "WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",+ "WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",+ "WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",+ "WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",+ "WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",+ "WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",+ "WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",+ "WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"+ ]+ }+ ],+ "source": [+ "import sys\n",+ "import os\n",+ "\n",+ "# Add the project root to the path so we can import the local version of semantica\n",+ "sys.path.append(os.path.abspath('../../'))\n",+ "\n",+ "# If running in Google Colab, uncomment the following line to install dependencies\n",+ "# !pip install -q semantica"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 4,"metadata": {},"outputs": [],"source": [@@ -43,7 +75,7 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 5,"metadata": {},"outputs": [],"source": [@@ -54,7 +86,12 @@" endpoint=\"http://localhost:9999/blazegraph\"\n",")\n","\n",- "print(f\"Connected to {store.backend_type} store\")"+ "# Check connection status\n",+ "if hasattr(store._store_backend, 'connected') and store._store_backend.connected:\n",+ " print(f\"Successfully connected to {store.backend_type} store at {store.endpoint}\")\n",+ "else:\n",+ " print(f\"Warning: Could not connect to {store.backend_type} at {store.endpoint}\")\n",+ " print(\"Operations requiring a live store connection will be skipped or fail.\")"]},{@@ -97,25 +134,35 @@"metadata": {},"outputs": [],"source": [- "# Add a single triplet\n",- "store.add_triplet(triplet1)\n",- "\n",- "# Create more triplets\n",- "triplets = [\n",- " Triplet(\n",- " subject=\"http://example.org/Bob\",\n",- " predicate=\"http://xmlns.com/foaf/0.1/knows\",\n",- " object=\"http://example.org/Charlie\"\n",- " ),\n",- " Triplet(\n",- " subject=\"http://example.org/Charlie\",\n",- " predicate=\"http://xmlns.com/foaf/0.1/knows\",\n",- " object=\"http://example.org/David\"\n",- " )\n",- "]\n",- "\n",- "# Bulk add\n",- "store.add_triplets(triplets)"+ "from semantica.utils.exceptions import ProcessingError\n",+ "\n",+ "try:\n",+ " # Add a single triplet\n",+ " store.add_triplet(triplet1)\n",+ " print(\"Added single triplet successfully.\")\n",+ "\n",+ " # Create more triplets\n",+ " triplets = [\n",+ " Triplet(\n",+ " subject=\"http://example.org/Bob\",\n",+ " predicate=\"http://xmlns.com/foaf/0.1/knows\",\n",+ " object=\"http://example.org/Charlie\"\n",+ " ),\n",+ " Triplet(\n",+ " subject=\"http://example.org/Charlie\",\n",+ " predicate=\"http://xmlns.com/foaf/0.1/knows\",\n",+ " object=\"http://example.org/David\"\n",+ " )\n",+ " ]\n",+ "\n",+ " # Bulk add\n",+ " store.add_triplets(triplets)\n",+ " print(\"Added bulk triplets successfully.\")\n",+ "\n",+ "except ProcessingError as e:\n",+ " print(f\"Operation skipped: {e}\")\n",+ "except Exception as e:\n",+ " print(f\"An error occurred: {e}\")"]},{@@ -142,8 +189,13 @@"LIMIT 10\n","\"\"\"\n","\n",- "results = store.execute_query(query)\n",- "print(\"Query Results:\", results)"+ "try:\n",+ " results = store.execute_query(query)\n",+ " print(\"Query Results:\", results)\n",+ "except ProcessingError as e:\n",+ " print(f\"Query skipped: {e}\")\n",+ "except Exception as e:\n",+ " print(f\"An error occurred: {e}\")"]},{diff --git a/cookbook/use_cases/healthcare/04_Healthcare_GraphRAG_Hybrid.ipynb b/cookbook/use_cases/healthcare/04_Healthcare_GraphRAG_Hybrid.ipynbindex 30844e99..34ee64f4 100644--- a/cookbook/use_cases/healthcare/04_Healthcare_GraphRAG_Hybrid.ipynb+++ b/cookbook/use_cases/healthcare/04_Healthcare_GraphRAG_Hybrid.ipynb@@ -64,7 +64,7 @@"\n","### Pipeline Overview\n","\n",- "**Medical Ontologies + Clinical Documents + EHRs (Virtual) \u2192 Parse \u2192 Extract Medical Entities \u2192 Build Materialized KG \u2192 Generate Embeddings \u2192 Vector Store \u2192 GraphRAG Setup \u2192 Query Orchestration \u2192 Generate Answers \u2192 Visualize & Export**\n",+ "**Medical Ontologies + Clinical Documents + EHRs (Virtual) → Parse → Extract Medical Entities → Build Materialized KG → Generate Embeddings → Vector Store → GraphRAG Setup → Query Orchestration → Generate Answers → Visualize & Export**\n","\n","---\n","\n",@@ -476,8 +476,8 @@"# Convert ontology to triplets and add to store\n","# In production, this would load the OWL ontology\n","sample_triplets = [\n",- " {\n",- " \"subject\": \"http://semantica.example.org/healthcare#Type2Diabetes\",\n",+ " {\n",+ " \"subject\": \"http://semantica.example.org/healthcare#Type2Diabetes\",\n"," \"predicate\": \"http://www.w3.org/2000/01/rdf-schema#subClassOf\",\n"," \"object\": \"http://semantica.example.org/healthcare#Diabetes\",\n"," \"confidence\": 1.0\n",@@ -828,4 +828,4 @@},"nbformat": 4,"nbformat_minor": 2-}\ No newline at end of file+}