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
Fix Phase 5 config and cleanup debug scripts
KaifAhmad15b14f1cc4a18
diff --git a/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb b/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynbindex 5cdc2db0..84212d5c 100644--- a/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb+++ b/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb@@ -4,8 +4,7 @@"cell_type": "markdown","metadata": {},"source": [- "# π§ͺ GraphRAG: Skincare Intelligence System (Powered by Groq)\n",- "\n",+ "# GraphRAG\n","## π Overview\n","\n","This notebook demonstrates the construction of a **highly detailed Knowledge Graph** for the Skincare and Dermatology domain. Unlike standard RAG, which treats documents as flat text, **GraphRAG** models the complex web of relationships between ingredients, skin types, conditions, and scientific mechanisms.\n",@@ -27,9 +26,25 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 1,"metadata": {},- "outputs": [],+ "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": ["!pip install -qU semantica networkx matplotlib plotly pandas faiss-cpu beautifulsoup4 groq"]@@ -45,9 +60,29 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 2,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "data": {+ "text/html": [+ "<div style='font-family: monospace;'><h4>π§ Semantica - π Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>π</td><td>Semantica is building</td><td>π§ kg</td><td>EntityResolver</td><td>-</td><td>10.76s</td></tr><tr><td>β </td><td>Semantica is deduplicating</td><td>π deduplication</td><td>DuplicateDetector</td><td>-</td><td>0.60s</td></tr><tr><td>β </td><td>Semantica is deduplicating</td><td>π deduplication</td><td>SimilarityCalculator</td><td>-</td><td>0.01s</td></tr><tr><td>β </td><td>Semantica is deduplicating</td><td>π deduplication</td><td>EntityMerger</td><td>-</td><td>0.05s</td></tr><tr><td>β </td><td>Semantica is deduplicating</td><td>π deduplication</td><td>MergeStrategyManager</td><td>-</td><td>0.01s</td></tr><tr><td>β </td><td>Semantica is resolving</td><td>β οΈ conflicts</td><td>ConflictDetector</td><td>-</td><td>0.00s</td></tr><tr><td>β </td><td>Semantica is building</td><td>π§ kg</td><td>CentralityCalculator</td><td>-</td><td>0.00s</td></tr><tr><td>β </td><td>Semantica is building</td><td>π§ kg</td><td>CommunityDetector</td><td>-</td><td>0.00s</td></tr><tr><td>β</td><td>Semantica is reasoning</td><td>π€ reasoning</td><td>GraphReasoner</td><td>-</td><td>1.09s</td></tr><tr><td>β </td><td>Semantica is visualizing</td><td>π visualization</td><td>KGVisualizer</td><td>-</td><td>0.11s</td></tr></table></div>"+ ],+ "text/plain": [+ "<IPython.core.display.HTML object>"+ ]+ },+ "metadata": {},+ "output_type": "display_data"+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "β Phase 0 Complete. Seeded 4 primary nodes with Groq backend.\n"+ ]+ }+ ],"source": ["import os\n","import json\n",@@ -107,9 +142,50 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 3,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Successfully ingested feed: https://makeupandbeautyblog.com/feed\n"+ ]+ },+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "Failed to fetch feed https://www.thebeautylookbook.com/feed: 403 Client Error: Forbidden for url: https://thebeautylookbook.com/feed\n",+ "Failed to ingest feed: Failed to fetch feed: 403 Client Error: Forbidden for url: https://thebeautylookbook.com/feed\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Feed Error https://www.thebeautylookbook.com/feed: Failed to fetch feed: 403 Client Error: Forbidden for url: https://thebeautylookbook.com/feed\n",+ "Successfully ingested feed: https://stylecaster.com/c/beauty/skin-care/feed/\n"+ ]+ },+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "Failed to fetch URL https://www.niams.nih.gov/health-topics/all-health-topics: 404 Client Error: Not Found for url: https://www.niams.nih.gov/health-topics/all-health-topics\n",+ "Failed to ingest web: Failed to fetch URL: 404 Client Error: Not Found for url: https://www.niams.nih.gov/health-topics/all-health-topics\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Web Error https://www.niams.nih.gov/health-topics/all-health-topics: Failed to fetch URL: 404 Client Error: Not Found for url: https://www.niams.nih.gov/health-topics/all-health-topics\n",+ "Successfully ingested web: https://dermnetnz.org/topics/emollients-and-moisturisers\n",+ "β Phase 1 Complete. Ingested 7 total web records.\n"+ ]+ }+ ],"source": ["from semantica.ingest import ingest_web, ingest_feed\n","\n",@@ -156,9 +232,17 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 4,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "β Local expert document ingested successfully.\n"+ ]+ }+ ],"source": ["from semantica.ingest import ingest_file\n","\n",@@ -192,9 +276,25 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 5,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "c:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\sentence_transformers\\cross_encoder\\CrossEncoder.py:13: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",+ " from tqdm.autonotebook import tqdm, trange\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "β Phase 2 Complete. Generated 16 semantic chunks.\n"+ ]+ }+ ],"source": ["from semantica.normalize import TextNormalizer, DataCleaner\n","from semantica.split import EntityAwareChunker\n",@@ -231,9 +331,18 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 6,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Extracting nodes and edges using Groq (Llama 3.1 8B)...\n",+ "β Phase 3 Complete. Extracted 11 entities using Groq.\n"+ ]+ }+ ],"source": ["from semantica.semantic_extract import NERExtractor, RelationExtractor\n","\n",@@ -257,7 +366,7 @@" \n"," # Extract Relations based on detected entities\n"," relations = rel_ext.extract(txt, entities=entities)\n",- " combined_results[\"relationships\"].extend([{\"source\": r.subject.text, \"target\": r.object.text, \"type\": r.predicate} for r in relations])\n",+ " combined_results[\"relationships\"].extend([{\"source\": r.subject, \"target\": r.object, \"type\": r.predicate} for r in relations])\n","\n","print(f\"β Phase 3 Complete. Extracted {len(combined_results['entities'])} entities using Groq.\")"]@@ -273,9 +382,17 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 7,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "β Phase 4 Complete. Graph Integrity: Issues Addressed\n"+ ]+ }+ ],"source": ["from semantica.kg import GraphBuilder, GraphValidator\n","from semantica.deduplication import DuplicateDetector, EntityMerger\n",@@ -314,9 +431,26 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 8,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "Reasoning failed: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************bt8A. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'code': 'invalid_api_key', 'param': None}, 'status': 401}\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "β Phase 5 Complete.\n",+ "Top Ingredients: ['Makeup and Beauty Blog | Makeup Reviews, Swatches and How-To Makeup', 'Makeup and Beauty Blog']\n",+ "Reasoning Output: Error during reasoning: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************bt8A. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'code': 'invalid_api_key', 'param': None}, 'status': 401}\n"+ ]+ }+ ],"source": ["from semantica.kg import CentralityCalculator, CommunityDetector\n","from semantica.reasoning import GraphReasoner\n",@@ -345,30 +479,6 @@"print(f\"Top Ingredients: {[r['node'] for r in rankings]}\")\n","print(f\"Reasoning Output: {answer}\")"]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "## π¦ Phase 6: Orchestration & Export\n",- "\n",- "Serializing our intelligence for production."- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "from semantica.export import GraphExporter\n",- "\n",- "# 1. Exporting the structured knowledge\n",- "exporter = GraphExporter()\n",- "exporter.export_to_json(kg, \"skincare_intelligence_graph.json\")\n",- "\n",- "print(\"π Mission Complete: Skincare Intelligence Graph is ready for deployment.\")"- ]}],"metadata": {diff --git a/fix_notebook.py b/fix_notebook.pynew file mode 100644index 00000000..b14a97bd--- /dev/null+++ b/fix_notebook.py@@ -0,0 +1,28 @@+import nbformat++def update_phase_5(notebook_path):+ with open(notebook_path, 'r', encoding='utf-8') as f:+ nb = nbformat.read(f, as_version=4)++ updated = False+ for cell in nb.cells:+ if cell.cell_type == 'code' and 'GraphReasoner' in cell.source:+ # Update instantiation to be explicit+ if 'GraphReasoner(core=core)' in cell.source:+ cell.source = cell.source.replace(+ 'GraphReasoner(core=core)',+ 'GraphReasoner(core=core, provider="groq", model="llama-3.1-8b-instant")'+ )+ updated = True+ print(f"Updated GraphReasoner instantiation in cell.")++ if updated:+ with open(notebook_path, 'w', encoding='utf-8') as f:+ nbformat.write(nb, f)+ print(f"Successfully updated notebook: {notebook_path}")+ else:+ print("No GraphReasoner instantiation found to update.")++if __name__ == "__main__":+ notebook_path = r"c:\Users\Mohd Kaif\semantica\cookbook\use_cases\advanced_rag\01_GraphRAG_Complete.ipynb"+ update_phase_5(notebook_path)