Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

Fix AttributeError in WebIngestor and upgrade to KG-aware chunking in GraphRAG notebook

KaifAhmad1529f099dddb4
diff --git a/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb b/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb
index 4d981acf..f2da31de 100644
--- a/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb
+++ b/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb
@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "# Semantica Mastery: The Ultimate End-to-End GraphRAG Pipeline\n",
+ "# The Ultimate End-to-End GraphRAG Pipeline\n",
"\n",
"## Overview\n",
"\n",
@@ -36,9 +36,40 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
+ "WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
+ "WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
+ "WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
+ "WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
+ "WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
+ "WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
+ "WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
+ "WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
+ "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
+ "descript-audiotools 0.7.2 requires protobuf<3.20,>=3.9.2, but you have protobuf 4.25.8 which is incompatible.\n",
+ "langchain-openai 0.2.10 requires langchain-core<0.4.0,>=0.3.21, but you have langchain-core 0.1.23 which is incompatible.\n",
+ "mistral-common 1.5.1 requires tiktoken<0.8.0,>=0.7.0, but you have tiktoken 0.12.0 which is incompatible.\n",
+ "nari-tts 0.1.0 requires numpy>=2.2.4, but you have numpy 1.26.4 which is incompatible.\n",
+ "nari-tts 0.1.0 requires torch>=2.6.0, but you have torch 2.2.1 which is incompatible.\n",
+ "parlant 3.0.2 requires fastapi==0.115.12, but you have fastapi 0.120.4 which is incompatible.\n",
+ "parlant 3.0.2 requires fastmcp==2.6.1, but you have fastmcp 2.14.1 which is incompatible.\n",
+ "parlant 3.0.2 requires opentelemetry-exporter-otlp-proto-grpc==1.27.0, but you have opentelemetry-exporter-otlp-proto-grpc 1.38.0 which is incompatible.\n",
+ "parlant 3.0.2 requires rich<14.0.0,>=13.7.1, but you have rich 14.2.0 which is incompatible.\n",
+ "parlant 3.0.2 requires tiktoken<0.9,>=0.8, but you have tiktoken 0.12.0 which is incompatible.\n",
+ "parlant 3.0.2 requires tokenizers<0.21,>=0.20, but you have tokenizers 0.21.4 which is incompatible.\n",
+ "parlant 3.0.2 requires uvicorn<0.33.0,>=0.32.1, but you have uvicorn 0.38.0 which is incompatible.\n",
+ "vllm 0.6.6.post1 requires torch==2.5.1, but you have torch 2.2.1 which is incompatible.\n",
+ "vllm 0.6.6.post1 requires torchvision==0.20.1, but you have torchvision 0.17.1 which is incompatible.\n"
+ ]
+ }
+ ],
"source": [
"# Environment Setup\n",
"!pip install -qU semantica networkx matplotlib plotly pandas faiss-cpu tiktoken beautifulsoup4 python-docx pdfplumber"
@@ -55,9 +86,17 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Config Loaded.\n"
+ ]
+ }
+ ],
"source": [
"import os\n",
"from semantica.core import Semantica, ConfigManager\n",
@@ -100,9 +139,29 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "<div style='font-family: monospace;'><h4>🧠 Semantica - πŸ“Š Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>βœ…</td><td>Semantica is seeding</td><td>🌱 seed</td><td>SeedDataManager</td><td>-</td><td>0.05s</td></tr></table></div>"
+ ],
+ "text/plain": [
+ "<IPython.core.display.HTML object>"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Foundation Graph Seeded with 2 Verified Nodes.\n"
+ ]
+ }
+ ],
"source": [
"import json\n",
"from semantica.seed import SeedDataManager\n",
@@ -145,11 +204,25 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ingesting Official Documentation...\n",
+ "\n",
+ "Fetching Live Tech News...\n",
+ "\n",
+ "Ingesting Engineering READMEs...\n",
+ "\n",
+ "Aggregated 14 documents from across the web.\n"
+ ]
+ }
+ ],
"source": [
- "from semantica.ingest import WebIngestor, FeedIngestor, ingest\n",
+ "from semantica.ingest import ingest_web, ingest_feed\n",
"from semantica.parse import parse_document\n",
"\n",
"all_content = []\n",
@@ -159,12 +232,16 @@
"web_urls = [\n",
" \"https://www.python.org/about/\",\n",
" \"https://www.python.org/downloads/\",\n",
- " \"https://realpython.com/python-news/\"\n",
+ " \"https://realpython.com/\" # Fixed 404: updated from /python-news/\n",
"]\n",
- "web_ingestor = WebIngestor()\n",
+ "\n",
"for url in web_urls:\n",
- " docs = web_ingestor.ingest(url, method=\"url\")\n",
- " all_content.extend([d.content if hasattr(d, 'content') else str(d) for d in docs])\n",
+ " try:\n",
+ " # Returns a WebContent object\n",
+ " doc = ingest_web(url, method=\"url\")\n",
+ " all_content.append(doc.text)\n",
+ " except Exception as e:\n",
+ " print(f\"Failed to ingest {url}: {e}\")\n",
"\n",
"# 2. Live RSS Feeds\n",
"print(\"\\nFetching Live Tech News...\")\n",
@@ -173,10 +250,17 @@
" \"https://techcrunch.com/feed/\",\n",
" \"https://www.wired.com/feed/rss\"\n",
"]\n",
- "feed_ingestor = FeedIngestor()\n",
+ "\n",
"for feed in rss_feeds:\n",
- " docs = feed_ingestor.ingest(feed)[:3] # Top 3 from each\n",
- " all_content.extend([d.content if hasattr(d, 'content') else str(d) for d in docs])\n",
+ " try:\n",
+ " # Returns a FeedData object\n",
+ " feed_data = ingest_feed(feed, method=\"rss\")\n",
+ " # Extract top 3 items from each feed\n",
+ " for item in feed_data.items[:3]:\n",
+ " content = item.content if item.content else item.description\n",
+ " all_content.append(content)\n",
+ " except Exception as e:\n",
+ " print(f\"Failed to ingest feed {feed}: {e}\")\n",
"\n",
"# 3. Repository & Technical Files\n",
"print(\"\\nIngesting Engineering READMEs...\")\n",
@@ -184,9 +268,15 @@
" \"https://raw.githubusercontent.com/psf/requests/main/README.md\",\n",
" \"https://raw.githubusercontent.com/encode/httpx/master/README.md\"\n",
"]\n",
+ "\n",
"for file_url in repo_files:\n",
- " docs = ingest(file_url, source_type=\"web\") \n",
- " all_content.extend([d.content if hasattr(d, 'content') else str(d) for d in docs])\n",
+ " try:\n",
+ " # Using ingest_web directly to ensure we get a WebContent object \n",
+ " # (avoiding the dictionary wrapper returned by the unified 'ingest' function)\n",
+ " doc = ingest_web(file_url, method=\"url\") \n",
+ " all_content.append(doc.text)\n",
+ " except Exception as e:\n",
+ " print(f\"Failed to ingest {file_url}: {e}\")\n",
"\n",
"print(f\"\\nAggregated {len(all_content)} documents from across the web.\")"
]
@@ -204,10 +294,26 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "c:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\sentence_transformers\\cross_encoder\\CrossEncoder.py:13: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",
+ " from tqdm.autonotebook import tqdm, trange\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Normalized text and generated 52 semantic chunks.\n"
+ ]
+ }
+ ],
"source": [
"from semantica.normalize import TextNormalizer\n",
- "from semantica.split import TextSplitter\n",
+ "from semantica.split import GraphBasedChunker\n",
"\n",
"# Normalization - Sanitizing input data\n",
"normalizer = TextNormalizer()\n",
@@ -238,9 +344,21 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "AttributeError",
+ "evalue": "'dict' object has no attribute 'nodes'",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
+ "Cell \u001b[1;32mIn[5], line 11\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[38;5;66;03m# 2. Quality Control: Deduplication\u001b[39;00m\n\u001b[0;32m 10\u001b[0m detector \u001b[38;5;241m=\u001b[39m DuplicateDetector(similarity_threshold\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.85\u001b[39m)\n\u001b[1;32m---> 11\u001b[0m duplicates \u001b[38;5;241m=\u001b[39m detector\u001b[38;5;241m.\u001b[39mdetect_duplicates(\u001b[38;5;28mlist\u001b[39m(\u001b[43mkg\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnodes\u001b[49m(data\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)))\n\u001b[0;32m 12\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m duplicates:\n\u001b[0;32m 13\u001b[0m merger \u001b[38;5;241m=\u001b[39m EntityMerger()\n",
+ "\u001b[1;31mAttributeError\u001b[0m: 'dict' object has no attribute 'nodes'"
+ ]
+ }
+ ],
"source": [
"from semantica.kg import GraphBuilder\n",
"from semantica.deduplication import DuplicateDetector, EntityMerger\n",
@@ -424,9 +542,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.11.0"
+ "version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
-}
\ No newline at end of file
+}
diff --git a/cookbook/use_cases/advanced_rag/02_RAG_vs_GraphRAG_Comparison.ipynb b/cookbook/use_cases/advanced_rag/02_RAG_vs_GraphRAG_Comparison.ipynb
index 79ab94d4..10205877 100644
--- a/cookbook/use_cases/advanced_rag/02_RAG_vs_GraphRAG_Comparison.ipynb
+++ b/cookbook/use_cases/advanced_rag/02_RAG_vs_GraphRAG_Comparison.ipynb
@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "# RAG vs. GraphRAG: Global Intelligence Edition\n",
+ "# RAG vs. GraphRAG: \n",
"\n",
"## Overview\n",
"\n",
@@ -230,4 +230,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
-}
\ No newline at end of file
+}
diff --git a/cookbook/use_cases/advanced_rag/ground_truth.json b/cookbook/use_cases/advanced_rag/ground_truth.json
new file mode 100644
index 00000000..17614824
--- /dev/null
+++ b/cookbook/use_cases/advanced_rag/ground_truth.json
@@ -0,0 +1 @@
+{"entities": [{"id": "python_org", "name": "Python Software Foundation", "type": "Organization"}, {"id": "guido_van_rossum", "name": "Guido van Rossum", "type": "Person"}], "relationships": [{"source": "guido_van_rossum", "target": "python_org", "type": "FOUNDED"}]}
\ No newline at end of file