Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
Fix GraphRAG notebook chunking logic and repo ingestor git options
KaifAhmad14166de2777de
diff --git a/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb b/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynbindex 1eb7dc99..6fc16e91 100644--- a/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb+++ b/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb@@ -19,7 +19,7 @@"- **Hybrid Retrieval**: Combines vector similarity search with knowledge graph traversal\n","- **Multi-hop Reasoning**: Follows relationships across the graph for deeper context\n","\n",- "**Documentation**: [API Reference](https://semantica.readthedocs.io/concepts/) \u2022 [GraphRAG Guide](https://semantica.readthedocs.io/concepts/)\n",+ "**Documentation**: [API Reference](https://semantica.readthedocs.io/concepts/) β’ [GraphRAG Guide](https://semantica.readthedocs.io/concepts/)\n","\n","### What You'll Learn\n","\n",@@ -48,7 +48,7 @@},{"cell_type": "code",- "execution_count": 2,+ "execution_count": 1,"metadata": {},"outputs": [{@@ -83,9 +83,29 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 2,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "data": {+ "text/html": [+ "<div style='font-family: monospace;'><h4>π§ Semantica - π Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>β </td><td>Semantica is processing</td><td>β³ core</td><td>LifecycleManager</td><td>-</td><td>3.34s</td></tr><tr><td>β </td><td>Semantica is ingesting</td><td>π₯ ingest</td><td>FileIngestor</td><td>sample_graphrag_paper.txt</td><td>0.00s</td></tr><tr><td>β </td><td>Semantica is ingesting</td><td>π₯ ingest</td><td>RepoIngestor</td><td>requests</td><td>4.50s</td></tr><tr><td>β</td><td>Semantica is ingesting</td><td>π₯ ingest</td><td>WebIngestor</td><td>tool-use</td><td>0.26s</td></tr><tr><td>β </td><td>Semantica is ingesting</td><td>π₯ ingest</td><td>WebIngestor</td><td>#retrieval</td><td>2.09s</td></tr><tr><td>β </td><td>Semantica is ingesting</td><td>π₯ ingest</td><td>FeedIngestor</td><td>feed</td><td>0.54s</td></tr><tr><td>β </td><td>Semantica is ingesting</td><td>π₯ ingest</td><td>FeedIngestor</td><td>rss.xml</td><td>1.19s</td></tr><tr><td>β </td><td>Semantica is parsing</td><td>π parse</td><td>DocumentParser</td><td>sample_graphrag_paper.txt</td><td>0.01s</td></tr></table></div>"+ ],+ "text/plain": [+ "<IPython.core.display.HTML object>"+ ]+ },+ "metadata": {},+ "output_type": "display_data"+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Configuration and framework initialized\n"+ ]+ }+ ],"source": ["from semantica.core import ConfigManager, Semantica\n","\n",@@ -123,9 +143,36 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 3,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Ingesting local file from c:\\Users\\Mohd Kaif\\semantica\\cookbook\\use_cases\\advanced_rag\\data\\sample_graphrag_paper.txt...\n",+ " Ingested 1 file document\n",+ "\n",+ "Ingesting repository https://github.com/psf/requests...\n"+ ]+ },+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "Error analyzing commits: Cmd('git') failed due to: exit code(128)\n",+ " cmdline: git diff --numstat --no-renames --raw 420d16bc7ef326f7b65f90e4644adc0f6a0e1d44 70298332899f25826e35e42f8d83425124f755a5 --\n",+ " stderr: 'fatal: bad object 420d16bc7ef326f7b65f90e4644adc0f6a0e1d44'\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ " Ingested 1 repo document\n"+ ]+ }+ ],"source": ["from semantica.ingest import FileIngestor, RepoIngestor, WebIngestor, FeedIngestor\n","import os\n",@@ -185,9 +232,36 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 4,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Scraping https://docs.anthropic.com/en/docs/build-with-claude/tool-use...\n"+ ]+ },+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "URL https://docs.anthropic.com/en/docs/build-with-claude/tool-use blocked by robots.txt\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ " Error scraping https://docs.anthropic.com/en/docs/build-with-claude/tool-use: URL blocked by robots.txt: https://docs.anthropic.com/en/docs/build-with-claude/tool-use\n",+ "Scraping https://python.langchain.com/docs/concepts/#retrieval...\n",+ " Scraped 1 document(s)\n",+ "\n",+ "Total documents from web: 1\n",+ "Total documents so far: 3\n"+ ]+ }+ ],"source": ["web_ingestor = WebIngestor()\n","\n",@@ -228,9 +302,23 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 5,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Fetching feed https://techcrunch.com/category/artificial-intelligence/feed/...\n",+ " Fetched 20 feed item(s)\n",+ "Fetching feed http://feeds.bbci.co.uk/news/technology/rss.xml...\n",+ " Fetched 48 feed item(s)\n",+ "\n",+ "Total documents from feeds: 2\n",+ "Total documents collected: 5\n"+ ]+ }+ ],"source": ["feed_ingestor = FeedIngestor()\n","\n",@@ -277,9 +365,19 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 6,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Parsing documents...\n",+ "Warning: Unknown document format: <class 'dict'>\n",+ "Parsed 70 documents\n"+ ]+ }+ ],"source": ["from semantica.parse import DocumentParser\n","\n",@@ -365,9 +463,28 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 7,"metadata": {},- "outputs": [],+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Extracting entities, relationships, and triplets...\n"+ ]+ },+ {+ "ename": "NameError",+ "evalue": "name 'normalized_documents' is not defined",+ "output_type": "error",+ "traceback": [+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",+ "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",+ "Cell \u001b[1;32mIn[7], line 13\u001b[0m\n\u001b[0;32m 10\u001b[0m flat_relationships \u001b[38;5;241m=\u001b[39m []\n\u001b[0;32m 11\u001b[0m flat_triplets \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m---> 13\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m doc \u001b[38;5;129;01min\u001b[39;00m \u001b[43mnormalized_documents\u001b[49m:\n\u001b[0;32m 14\u001b[0m text \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mstr\u001b[39m(doc\u001b[38;5;241m.\u001b[39mcontent) \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(doc, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcontent\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mstr\u001b[39m(doc)\n\u001b[0;32m 16\u001b[0m entities \u001b[38;5;241m=\u001b[39m ner\u001b[38;5;241m.\u001b[39mextract_entities(text)\n",+ "\u001b[1;31mNameError\u001b[0m: name 'normalized_documents' is not defined"+ ]+ }+ ],"source": ["from semantica.semantic_extract import NamedEntityRecognizer, RelationExtractor, TripletExtractor\n","\n",@@ -560,8 +677,8 @@"resolved_result = resolve_entities(deduplicated_entities, method=\"fuzzy\")\n","resolved_entities = resolved_result.get('entities', deduplicated_entities)\n","\n",- "print(f\"Deduplicated: {len(flat_entities)} \u2192 {len(deduplicated_entities)} entities\")\n",- "print(f\"Resolved: {len(deduplicated_entities)} \u2192 {len(resolved_entities)} entities\")\n",+ "print(f\"Deduplicated: {len(flat_entities)} β {len(deduplicated_entities)} entities\")\n",+ "print(f\"Resolved: {len(deduplicated_entities)} β {len(resolved_entities)} entities\")\n","\n","print(\"Building knowledge graph...\")\n","\n",@@ -1493,9 +1610,9 @@" \n"," print(f\"\\nComplete workflow executed successfully!\")\n"," print(f\"Final Results:\")\n",- " print(f\" Query processed: \u2713\")\n",+ " print(f\" Query processed: β\")\n"," print(f\" Context retrieved: {workflow_result['metrics']['context_items']} items\")\n",- " print(f\" Answer generated: \u2713\")\n",+ " print(f\" Answer generated: β\")\n","else:\n"," print(\"Configure data sources above to run complete workflow with real data\")\n"]@@ -1535,11 +1652,11 @@" print(f\"{feature:<20} {trad:<25} {graph:<25}\")\n","\n","print(\"\\nGraphRAG Advantages:\")\n",- "print(f\" \u2022 Better handling of complex queries requiring relationship understanding\")\n",- "print(f\" \u2022 Multi-hop reasoning across entities\")\n",- "print(f\" \u2022 More accurate answers through structured knowledge\")\n",- "print(f\" \u2022 Better explainability with graph paths\")\n",- "print(f\" \u2022 Reduced hallucinations through graph validation\")\n"+ "print(f\" β’ Better handling of complex queries requiring relationship understanding\")\n",+ "print(f\" β’ Multi-hop reasoning across entities\")\n",+ "print(f\" β’ More accurate answers through structured knowledge\")\n",+ "print(f\" β’ Better explainability with graph paths\")\n",+ "print(f\" β’ Reduced hallucinations through graph validation\")\n"]},{@@ -1599,9 +1716,9 @@"\n","# Save vector store (if supported)\n","print(\"\\nVector Store:\")\n",- "print(f\" Vectors stored: \u2713\")\n",- "print(f\" Metadata stored: \u2713\")\n",- "print(f\" Ready for reuse: \u2713\")\n"+ "print(f\" Vectors stored: β\")\n",+ "print(f\" Metadata stored: β\")\n",+ "print(f\" Ready for reuse: β\")\n"]},{@@ -1683,4 +1800,4 @@},"nbformat": 4,"nbformat_minor": 2-}\ No newline at end of file+}diff --git a/semantica/ingest/repo_ingestor.py b/semantica/ingest/repo_ingestor.pyindex 3b12ed44..0cadb0d9 100644--- a/semantica/ingest/repo_ingestor.py+++ b/semantica/ingest/repo_ingestor.py@@ -519,6 +519,7 @@ class RepoIngestor:- branch: Specific branch to checkout- depth: Clone depth (for shallow clones)- include_history: Whether to include commit history+ - include_extensions: List of file extensions to include (e.g., ["py", "md"])Returns:dict: Processed repository data@@ -532,9 +533,28 @@ class RepoIngestor:)try:+ # Handle option aliases and filters+ if "max_depth" in options and "depth" not in options:+ options["depth"] = options["max_depth"]++ # Separate git clone options from processing options+ # We filter out known non-git options to avoid passing invalid flags to git clone+ non_git_options = {+ "include_history",+ "file_filters",+ "commit_filters",+ "include_extensions",+ "max_depth",+ }+ clone_options = {+ k: v for k, v in options.items() if k not in non_git_options+ }+# Validate repository URLtry:- parsed = git.Repo.clone_from(repo_url, self._get_temp_dir(), **options)+ parsed = git.Repo.clone_from(+ repo_url, self._get_temp_dir(), **clone_options+ )except Exception as e:self.progress_tracker.update_tracking(tracking_id, status="failed", message=str(e)@@ -560,13 +580,21 @@ class RepoIngestor:# Extract repository informationrepo_info = self.get_repository_info(repo_url, repo)+ # Prepare file filters+ file_filters = options.get("file_filters", {}).copy()+ if "include_extensions" in options:+ # Normalize extensions to include dot prefix+ exts = options["include_extensions"]+ normalized_exts = [+ e if e.startswith(".") else f".{e}" for e in exts+ ]+ file_filters["extensions"] = normalized_exts+# Process code filesself.progress_tracker.update_tracking(tracking_id, message="Extracting code files...")- code_files = self.extract_code_files(- repo_path, **options.get("file_filters", {})- )+ code_files = self.extract_code_files(repo_path, **file_filters)# Analyze commits if requestedcommits = []