{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bible Text Batch Processing with KG Engine\n",
    "\n",
    "This notebook demonstrates batch processing of the Bible text file using KG Engine v2 with Ollama."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup and Configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "✅ Environment loaded\n",
      "   Ollama Model: phi3:3.8b\n",
      "   Ollama URL: http://localhost:11434/v1\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import sys\n",
    "from pathlib import Path\n",
    "import time\n",
    "import logging\n",
    "\n",
    "logging.getLogger().setLevel(logging.INFO)\n",
    "logging.getLogger('openai').setLevel(logging.WARNING)\n",
    "# Add src to Python path\n",
    "src_path = Path('../src').resolve()\n",
    "if str(src_path) not in sys.path:\n",
    "    sys.path.insert(0, str(src_path))\n",
    "\n",
    "# Load environment variables\n",
    "from dotenv import load_dotenv\n",
    "load_dotenv('../.env.notebook')\n",
    "\n",
    "# Disable tokenizer parallelism warning\n",
    "os.environ[\"TOKENIZERS_PARALLELISM\"] = \"false\"\n",
    "\n",
    "print(f\"✅ Environment loaded\")\n",
    "print(f\"   Ollama Model: {os.getenv('OLLAMA_MODEL')}\")\n",
    "print(f\"   Ollama URL: {os.getenv('OLLAMA_BASE_URL')}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Import KG Engine Components"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "✅ KG Engine components imported\n"
     ]
    }
   ],
   "source": [
    "from kg_engine import (\n",
    "    KnowledgeGraphEngineV2,\n",
    "    InputItem,\n",
    "    Neo4jConfig,\n",
    "    LLMClientFactory\n",
    ")\n",
    "\n",
    "print(\"✅ KG Engine components imported\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Initialize Engine with Ollama"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:root:Neo4j connectivity verified bolt://localhost:7687, neo4j, neo4j\n",
      "INFO:sentence_transformers.SentenceTransformer:Use pytorch device_name: mps\n",
      "INFO:sentence_transformers.SentenceTransformer:Load pretrained SentenceTransformer: all-MiniLM-L6-v2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "✅ Neo4j connected\n",
      "✅ LLM Config: litellm - gpt-4o\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:sentence_transformers.cross_encoder.CrossEncoder:Use pytorch device: mps\n",
      "INFO:kg_engine.utils.neo4j_index_manager:Vector index triplet_embedding_index already exists, skipping creation\n",
      "INFO:kg_engine.models.classifier_map:Loaded classifier map with 8 categories\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "dbcfe7a560164270a1438b49f9e29cb2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e612ccfc2801484aa424da36ee586e89",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "dce648c30af5428a801ac53b8f2b8539",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2bac978f78d24c30aa7f1b23c5731e3e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2df03a8bd1a34edabb68a1c1f1d378ba",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "69841efa2753407fb654c8b78bcebb86",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a8c565e8c6724784b8cbcc12f30bff51",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8e9f99331a8446959dda524469ee1048",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "80831e21dfd643b2b1c2a3e8d59c6f3c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7810bb2d41e34e308e3916c13f90a780",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "52b74498bee44627936941b77c64004b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9b091e9dcb9d424fb47f2d2b4a28d7e4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ed9270a6e4db4bc78adb5d92666cfa0d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "47b554cfc619485b8f3b562671fcd02a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "aa6326b963654085b2e90411d99c352d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e76905631357463aa9d05e63b2305a96",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9e5b166faf27484692e1df0441442f75",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2b3c9071015a43dd9abf9df51d6bea41",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "dee91727d038464c82e3803bdd0d475c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1edce71f216240ccb91d557c44a175ca",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d940598e9b054614bc4ba774bda133a1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cac9a32ae816464ab5cc3345d44453d6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "24950b3215094a3fa0fc4d1e42efd1d8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e8620074ba77463b90e890e5301461f6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "🤖 LLM Interface initialized: gpt-4o via litellm\n",
      "🚀 Knowledge Graph Engine v2\n",
      "   - LLM interface: gpt-4o via litellm\n",
      "\n",
      "🚀 KG Engine initialized and ready!\n"
     ]
    }
   ],
   "source": [
    "# Create Neo4j configuration\n",
    "neo4j_config = Neo4jConfig()\n",
    "\n",
    "# Verify Neo4j connectivity\n",
    "if neo4j_config.verify_connectivity():\n",
    "    print(\"✅ Neo4j connected\")\n",
    "else:\n",
    "    print(\"❌ Neo4j connection failed\")\n",
    "    raise ConnectionError(\"Cannot connect to Neo4j\")\n",
    "\n",
    "# Create LLM configuration from environment\n",
    "llm_config = LLMClientFactory.create_from_env()\n",
    "print(f\"✅ LLM Config: {llm_config.provider} - {llm_config.get_model_name()}\")\n",
    "\n",
    "# Initialize the engine\n",
    "engine = KnowledgeGraphEngineV2(\n",
    "    llm_config=llm_config,\n",
    "    neo4j_config=neo4j_config\n",
    ")\n",
    "\n",
    "print(\"\\n🚀 KG Engine initialized and ready!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load and Prepare Bible Text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "📖 Loaded Bible text\n",
      "   Total verses: 37026\n",
      "   First verse: 1:1 In the beginning God created the heaven and the earth.\n",
      "   Last verse: http://www.gutenberg.org\n"
     ]
    }
   ],
   "source": [
    "# Path to Bible text file\n",
    "bible_path = Path('../examples/sample_documents/bible.txt')\n",
    "\n",
    "# Read the Bible text\n",
    "with open(bible_path, 'r', encoding='utf-8') as f:\n",
    "    bible_text = f.read()\n",
    "\n",
    "# Split into verses (assuming each verse is on a new line)\n",
    "verses = [line.strip() for line in bible_text.split('\\n') if line.strip() and ':' in line]\n",
    "\n",
    "print(f\"📖 Loaded Bible text\")\n",
    "print(f\"   Total verses: {len(verses)}\")\n",
    "print(f\"   First verse: {verses[0] if verses else 'None'}\")\n",
    "print(f\"   Last verse: {verses[-1] if verses else 'None'}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Define Batch Processing Parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "⚙️ Batch Processing Configuration:\n",
      "   Batch size: 5 verses\n",
      "   Batches to process: 50\n",
      "   Total verses to process: 250\n",
      "   Delay between batches: 1s\n"
     ]
    }
   ],
   "source": [
    "# Batch processing parameters\n",
    "BATCH_SIZE = 5  # Number of verses per batch\n",
    "NUM_BATCHES = 50  # Number of batches to process (set None for all)\n",
    "DELAY_BETWEEN_BATCHES = 1  # Seconds to wait between batches\n",
    "\n",
    "# Calculate total batches\n",
    "total_possible_batches = len(verses) // BATCH_SIZE\n",
    "batches_to_process = min(NUM_BATCHES or total_possible_batches, total_possible_batches)\n",
    "\n",
    "print(f\"⚙️ Batch Processing Configuration:\")\n",
    "print(f\"   Batch size: {BATCH_SIZE} verses\")\n",
    "print(f\"   Batches to process: {batches_to_process}\")\n",
    "print(f\"   Total verses to process: {batches_to_process * BATCH_SIZE}\")\n",
    "print(f\"   Delay between batches: {DELAY_BETWEEN_BATCHES}s\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Process Batches"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "🔄 Starting batch processing...\n",
      "\n",
      "📦 Batch 1/50\n",
      "   Verses 1-5\n",
      "   First verse: 1:1 In the beginning God created the heaven and th...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "74ff669c96404126b55db595c626509f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1b08a25434654677a68e8441d49fb97d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: CREATED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "683811041ddb4040ac222c81d485d1a4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "49482dfbb5d448468f69691ee230bf05",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: CREATED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f2ab6336d94d4d04b8c091c1e18ba131",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> heaven\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d074da86bf074ad09456af9d0aea3427",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> earth\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c4c06ad91e4f437b9b88f6b8eed85063",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "37e21f2e051e4d1cb6409e8a251ea9b1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SAID' -> 'said' in category 'communication' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SAID -> SAID\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "77df311eb45d48c5933d22bdfd4453dd",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4daaf3e4341e4b898c497a847c08e240",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'APPEARS' -> 'appears' in category 'status' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: EXISTS -> APPEARS\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b2868681931f4597ad502d77e14065dc",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SAID-> light\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4013e01d1ea545e7baf4e045a4bc01ff",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: light -APPEARS-> light\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3758e90cdcf944ec9cb63c6631e47619",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "12761e6c417b47128d93246e2715f067",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SAW -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d795631b6f184255b780b35ed127aef3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "80bb1be3962942c3ada051187d6608b2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'APPEARS' -> 'appears' in category 'status' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: HAS_STATUS -> APPEARS\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f0984b91961e411b812dced2583ab1f5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0e98bb80664647b1b97c940fd7638cb3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: DIVIDED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "07cf8e6335464c1caa50304c697a0e3f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> light\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1bab21931ea8426baca9d9286115be36",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: light -APPEARS-> good\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a2bfa2ae37e54a59a99b92acde15ccf7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0dc802bc517f4760bf3f28232e68f06d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: CALLED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "bac7a683ccfa40fab6aec6e3c6d68f31",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "17c3e7640da44743b8c5a31fc307c209",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: CALLED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3d533372e79148acbfc91758d346aceb",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> Day\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5adc841b870149d9aa2736cf4747335f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> Night\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   ✅ Processed in 14350.3ms\n",
      "   New edges: 8\n",
      "   Errors: 0\n",
      "\n",
      "📦 Batch 2/50\n",
      "   Verses 6-10\n",
      "   First verse: 1:6 And God said, Let there be a firmament in the ...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a4ccb8ab58094f8a941cd7d2d5e5556f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "252c24da952b40bfbc7244022c3b8af3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SAID' -> 'said' in category 'communication' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SAID -> SAID\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f5bef24042814652b814903900428f17",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SAID-> firmament\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e2db878b5c6c44c58cda42d7991b9ce2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5b4d0a0ba6d544ef9a7a6bc0ae801b13",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'CREATED_THE' -> 'created the' in category 'creation' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: MADE -> CREATED_THE\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9d8e313604e14ff88a76113ca9d1747d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7fd999fda7c149f7810314f9d319f4cc",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'MADE_AND_DIVIDED' -> 'made and divided' in category 'creation' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: DIVIDED -> MADE_AND_DIVIDED\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "da287162076c4a588885e41d47220bdb",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -CREATED_THE-> firmament\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4aa291cbd44b411bb6265dcb26c84d3a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -MADE_AND_DIVIDED-> waters\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8d024a8e11dd499a9b069a61de1de32e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d2e110095b3e44f19c5c744d293a7a31",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: CALLED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "710a32bb8c74426caab7cea072a44036",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> Heaven\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c1f42b075c414894a77748ec0d2e3752",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a279a31170344e99ab8a85de30a356e3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SAID' -> 'said' in category 'communication' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SAID -> SAID\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "be95ce5207ed48fab65d03ffc4aa4fe8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SAID-> waters\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   ✅ Processed in 10505.5ms\n",
      "   New edges: 5\n",
      "   Errors: 0\n",
      "\n",
      "📦 Batch 3/50\n",
      "   Verses 11-15\n",
      "   First verse: unto one place, and let the dry land appear: and i...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "acdd8d8572374df3a55d4f88665eff1e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f7d800c32ad54ddaa3ad9a7e96504d5f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: CALLED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "784d4a814c294173ab453f142e35441a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> Earth\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b68fa012ce184b2e8a27531ae06cd102",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "299ffea2d2a54e539245d576f51d0c04",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'APPEARS' -> 'appears' in category 'status' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SAW -> APPEARS\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0e48b494101045a2b24d0e44b85efa78",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -APPEARS-> good\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "469a730828804e548e0efbc5b9712a9d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3480188b6f8a4bc9bf96964871de59d3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SAID' -> 'said' in category 'communication' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SAID -> SAID\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e8ceb952199c4824865bb3c5f4359eec",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SAID-> earth\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   ✅ Processed in 9208.3ms\n",
      "   New edges: 3\n",
      "   Errors: 0\n",
      "\n",
      "📦 Batch 4/50\n",
      "   Verses 16-20\n",
      "   First verse: 1:12 And the earth brought forth grass, and herb y...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e72496bc19f24af085fa416307018661",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a84d2b0dd3bb41d6b7383661f3c23c7b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SAID' -> 'said' in category 'communication' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SAID -> SAID\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "461e5ae2de634427aab85eb9939f04ef",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SAID-> lights in the firmament of the heaven\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   ✅ Processed in 5979.4ms\n",
      "   New edges: 1\n",
      "   Errors: 0\n",
      "\n",
      "📦 Batch 5/50\n",
      "   Verses 21-25\n",
      "   First verse: the firmament of the heaven to give light upon the...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1ab4e1ed64fe4a9f9064f71e8ea5919e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "630f4ccb84a0487aaa26e05c4d514038",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: MADE -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ae019bc26900495492bfdc313c784c25",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9d6a6e8d60fa4b2b9e7dfa16c6cacc3a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'APPEARS' -> 'appears' in category 'status' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: RULES -> APPEARS\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c500e0348bba4f989b6fb0f0c2649a55",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> two great lights\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1ada0afb398e4bf887eae3d06503fe7c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: greater light -APPEARS-> day\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "08f9605e2b27410d92b3f1325699d480",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "43a69af0bffa4e4c959007deadadacb5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SET_IN -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "237ffa9b4f504c10a2fa2a10542a2d48",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a8ad1c7fc97a43a1b40e67e794996873",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: PURPOSE -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "dc9dc4be85db4f23878ae4cedc89a1c1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> firmament\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6fd4b5dda0604eb38636c785e1f8c5ff",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: them -SURVIVES_TOGETHER-> give light\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   ✅ Processed in 9375.7ms\n",
      "   New edges: 4\n",
      "   Errors: 0\n",
      "\n",
      "📦 Batch 6/50\n",
      "   Verses 26-30\n",
      "   First verse: to divide the light from the darkness: and God saw...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "030dd3d33e3445e5bb97a17602a44f29",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a30e206cc6e4425ab9fb1f884f989fb8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: DIVIDES -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c1cfe59368a64c32a041276505cf93f7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "19a0bb224e85475faff51ca899b19bb7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: DIVIDES -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a6cd7b10b27d4a82adc7802f6f2ac85b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fdf2e21e400343d9a02c5a136715b509",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'APPEARS' -> 'appears' in category 'status' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SEES_AS_GOOD -> APPEARS\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e0a386417fb64aa68595bc5c692f7a83",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> darkness\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8a7269ff4ea2404494fd96037a74d35a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -APPEARS-> it\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d807bcfcd2c441709d82a52a47fed79a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "14bfceb951ca45feab1db60799f3d02a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: CREATED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b458ed182e4d4d84bb87ef87f3cdecd7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "59aa548b07a543fd98e67ec77aeb2272",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: CREATED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c52a09f6e18642d3ba8745e9b06ace5e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> whale\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "207f377bd24a461b8a7f401831d6cd50",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> living creature\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   ✅ Processed in 11247.0ms\n",
      "   New edges: 4\n",
      "   Errors: 0\n",
      "\n",
      "📦 Batch 7/50\n",
      "   Verses 31-35\n",
      "   First verse: 1:22 And God blessed them, saying, Be fruitful, an...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: BLESSED -> BLESSED\n",
      "WARNING:neo4j.notifications:Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning} {category: UNRECOGNIZED} {title: The provided relationship type is not in the database.} {description: One of the relationship types in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing relationship type is: BLESSED)} {position: line: 3, column: 51, offset: 85} for query: '\\n                    MATCH (s:Entity {name: $subject})\\n                          -[r:`BLESSED`]->\\n                          (o:Entity {name: $object})\\n                    WHERE r.obsolete = false\\n                    RETURN s, r, o, type(r) as rel_type\\n                '\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9c3310380e184e0ab8a836c97fac5ca3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -BLESSED-> them\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "91dbaf8ce4fb4ac28f38973ca6a07ca4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6f648ca66db74a30afcfd2a91db02674",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'CREATED_THE' -> 'created the' in category 'creation' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: MADE -> CREATED_THE\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "601d2dad127947539ae5139212a4af47",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1cbf7a38fdf640c08adb7a5c2b7d76c2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'CREATED_THE' -> 'created the' in category 'creation' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: MADE -> CREATED_THE\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "936ebbf489094bff8f77bcf8000f11c1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -CREATED_THE-> beast\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e9ee88f9234b4b1290693fcf09cb7294",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -CREATED_THE-> cattle\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   ✅ Processed in 6820.6ms\n",
      "   New edges: 3\n",
      "   Errors: 0\n",
      "\n",
      "📦 Batch 8/50\n",
      "   Verses 36-40\n",
      "   First verse: his kind: and God saw that it was good....\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0a4cdfb8c010423d8b74316384787c6c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8432b8fc3fd84330b3f29b3256aceaec",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SAID' -> 'said' in category 'communication' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SAID -> SAID\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8998ddf986d54bb680e0def1689b336a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SAID-> Let us make man in our image, after our likeness\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5063fdd09f0649e7914b148d96031278",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e0a705b465f547d6951fc5f81f673be5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_TOGETHER' -> 'survives together' in category 'activity' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: CREATED -> SURVIVES_TOGETHER\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2a0a57c4be6d429aade564fea962aabc",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SURVIVES_TOGETHER-> man\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: BLESSED -> BLESSED\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2e6a4293e73849b79c52109e854d6725",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3edcba595dd442c2b5a3e4f28bd7fe2f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SAID' -> 'said' in category 'communication' with embedding cache\n",
      "INFO:kg_engine.utils.graph_standardizer:Standardized: SAID_UNTO -> SAID\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "563dab842c0c4e62b0b3bce6d36cc677",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Added edge: God -SAID-> them\n",
      "INFO:httpx:HTTP Request: POST https://litellm.chatcyber.ai/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   ✅ Processed in 9449.7ms\n",
      "   New edges: 3\n",
      "   Errors: 0\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mKeyboardInterrupt\u001b[39m                         Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 75\u001b[39m\n\u001b[32m     73\u001b[39m     \u001b[38;5;66;03m# Delay between batches (except for the last one)\u001b[39;00m\n\u001b[32m     74\u001b[39m     \u001b[38;5;28;01mif\u001b[39;00m batch_num < batches_to_process - \u001b[32m1\u001b[39m:\n\u001b[32m---> \u001b[39m\u001b[32m75\u001b[39m         \u001b[43mtime\u001b[49m\u001b[43m.\u001b[49m\u001b[43msleep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mDELAY_BETWEEN_BATCHES\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m     77\u001b[39m     \u001b[38;5;28mprint\u001b[39m()  \u001b[38;5;66;03m# Empty line between batches\u001b[39;00m\n\u001b[32m     79\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33m✅ Batch processing complete!\u001b[39m\u001b[33m\"\u001b[39m)\n",
      "\u001b[31mKeyboardInterrupt\u001b[39m: "
     ]
    }
   ],
   "source": [
    "# Initialize tracking variables\n",
    "total_stats = {\n",
    "    \"processed_items\": 0,\n",
    "    \"new_edges\": 0,\n",
    "    \"updated_edges\": 0,\n",
    "    \"obsoleted_edges\": 0,\n",
    "    \"duplicates_ignored\": 0,\n",
    "    \"errors\": [],\n",
    "    \"processing_time_ms\": 0\n",
    "}\n",
    "\n",
    "batch_results = []\n",
    "\n",
    "print(\"🔄 Starting batch processing...\\n\")\n",
    "\n",
    "# Process batches\n",
    "for batch_num in range(batches_to_process):\n",
    "    start_idx = batch_num * BATCH_SIZE\n",
    "    end_idx = start_idx + BATCH_SIZE\n",
    "    \n",
    "    # Get verses for this batch\n",
    "    batch_verses = verses[start_idx:end_idx]\n",
    "    \n",
    "    # Create InputItems\n",
    "    input_items = [\n",
    "        InputItem(\n",
    "            description=verse,\n",
    "            metadata={\n",
    "                \"source\": \"bible\",\n",
    "                \"batch_number\": batch_num + 1,\n",
    "                \"verse_index\": start_idx + i\n",
    "            }\n",
    "        )\n",
    "        for i, verse in enumerate(batch_verses)\n",
    "    ]\n",
    "    \n",
    "    print(f\"📦 Batch {batch_num + 1}/{batches_to_process}\")\n",
    "    print(f\"   Verses {start_idx + 1}-{end_idx}\")\n",
    "    print(f\"   First verse: {batch_verses[0][:50]}...\")\n",
    "    \n",
    "    # Process the batch\n",
    "    try:\n",
    "        batch_start_time = time.time()\n",
    "        results = engine.process_input(input_items)\n",
    "        batch_time = (time.time() - batch_start_time) * 1000\n",
    "        \n",
    "        # Store batch results\n",
    "        batch_results.append({\n",
    "            \"batch_number\": batch_num + 1,\n",
    "            \"results\": results,\n",
    "            \"processing_time_ms\": batch_time\n",
    "        })\n",
    "        \n",
    "        # Update totals\n",
    "        total_stats[\"processed_items\"] += results.get(\"processed_items\", 0)\n",
    "        total_stats[\"new_edges\"] += results.get(\"new_edges\", 0)\n",
    "        total_stats[\"updated_edges\"] += results.get(\"updated_edges\", 0)\n",
    "        total_stats[\"obsoleted_edges\"] += results.get(\"obsoleted_edges\", 0)\n",
    "        total_stats[\"duplicates_ignored\"] += results.get(\"duplicates_ignored\", 0)\n",
    "        total_stats[\"processing_time_ms\"] += batch_time\n",
    "        \n",
    "        if results.get(\"errors\"):\n",
    "            total_stats[\"errors\"].extend(results[\"errors\"])\n",
    "        \n",
    "        print(f\"   ✅ Processed in {batch_time:.1f}ms\")\n",
    "        print(f\"   New edges: {results.get('new_edges', 0)}\")\n",
    "        print(f\"   Errors: {len(results.get('errors', []))}\")\n",
    "        \n",
    "    except Exception as e:\n",
    "        print(f\"   ❌ Error: {e}\")\n",
    "        total_stats[\"errors\"].append(f\"Batch {batch_num + 1}: {str(e)}\")\n",
    "    \n",
    "    # Delay between batches (except for the last one)\n",
    "    if batch_num < batches_to_process - 1:\n",
    "        time.sleep(DELAY_BETWEEN_BATCHES)\n",
    "    \n",
    "    print()  # Empty line between batches\n",
    "\n",
    "print(\"✅ Batch processing complete!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Processing Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "📊 Final Processing Statistics:\n",
      "   Total batches processed: 20\n",
      "   Total items processed: 100\n",
      "   Total new edges: 111\n",
      "   Total updated edges: 0\n",
      "   Total obsoleted edges: 0\n",
      "   Total duplicates ignored: 16\n",
      "   Total errors: 6\n",
      "   Total processing time: 319631.7ms\n",
      "   Average time per batch: 15981.6ms\n",
      "\n",
      "⚠️ Sample errors (first 5):\n",
      "   1. No existing relationship found to obsolete: The LORD God had not allowed any herb to grow in the field prior.\n",
      "   2. No existing relationship found to obsolete: You may not eat from the tree of the knowledge.\n",
      "   3. No existing relationship found to obsolete: Reader shall not eat of the forbidden item.\n",
      "   4. No existing relationship found to obsolete: Should not eat from all trees in the garden.\n",
      "   5. No existing relationship found to obsolete: The serpent said to the woman, 'You shall not surely die.'\n"
     ]
    }
   ],
   "source": [
    "print(\"📊 Final Processing Statistics:\")\n",
    "print(f\"   Total batches processed: {len(batch_results)}\")\n",
    "print(f\"   Total items processed: {total_stats['processed_items']}\")\n",
    "print(f\"   Total new edges: {total_stats['new_edges']}\")\n",
    "print(f\"   Total updated edges: {total_stats['updated_edges']}\")\n",
    "print(f\"   Total obsoleted edges: {total_stats['obsoleted_edges']}\")\n",
    "print(f\"   Total duplicates ignored: {total_stats['duplicates_ignored']}\")\n",
    "print(f\"   Total errors: {len(total_stats['errors'])}\")\n",
    "print(f\"   Total processing time: {total_stats['processing_time_ms']:.1f}ms\")\n",
    "print(f\"   Average time per batch: {total_stats['processing_time_ms'] / len(batch_results):.1f}ms\")\n",
    "\n",
    "# Show sample errors if any\n",
    "if total_stats['errors']:\n",
    "    print(\"\\n⚠️ Sample errors (first 5):\")\n",
    "    for i, error in enumerate(total_stats['errors'][:5]):\n",
    "        print(f\"   {i+1}. {error}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## View Graph Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "📈 Current Graph Statistics:\n",
      "   Total entities: 154\n",
      "   Active edges: 140\n",
      "   Total edges: 140\n",
      "   Relationship types: 17\n",
      "\n",
      "📋 Sample relationship types (first 10):\n",
      "   - RELATES_TO\n",
      "   - CREATED_THE\n",
      "   - WAS_STATE\n",
      "   - SAID_TO_CREATE\n",
      "   - SURVIVES_TOGETHER\n",
      "   - CALLED_LITERALLY\n",
      "   - SAID\n",
      "   - MADE_AND_DIVIDED\n",
      "   - UNDER\n",
      "   - IS_CALLED\n"
     ]
    }
   ],
   "source": [
    "# Get current graph statistics\n",
    "stats = engine.get_stats()\n",
    "\n",
    "print(\"📈 Current Graph Statistics:\")\n",
    "print(f\"   Total entities: {stats.get('entities', 0)}\")\n",
    "print(f\"   Active edges: {stats.get('graph_stats', {}).get('active_edges', 0)}\")\n",
    "print(f\"   Total edges: {stats.get('graph_stats', {}).get('total_edges', 0)}\")\n",
    "print(f\"   Relationship types: {stats.get('graph_stats', {}).get('relationship_types', 0)}\")\n",
    "\n",
    "# Show sample relationships\n",
    "relationships = stats.get('relationships', [])\n",
    "if relationships:\n",
    "    print(f\"\\n📋 Sample relationship types (first 10):\")\n",
    "    for rel in relationships[:10]:\n",
    "        print(f\"   - {rel}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Queries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "🔍 Testing queries on processed data:\n",
      "\n",
      "Q: Who created the heaven and earth?\n",
      "Search type: SearchType.BOTH Who created the heaven and earth?\n",
      "Parsing query DIRECT with LLM intuition...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST http://localhost:11434/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Parsed query: ParsedQuery(entities=['Heaven and Earth'], relationships=['CREATED'], search_type=<SearchType.DIRECT: 'direct'>, query_intent='search', temporal_context=None)\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "181b471a6fb84e8bbc318e8c5df7a627",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e5dfc78b79bb427eae6f18e8ddd5277d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "bf5c5b3bfee844b583a06e4691af9595",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2572495e6c024e88abb664bca59742e4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'CREATED_THE' -> 'created the' in category 'creation' with embedding cache\n",
      "INFO:kg_engine.core.engine:Standardized 'CREATED' -> 'CREATED_THE' (category: creation)\n",
      "WARNING:neo4j.notifications:Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning} {category: UNRECOGNIZED} {title: The provided relationship type is not in the database.} {description: One of the relationship types in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing relationship type is: CREATED)} {position: line: 3, column: 50, offset: 92} for query: '\\n                MATCH (start:Entity {name: $entity_name})\\n                MATCH (start)-[r:CREATED|CREATED_THE]-(connected:Entity)\\n                WHERE r.obsolete = false\\n                RETURN start, r, connected, \\n                       r.confidence as confidence,\\n                       type(r) as relationship_type\\n                ORDER BY r.confidence DESC\\n                LIMIT $limit\\n                '\n",
      "INFO:kg_engine.storage.graph_db:Entity exploration returned 0 results for Heaven and Earth\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Standardized relationships: ['CREATED_THE']\n",
      "Searching with entities: ['Heaven and Earth'] and relationships: ['CREATED', 'CREATED_THE']\n",
      "Parsing query SEMANTIC...\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b7428b1431c5402890bfeaa10da67913",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Vector similarity search returned 10 results\n",
      "INFO:httpx:HTTP Request: POST http://localhost:11434/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A: In the beginning, God created heaven and earth. This concept comes from religious texts such as Genesis in the Bible. It is important to note that interpretations may vary among different beliefs.\n",
      "   (Found 10 results in 3200.0ms)\n",
      "\n",
      "Q: What did God create on the first day?\n",
      "Search type: SearchType.BOTH What did God create on the first day?\n",
      "Parsing query DIRECT with LLM intuition...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST http://localhost:11434/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Parsed query: ParsedQuery(entities=['God', 'first day'], relationships=['CREATED', 'FIRST_DAY'], search_type=<SearchType.DIRECT: 'direct'>, query_intent='search', temporal_context=None)\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2ab99109fbd64df39e220dedef6e88fc",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ad1a1642e69b4c78a1b11842acb89c13",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d32624f9496940af944cad15c959c1be",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "db049fe05b4e45c9907a8b0960a98bf2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'CREATED_THE' -> 'created the' in category 'creation' with embedding cache\n",
      "INFO:kg_engine.core.engine:Standardized 'CREATED' -> 'CREATED_THE' (category: creation)\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4696739d6e004d2487a13ea7d1c9c99b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3b5c05b681f44ee0a43805f51be7bb85",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d44f82081dfd46c885c9c198e001ec28",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "50645c68aaad42e0950ffb90a96cc7de",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'IS_ON' -> 'is on' in category 'location' with embedding cache\n",
      "INFO:kg_engine.core.engine:Standardized 'FIRST_DAY' -> 'IS_ON' (category: location)\n",
      "WARNING:neo4j.notifications:Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning} {category: UNRECOGNIZED} {title: The provided relationship type is not in the database.} {description: One of the relationship types in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing relationship type is: CREATED)} {position: line: 3, column: 50, offset: 92} for query: '\\n                MATCH (start:Entity {name: $entity_name})\\n                MATCH (start)-[r:CREATED|FIRST_DAY|CREATED_THE|IS_ON]-(connected:Entity)\\n                WHERE r.obsolete = false\\n                RETURN start, r, connected, \\n                       r.confidence as confidence,\\n                       type(r) as relationship_type\\n                ORDER BY r.confidence DESC\\n                LIMIT $limit\\n                '\n",
      "WARNING:neo4j.notifications:Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning} {category: UNRECOGNIZED} {title: The provided relationship type is not in the database.} {description: One of the relationship types in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing relationship type is: FIRST_DAY)} {position: line: 3, column: 58, offset: 100} for query: '\\n                MATCH (start:Entity {name: $entity_name})\\n                MATCH (start)-[r:CREATED|FIRST_DAY|CREATED_THE|IS_ON]-(connected:Entity)\\n                WHERE r.obsolete = false\\n                RETURN start, r, connected, \\n                       r.confidence as confidence,\\n                       type(r) as relationship_type\\n                ORDER BY r.confidence DESC\\n                LIMIT $limit\\n                '\n",
      "INFO:kg_engine.storage.graph_db:Entity exploration returned 10 results for God\n",
      "WARNING:neo4j.notifications:Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning} {category: UNRECOGNIZED} {title: The provided relationship type is not in the database.} {description: One of the relationship types in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing relationship type is: CREATED)} {position: line: 3, column: 50, offset: 92} for query: '\\n                MATCH (start:Entity {name: $entity_name})\\n                MATCH (start)-[r:CREATED|FIRST_DAY|CREATED_THE|IS_ON]-(connected:Entity)\\n                WHERE r.obsolete = false\\n                RETURN start, r, connected, \\n                       r.confidence as confidence,\\n                       type(r) as relationship_type\\n                ORDER BY r.confidence DESC\\n                LIMIT $limit\\n                '\n",
      "WARNING:neo4j.notifications:Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning} {category: UNRECOGNIZED} {title: The provided relationship type is not in the database.} {description: One of the relationship types in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing relationship type is: FIRST_DAY)} {position: line: 3, column: 58, offset: 100} for query: '\\n                MATCH (start:Entity {name: $entity_name})\\n                MATCH (start)-[r:CREATED|FIRST_DAY|CREATED_THE|IS_ON]-(connected:Entity)\\n                WHERE r.obsolete = false\\n                RETURN start, r, connected, \\n                       r.confidence as confidence,\\n                       type(r) as relationship_type\\n                ORDER BY r.confidence DESC\\n                LIMIT $limit\\n                '\n",
      "INFO:kg_engine.storage.graph_db:Entity exploration returned 0 results for first day\n",
      "INFO:kg_engine.storage.graph_db:Found 0 paths from God to first day\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Standardized relationships: ['CREATED_THE', 'IS_ON']\n",
      "Searching with entities: ['God', 'first day'] and relationships: ['CREATED', 'FIRST_DAY', 'CREATED_THE', 'IS_ON']\n",
      "Parsing query SEMANTIC...\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "767b90955e0647a191fbdea49e82ea0d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Vector similarity search returned 10 results\n",
      "INFO:httpx:HTTP Request: POST http://localhost:11434/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A: On the first day of creation, God made light and separated it from darkness. He then created the sky as a dome above this new space where life could exist under his guidance. The rest was seen as good by Him. This includes land animals like cattle that were also part of His creations on Earth.\n",
      "   (Found 10 results in 4454.0ms)\n",
      "\n",
      "Q: What is the firmament?\n",
      "Search type: SearchType.BOTH What is the firmament?\n",
      "Parsing query DIRECT with LLM intuition...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST http://localhost:11434/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Parsed query: ParsedQuery(entities=['firmament'], relationships=['DEFINED_AS'], search_type=<SearchType.DIRECT: 'direct'>, query_intent='search', temporal_context=None)\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8d901ec186684b85a18613b1aa5b3380",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5ba55dbcc5684f1e84f2aade26176233",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "85b68e0a2f8a4b668fbd1b8054a8c814",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b364d800ae174196bb0edf05d9b7f711",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.utils.graph_standardizer:✅ Successfully synced new edge 'SURVIVES_INTO' -> 'survives into' in category 'nature' with embedding cache\n",
      "INFO:kg_engine.core.engine:Standardized 'DEFINED_AS' -> 'SURVIVES_INTO' (category: nature)\n",
      "WARNING:neo4j.notifications:Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning} {category: UNRECOGNIZED} {title: The provided relationship type is not in the database.} {description: One of the relationship types in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing relationship type is: DEFINED_AS)} {position: line: 3, column: 50, offset: 92} for query: '\\n                MATCH (start:Entity {name: $entity_name})\\n                MATCH (start)-[r:DEFINED_AS|SURVIVES_INTO]-(connected:Entity)\\n                WHERE r.obsolete = false\\n                RETURN start, r, connected, \\n                       r.confidence as confidence,\\n                       type(r) as relationship_type\\n                ORDER BY r.confidence DESC\\n                LIMIT $limit\\n                '\n",
      "INFO:kg_engine.storage.graph_db:Entity exploration returned 0 results for firmament\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Standardized relationships: ['SURVIVES_INTO']\n",
      "Searching with entities: ['firmament'] and relationships: ['DEFINED_AS', 'SURVIVES_INTO']\n",
      "Parsing query SEMANTIC...\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9ef670dc1693490fb8786a138385357e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Vector similarity search returned 10 results\n",
      "INFO:httpx:HTTP Request: POST http://localhost:11434/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A: The firmament refers to a solid dome that was believed by ancient cultures like the Hebrews and Greeks to separate the waters above from the land below. In religious texts, such as in Genesis chapter one of the Bible, it is described as Heaven being created when God spoke, saying \"Let there be a firmament.\" This term has been used historically to describe what we might now refer to more accurately as the sky or atmosphere where clouds and weather occur.\n",
      "   (Found 10 results in 4561.6ms)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Test some queries on the processed data\n",
    "test_queries = [\n",
    "    \"Who created the heaven and earth?\",\n",
    "    \"What did God create on the first day?\",\n",
    "    \"What is the firmament?\"\n",
    "]\n",
    "\n",
    "print(\"🔍 Testing queries on processed data:\\n\")\n",
    "\n",
    "for query in test_queries:\n",
    "    print(f\"Q: {query}\")\n",
    "    try:\n",
    "        response = engine.search(query)\n",
    "        print(f\"A: {response.answer}\")\n",
    "        print(f\"   (Found {len(response.results)} results in {response.query_time_ms:.1f}ms)\")\n",
    "    except Exception as e:\n",
    "        print(f\"   Error: {e}\")\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Graph Visualization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Analyze graph structure\n",
    "def analyze_graph_structure(G):\n",
    "    \"\"\"Analyze and display graph structure statistics\"\"\"\n",
    "    print(\"📈 Graph Structure Analysis:\")\n",
    "    print(f\"   Nodes: {G.number_of_nodes()}\")\n",
    "    print(f\"   Edges: {G.number_of_edges()}\")\n",
    "    \n",
    "    if G.number_of_nodes() > 0:\n",
    "        # Degree analysis\n",
    "        degrees = [G.degree(node) for node in G.nodes()]\n",
    "        avg_degree = sum(degrees) / len(degrees)\n",
    "        max_degree = max(degrees)\n",
    "        \n",
    "        print(f\"   Average degree: {avg_degree:.2f}\")\n",
    "        print(f\"   Maximum degree: {max_degree}\")\n",
    "        \n",
    "        # Find most connected nodes\n",
    "        degree_dict = dict(G.degree())\n",
    "        top_nodes = sorted(degree_dict.items(), key=lambda x: x[1], reverse=True)[:5]\n",
    "        \n",
    "        print(\"\\\\n🔗 Most Connected Entities:\")\n",
    "        for node, degree in top_nodes:\n",
    "            print(f\"   {node}: {degree} connections\")\n",
    "        \n",
    "        # Relationship type distribution\n",
    "        relationships = [G[u][v]['relationship'] for u, v in G.edges()]\n",
    "        rel_counts = {}\n",
    "        for rel in relationships:\n",
    "            rel_counts[rel] = rel_counts.get(rel, 0) + 1\n",
    "        \n",
    "        top_rels = sorted(rel_counts.items(), key=lambda x: x[1], reverse=True)[:5]\n",
    "        print(\"\\\\n📊 Most Common Relationships:\")\n",
    "        for rel, count in top_rels:\n",
    "            print(f\"   {rel}: {count} edges\")\n",
    "\n",
    "if 'G' in locals():\n",
    "    analyze_graph_structure(G)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install required packages for visualization\n",
    "import subprocess\n",
    "import sys\n",
    "\n",
    "def install_package(package):\n",
    "    try:\n",
    "        __import__(package)\n",
    "    except ImportError:\n",
    "        print(f\"Installing {package}...\")\n",
    "        subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", package])\n",
    "\n",
    "# Install visualization packages\n",
    "install_package(\"networkx\")\n",
    "install_package(\"matplotlib\")\n",
    "install_package(\"plotly\")\n",
    "\n",
    "print(\"✅ Visualization packages ready\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# %pip install networkx matplotlib plotly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "📊 Fetching graph data (limit: 50)...\n",
      "✅ Retrieved 50 relationships\n",
      "\\n🎨 Creating visualizations for 50 relationships...\n",
      "   Graph has 58 nodes and 42 edges\n",
      "\\n📊 Creating static visualization...\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 465968 characters]",
      "text/plain": [
       "<Figure size 1500x1000 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "📋 Relationship Types in Graph:\n",
      "   1. SAID_TO\n",
      "   2. WAS_STATE\n",
      "   3. IS_CALLED\n",
      "   4. CALLED_LITERALLY\n",
      "   5. BECOMES_DRY\n",
      "   6. SURVIVES_TOGETHER\n",
      "   7. SAID\n",
      "   8. CREATED_THE\n",
      "   9. UNDER\n",
      "   10. SURVIVES_INTO\n",
      "\\n🔄 Creating interactive visualization...\n"
     ]
    },
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "hoverinfo": "none",
         "line": {
          "color": "#888",
          "width": 2
         },
         "mode": "lines",
         "type": "scatter",
         "x": [
          -0.5592806268562268,
          -0.33836178137462136,
          null,
          0.32333048063582126,
          0.6886412948629458,
          null,
          0.6886412948629458,
          -0.8495986420889274,
          null,
          0.09033388060056075,
          0.9725415631260524,
          null,
          0.09033388060056075,
          -0.09210122558664155,
          null,
          0.09033388060056075,
          -0.714215775950812,
          null,
          0.09033388060056075,
          0.6211783178665325,
          null,
          0.09033388060056075,
          -0.5141280627337671,
          null,
          0.09033388060056075,
          0.9341620531031671,
          null,
          0.09033388060056075,
          0.9060888504277154,
          null,
          0.09033388060056075,
          0.6641741130307038,
          null,
          0.09033388060056075,
          0.9355679354114353,
          null,
          0.09033388060056075,
          0.1697372213634911,
          null,
          0.09033388060056075,
          -0.8868749538580702,
          null,
          0.09033388060056075,
          0.6886412948629458,
          null,
          0.09033388060056075,
          -0.845764743935411,
          null,
          0.09033388060056075,
          -0.283876196371828,
          null,
          0.09033388060056075,
          -0.9311133430160317,
          null,
          0.09033388060056075,
          0.956637632552342,
          null,
          0.09033388060056075,
          -0.9812997957556093,
          null,
          0.09033388060056075,
          -0.06829924881021615,
          null,
          0.09033388060056075,
          0.8280683936768309,
          null,
          0.09033388060056075,
          -0.8716483513758582,
          null,
          0.09033388060056075,
          -0.6571978627917002,
          null,
          0.09033388060056075,
          0.19893615592489808,
          null,
          0.09033388060056075,
          0.49828430059713,
          null,
          -0.21226380389300725,
          -0.7942911573183178,
          null,
          -0.877257979267738,
          0.34635723463519974,
          null,
          -0.3867715252780896,
          0.35123636448857404,
          null,
          -0.7426407442096041,
          0.872588910509549,
          null,
          0.8159965759526181,
          0.41865754177277786,
          null,
          0.8403526394144143,
          0.6326874534925975,
          null,
          0.8403526394144143,
          -0.5700237427360142,
          null,
          0.009367087596577766,
          -0.7946088760487827,
          null,
          0.15798504144171885,
          0.4790008852149962,
          null,
          -0.9426765201734518,
          -0.3811094212525565,
          null,
          -0.6400344266093257,
          0.8411715509251791,
          null,
          0.8398937533692195,
          -0.5206284464357835,
          null,
          -0.890820706179011,
          0.0265792157948131,
          null,
          -1,
          0.820499716418652,
          null,
          -0.20504302355783247,
          0.682416552887756,
          null,
          -0.20504302355783247,
          0.6294582663709676,
          null
         ],
         "y": [
          -0.872020556439424,
          0.9240092253555684,
          null,
          -0.961243479691427,
          0.6897675217678131,
          null,
          0.6897675217678131,
          -0.21488567421129906,
          null,
          -0.3090150227352253,
          0.11253079920204731,
          null,
          -0.3090150227352253,
          0.9042365936710914,
          null,
          -0.3090150227352253,
          0.7287374219448444,
          null,
          -0.3090150227352253,
          0.819872420469007,
          null,
          -0.3090150227352253,
          -0.7421957541093132,
          null,
          -0.3090150227352253,
          -0.2702795193648612,
          null,
          -0.3090150227352253,
          -0.14825922982987785,
          null,
          -0.3090150227352253,
          -0.593896693616116,
          null,
          -0.3090150227352253,
          0.26481787179128013,
          null,
          -0.3090150227352253,
          0.9474098017360343,
          null,
          -0.3090150227352253,
          -0.3596344167644,
          null,
          -0.3090150227352253,
          0.6897675217678131,
          null,
          -0.3090150227352253,
          0.5453083119299753,
          null,
          -0.3090150227352253,
          -0.9692635374660882,
          null,
          -0.3090150227352253,
          -0.06381011019553305,
          null,
          -0.3090150227352253,
          -0.03533385942544315,
          null,
          -0.3090150227352253,
          -0.22094824504391083,
          null,
          -0.3090150227352253,
          -0.8919215348030575,
          null,
          -0.3090150227352253,
          -0.3355395154227949,
          null,
          -0.3090150227352253,
          0.35056354681397167,
          null,
          -0.3090150227352253,
          -0.7153207043378742,
          null,
          -0.3090150227352253,
          0.8468639360736561,
          null,
          -0.3090150227352253,
          -0.8739099596823288,
          null,
          0.9113281692431583,
          -0.6729432717559279,
          null,
          -0.49055657826874,
          0.9239977125372933,
          null,
          -0.8621456206619026,
          -0.8383558334144788,
          null,
          -0.5402678363110126,
          0.47234797545579377,
          null,
          -0.5805786060380493,
          0.7277707371508157,
          null,
          -0.44983966029324446,
          0.4965787632208507,
          null,
          -0.44983966029324446,
          0.7105091414092201,
          null,
          -0.9630899562532372,
          0.4652977918554979,
          null,
          -0.9938593185534468,
          0.8341049890336388,
          null,
          0.25106233383300425,
          0.8133801115021562,
          null,
          0.5653940040283388,
          0.3587901419616009,
          null,
          0.11837410175677365,
          0.8313173345271039,
          null,
          0.11867057142297092,
          0.9166434305906146,
          null,
          0.08776703429964565,
          0.6165742287669149,
          null,
          -0.8526133404804077,
          -0.7974371811645634,
          null,
          -0.8526133404804077,
          -0.734861007016698,
          null
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "heavens<br>Connections: 1",
          "earth<br>Connections: 0",
          "Firmament<br>Connections: 1",
          "Earth<br>Connections: 1",
          "God<br>Connections: 23",
          "fill<br>Connections: 0",
          "SERPENT<br>Connections: 1",
          "allowed to eat fruit from trees in the garden<br>Connections: 0",
          "firmament and waters<br>Connections: 0",
          "3:8 AND THEM<br>Connections: 1",
          "LORD GOD'S VOICE IN GARDEN<br>Connections: 0",
          "Mankind<br>Connections: 1",
          "dominion over the earth<br>Connections: 0",
          "Person (implied)<br>Connections: 1",
          "Farm<br>Connections: 0",
          "Heaven<br>Connections: 1",
          "giving light upon the earth: and it was<br>Connections: 0",
          "lights in the firmament of heaven<br>Connections: 0",
          "without form, void, darkness<br>Connections: 0",
          "Seas<br>Connections: 0",
          "it (the kind)<br>Connections: 0",
          "GOD<br>Connections: 2",
          "HEAVEN_AND_THE_EARTH<br>Connections: 0",
          "LIVING_CREATURES<br>Connections: 0",
          "earth's kind and cattle<br>Connections: 0",
          "LORD GOD<br>Connections: 1",
          "GARDEN<br>Connections: 0",
          "Herb<br>Connections: 1",
          "Field<br>Connections: 0",
          "WHALES<br>Connections: 0",
          "HEAVEN AND THE EARTH<br>Connections: 0",
          "Let there be a firmament in the midst of the waters<br>Connections: 0",
          "Itself<br>Connections: 1",
          "The Earth<br>Connections: 0",
          "multiply<br>Connections: 0",
          "Let the earth bring forth grass and herbs yielding<br>Connections: 0",
          "Let waters under heaven be gathered together<br>Connections: 0",
          "One Place<br>Connections: 1",
          "Dry Land<br>Connections: 0",
          "light<br>Connections: 0",
          "Winged Fowl<br>Connections: 1",
          "God's Creation<br>Connections: 0",
          "fruitful<br>Connections: 0",
          "waters<br>Connections: 0",
          "firmament<br>Connections: 0",
          "two_great_lights<br>Connections: 0",
          "firmament in the midst of waters<br>Connections: 0",
          "Darkness<br>Connections: 0",
          "Light<br>Connections: 0",
          "lesser_light<br>Connections: 1",
          "night<br>Connections: 0",
          "Seasons<br>Connections: 1",
          "Lights<br>Connections: 0",
          "Firmament of the heaven<br>Connections: 0",
          "EARTH<br>Connections: 2",
          "orbiting<br>Connections: 0",
          "rotating<br>Connections: 0",
          "Let the waters bring forth abundantly the living creature<br>Connections: 0"
         ],
         "marker": {
          "color": [
           1,
           0,
           1,
           1,
           23,
           0,
           1,
           0,
           0,
           1,
           0,
           1,
           0,
           1,
           0,
           1,
           0,
           0,
           0,
           0,
           0,
           2,
           0,
           0,
           0,
           1,
           0,
           1,
           0,
           0,
           0,
           0,
           1,
           0,
           0,
           0,
           0,
           1,
           0,
           0,
           1,
           0,
           0,
           0,
           0,
           0,
           0,
           0,
           0,
           1,
           0,
           1,
           0,
           0,
           2,
           0,
           0,
           0
          ],
          "colorbar": {
           "len": 0.5,
           "thickness": 15,
           "title": {
            "text": "Node<br>Connections"
           },
           "x": 1.02
          },
          "colorscale": [
           [
            0,
            "#440154"
           ],
           [
            0.1111111111111111,
            "#482878"
           ],
           [
            0.2222222222222222,
            "#3e4989"
           ],
           [
            0.3333333333333333,
            "#31688e"
           ],
           [
            0.4444444444444444,
            "#26828e"
           ],
           [
            0.5555555555555556,
            "#1f9e89"
           ],
           [
            0.6666666666666666,
            "#35b779"
           ],
           [
            0.7777777777777778,
            "#6ece58"
           ],
           [
            0.8888888888888888,
            "#b5de2b"
           ],
           [
            1,
            "#fde725"
           ]
          ],
          "line": {
           "width": 2
          },
          "reversescale": true,
          "showscale": true,
          "size": 15
         },
         "mode": "markers+text",
         "text": [
          "heavens",
          "earth",
          "Firmament",
          "Earth",
          "God",
          "fill",
          "SERPENT",
          "allowed to eat fruit from trees in the garden",
          "firmament and waters",
          "3:8 AND THEM",
          "LORD GOD'S VOICE IN GARDEN",
          "Mankind",
          "dominion over the earth",
          "Person (implied)",
          "Farm",
          "Heaven",
          "giving light upon the earth: and it was",
          "lights in the firmament of heaven",
          "without form, void, darkness",
          "Seas",
          "it (the kind)",
          "GOD",
          "HEAVEN_AND_THE_EARTH",
          "LIVING_CREATURES",
          "earth's kind and cattle",
          "LORD GOD",
          "GARDEN",
          "Herb",
          "Field",
          "WHALES",
          "HEAVEN AND THE EARTH",
          "Let there be a firmament in the midst of the waters",
          "Itself",
          "The Earth",
          "multiply",
          "Let the earth bring forth grass and herbs yielding",
          "Let waters under heaven be gathered together",
          "One Place",
          "Dry Land",
          "light",
          "Winged Fowl",
          "God's Creation",
          "fruitful",
          "waters",
          "firmament",
          "two_great_lights",
          "firmament in the midst of waters",
          "Darkness",
          "Light",
          "lesser_light",
          "night",
          "Seasons",
          "Lights",
          "Firmament of the heaven",
          "EARTH",
          "orbiting",
          "rotating",
          "Let the waters bring forth abundantly the living creature"
         ],
         "textposition": "middle center",
         "type": "scatter",
         "x": [
          -0.5592806268562268,
          -0.33836178137462136,
          0.32333048063582126,
          0.6886412948629458,
          0.09033388060056075,
          0.9725415631260524,
          -0.21226380389300725,
          -0.7942911573183178,
          -0.09210122558664155,
          -0.877257979267738,
          0.34635723463519974,
          -0.3867715252780896,
          0.35123636448857404,
          -0.7426407442096041,
          0.872588910509549,
          0.8159965759526181,
          0.41865754177277786,
          -0.714215775950812,
          -0.8495986420889274,
          0.6211783178665325,
          -0.5141280627337671,
          0.8403526394144143,
          0.6326874534925975,
          0.9341620531031671,
          0.9060888504277154,
          0.009367087596577766,
          -0.7946088760487827,
          0.15798504144171885,
          0.4790008852149962,
          0.6641741130307038,
          -0.5700237427360142,
          0.9355679354114353,
          -0.9426765201734518,
          -0.3811094212525565,
          0.1697372213634911,
          -0.8868749538580702,
          -0.845764743935411,
          -0.6400344266093257,
          0.8411715509251791,
          -0.283876196371828,
          0.8398937533692195,
          -0.5206284464357835,
          -0.9311133430160317,
          0.956637632552342,
          -0.9812997957556093,
          -0.06829924881021615,
          0.8280683936768309,
          -0.8716483513758582,
          -0.6571978627917002,
          -0.890820706179011,
          0.0265792157948131,
          -1,
          0.820499716418652,
          0.19893615592489808,
          -0.20504302355783247,
          0.682416552887756,
          0.6294582663709676,
          0.49828430059713
         ],
         "y": [
          -0.872020556439424,
          0.9240092253555684,
          -0.961243479691427,
          0.6897675217678131,
          -0.3090150227352253,
          0.11253079920204731,
          0.9113281692431583,
          -0.6729432717559279,
          0.9042365936710914,
          -0.49055657826874,
          0.9239977125372933,
          -0.8621456206619026,
          -0.8383558334144788,
          -0.5402678363110126,
          0.47234797545579377,
          -0.5805786060380493,
          0.7277707371508157,
          0.7287374219448444,
          -0.21488567421129906,
          0.819872420469007,
          -0.7421957541093132,
          -0.44983966029324446,
          0.4965787632208507,
          -0.2702795193648612,
          -0.14825922982987785,
          -0.9630899562532372,
          0.4652977918554979,
          -0.9938593185534468,
          0.8341049890336388,
          -0.593896693616116,
          0.7105091414092201,
          0.26481787179128013,
          0.25106233383300425,
          0.8133801115021562,
          0.9474098017360343,
          -0.3596344167644,
          0.5453083119299753,
          0.5653940040283388,
          0.3587901419616009,
          -0.9692635374660882,
          0.11837410175677365,
          0.8313173345271039,
          -0.06381011019553305,
          -0.03533385942544315,
          -0.22094824504391083,
          -0.8919215348030575,
          -0.3355395154227949,
          0.35056354681397167,
          -0.7153207043378742,
          0.11867057142297092,
          0.9166434305906146,
          0.08776703429964565,
          0.6165742287669149,
          0.8468639360736561,
          -0.8526133404804077,
          -0.7974371811645634,
          -0.734861007016698,
          -0.8739099596823288
         ]
        }
       ],
       "layout": {
        "annotations": [
         {
          "font": {
           "size": 12
          },
          "showarrow": false,
          "text": "Node size and color represent number of connections",
          "x": 0.005,
          "xanchor": "left",
          "xref": "paper",
          "y": -0.002,
          "yanchor": "bottom",
          "yref": "paper"
         }
        ],
        "hovermode": "closest",
        "margin": {
         "b": 20,
         "l": 5,
         "r": 5,
         "t": 40
        },
        "showlegend": false,
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "#2a3f5f"
            },
            "error_y": {
             "color": "#2a3f5f"
            },
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "baxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "histogram": [
           {
            "marker": {
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermap": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermap"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "#EBF0F8"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "#C8D4E3"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowcolor": "#2a3f5f",
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 0,
            "ticks": ""
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "#8e0152"
            ],
            [
             0.1,
             "#c51b7d"
            ],
            [
             0.2,
             "#de77ae"
            ],
            [
             0.3,
             "#f1b6da"
            ],
            [
             0.4,
             "#fde0ef"
            ],
            [
             0.5,
             "#f7f7f7"
            ],
            [
             0.6,
             "#e6f5d0"
            ],
            [
             0.7,
             "#b8e186"
            ],
            [
             0.8,
             "#7fbc41"
            ],
            [
             0.9,
             "#4d9221"
            ],
            [
             1,
             "#276419"
            ]
           ],
           "sequential": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ]
          },
          "colorway": [
           "#636efa",
           "#EF553B",
           "#00cc96",
           "#ab63fa",
           "#FFA15A",
           "#19d3f3",
           "#FF6692",
           "#B6E880",
           "#FF97FF",
           "#FECB52"
          ],
          "font": {
           "color": "#2a3f5f"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "#E5ECF6",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "white"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "#E5ECF6",
          "polar": {
           "angularaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "radialaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "yaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "zaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           }
          },
          "shapedefaults": {
           "line": {
            "color": "#2a3f5f"
           }
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "baxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "caxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          }
         }
        },
        "title": {
         "font": {
          "size": 16
         },
         "text": "Bible Knowledge Graph - Interactive View"
        },
        "xaxis": {
         "showgrid": false,
         "showticklabels": false,
         "zeroline": false
        },
        "yaxis": {
         "showgrid": false,
         "showticklabels": false,
         "zeroline": false
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import networkx as nx\n",
    "import matplotlib.pyplot as plt\n",
    "import plotly.graph_objects as go\n",
    "import plotly.express as px\n",
    "from collections import defaultdict\n",
    "import random\n",
    "\n",
    "def get_graph_data_for_visualization(engine, limit=100):\n",
    "    \"\"\"Get graph data from Neo4j for visualization\"\"\"\n",
    "    print(f\"📊 Fetching graph data (limit: {limit})...\")\n",
    "    \n",
    "    try:\n",
    "        # Get all relationships with their entities\n",
    "        with engine.graph_db.driver.session(database=engine.graph_db.config.database) as session:\n",
    "            result = session.run(f\"\"\"\n",
    "                MATCH (s:Entity)-[r]->(o:Entity)\n",
    "                WHERE r.obsolete = false\n",
    "                RETURN s.name as subject, type(r) as relationship, o.name as object, \n",
    "                       r.confidence as confidence, r.summary as summary\n",
    "                ORDER BY r.confidence DESC\n",
    "                LIMIT {limit}\n",
    "            \"\"\")\n",
    "            \n",
    "            relationships = []\n",
    "            for record in result:\n",
    "                relationships.append({\n",
    "                    'subject': record['subject'],\n",
    "                    'relationship': record['relationship'], \n",
    "                    'object': record['object'],\n",
    "                    'confidence': record['confidence'],\n",
    "                    'summary': record['summary']\n",
    "                })\n",
    "            \n",
    "        print(f\"✅ Retrieved {len(relationships)} relationships\")\n",
    "        return relationships\n",
    "        \n",
    "    except Exception as e:\n",
    "        print(f\"❌ Error fetching graph data: {e}\")\n",
    "        return []\n",
    "\n",
    "def create_networkx_graph(relationships):\n",
    "    \"\"\"Create NetworkX graph from relationships\"\"\"\n",
    "    G = nx.DiGraph()\n",
    "    \n",
    "    # Add edges with attributes\n",
    "    for rel in relationships:\n",
    "        G.add_edge(\n",
    "            rel['subject'], \n",
    "            rel['object'],\n",
    "            relationship=rel['relationship'],\n",
    "            confidence=rel['confidence'],\n",
    "            summary=rel['summary']\n",
    "        )\n",
    "    \n",
    "    return G\n",
    "\n",
    "def visualize_graph_matplotlib(G, title=\"Knowledge Graph Visualization\"):\n",
    "    \"\"\"Create static visualization using matplotlib\"\"\"\n",
    "    plt.figure(figsize=(15, 10))\n",
    "    \n",
    "    # Create layout\n",
    "    pos = nx.spring_layout(G, k=3, iterations=50)\n",
    "    \n",
    "    # Draw nodes\n",
    "    node_sizes = [300 + len(G.edges(node)) * 100 for node in G.nodes()]\n",
    "    nx.draw_networkx_nodes(G, pos, node_size=node_sizes, \n",
    "                          node_color='lightblue', alpha=0.7)\n",
    "    \n",
    "    # Draw edges with different colors for different relationships\n",
    "    edge_colors = []\n",
    "    relationships = [G[u][v]['relationship'] for u, v in G.edges()]\n",
    "    unique_rels = list(set(relationships))\n",
    "    color_map = {rel: plt.cm.Set3(i/len(unique_rels)) for i, rel in enumerate(unique_rels)}\n",
    "    \n",
    "    for u, v in G.edges():\n",
    "        rel = G[u][v]['relationship']\n",
    "        edge_colors.append(color_map[rel])\n",
    "    \n",
    "    nx.draw_networkx_edges(G, pos, edge_color=edge_colors, \n",
    "                          arrows=True, arrowsize=20, alpha=0.6, width=2)\n",
    "    \n",
    "    # Draw labels\n",
    "    nx.draw_networkx_labels(G, pos, font_size=8, font_weight='bold')\n",
    "    \n",
    "    plt.title(title, size=16, weight='bold')\n",
    "    plt.axis('off')\n",
    "    plt.tight_layout()\n",
    "    plt.show()\n",
    "    \n",
    "    # Show relationship type legend\n",
    "    print(\"📋 Relationship Types in Graph:\")\n",
    "    for i, rel in enumerate(unique_rels[:10]):  # Show first 10\n",
    "        print(f\"   {i+1}. {rel}\")\n",
    "\n",
    "def visualize_graph_plotly(relationships, title=\"Interactive Knowledge Graph\"):\n",
    "    \"\"\"Create interactive visualization using Plotly\"\"\"\n",
    "    \n",
    "    # Create NetworkX graph for layout\n",
    "    G = create_networkx_graph(relationships)\n",
    "    pos = nx.spring_layout(G, k=3, iterations=50)\n",
    "    \n",
    "    # Extract node and edge information\n",
    "    node_x = []\n",
    "    node_y = []\n",
    "    node_text = []\n",
    "    node_info = []\n",
    "    \n",
    "    for node in G.nodes():\n",
    "        x, y = pos[node]\n",
    "        node_x.append(x)\n",
    "        node_y.append(y)\n",
    "        node_text.append(node)\n",
    "        \n",
    "        # Count connections\n",
    "        connections = len(G.edges(node))\n",
    "        node_info.append(f\"{node}<br>Connections: {connections}\")\n",
    "    \n",
    "    # Create edge traces\n",
    "    edge_x = []\n",
    "    edge_y = []\n",
    "    edge_info = []\n",
    "    \n",
    "    for edge in G.edges():\n",
    "        x0, y0 = pos[edge[0]]\n",
    "        x1, y1 = pos[edge[1]]\n",
    "        edge_x.extend([x0, x1, None])\n",
    "        edge_y.extend([y0, y1, None])\n",
    "        \n",
    "        # Get edge information\n",
    "        rel_data = G[edge[0]][edge[1]]\n",
    "        edge_info.append(f\"{edge[0]} → {edge[1]}<br>{rel_data['relationship']}<br>Confidence: {rel_data['confidence']:.2f}\")\n",
    "    \n",
    "    # Create edge trace\n",
    "    edge_trace = go.Scatter(x=edge_x, y=edge_y,\n",
    "                           line=dict(width=2, color='#888'),\n",
    "                           hoverinfo='none',\n",
    "                           mode='lines')\n",
    "    \n",
    "    # Create node trace\n",
    "    node_trace = go.Scatter(x=node_x, y=node_y,\n",
    "                           mode='markers+text',\n",
    "                           hoverinfo='text',\n",
    "                           text=node_text,\n",
    "                           textposition='middle center',\n",
    "                           hovertext=node_info,\n",
    "                           marker=dict(showscale=True,\n",
    "                                     colorscale='Viridis',\n",
    "                                     reversescale=True,\n",
    "                                     color=[],\n",
    "                                     size=15,\n",
    "                                     colorbar=dict(\n",
    "                                         thickness=15,\n",
    "                                         len=0.5,\n",
    "                                         x=1.02,\n",
    "                                         title=\"Node<br>Connections\"\n",
    "                                     ),\n",
    "                                     line=dict(width=2)))\n",
    "    \n",
    "    # Color nodes by number of connections\n",
    "    node_adjacencies = []\n",
    "    for node in G.nodes():\n",
    "        node_adjacencies.append(len(list(G.neighbors(node))))\n",
    "    \n",
    "    node_trace.marker.color = node_adjacencies\n",
    "    \n",
    "    # Create figure\n",
    "    fig = go.Figure(data=[edge_trace, node_trace],\n",
    "                   layout=go.Layout(\n",
    "                            title=title,\n",
    "                            title_font_size=16,\n",
    "                            showlegend=False,\n",
    "                            hovermode='closest',\n",
    "                            margin=dict(b=20,l=5,r=5,t=40),\n",
    "                            annotations=[ dict(\n",
    "                                text=\"Node size and color represent number of connections\",\n",
    "                                showarrow=False,\n",
    "                                xref=\"paper\", yref=\"paper\",\n",
    "                                x=0.005, y=-0.002,\n",
    "                                xanchor='left', yanchor='bottom',\n",
    "                                font=dict(size=12)\n",
    "                            )],\n",
    "                            xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),\n",
    "                            yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))\n",
    "    \n",
    "    fig.show()\n",
    "    \n",
    "    return fig\n",
    "\n",
    "# Get graph data and create visualizations\n",
    "relationships = get_graph_data_for_visualization(engine, limit=50)\n",
    "\n",
    "if relationships:\n",
    "    print(f\"\\\\n🎨 Creating visualizations for {len(relationships)} relationships...\")\n",
    "    \n",
    "    # Create NetworkX graph\n",
    "    G = create_networkx_graph(relationships)\n",
    "    print(f\"   Graph has {G.number_of_nodes()} nodes and {G.number_of_edges()} edges\")\n",
    "    \n",
    "    # Static visualization\n",
    "    print(\"\\\\n📊 Creating static visualization...\")\n",
    "    visualize_graph_matplotlib(G, \"Bible Knowledge Graph - Static View\")\n",
    "    \n",
    "    # Interactive visualization\n",
    "    print(\"\\\\n🔄 Creating interactive visualization...\")\n",
    "    fig = visualize_graph_plotly(relationships, \"Bible Knowledge Graph - Interactive View\")\n",
    "    \n",
    "else:\n",
    "    print(\"❌ No relationships found for visualization\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cleanup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:kg_engine.storage.graph_db:Cleared all graph data\n",
      "INFO:kg_engine.storage.graph_db:Cleared all graph data\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Uncomment to clear all data\n",
    "# print(\"🧹 Clearing all data...\")\n",
    "engine.clear_all_data()\n",
    "# print(\"✅ All data cleared\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
