Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

Improve code quality in cookbook notebooks

KaifAhmad157a1943ba62f
diff --git a/cookbook/advanced/07_Pipeline_Orchestration.ipynb b/cookbook/advanced/07_Pipeline_Orchestration.ipynb
index cf0afab0..2ad77850 100644
--- a/cookbook/advanced/07_Pipeline_Orchestration.ipynb
+++ b/cookbook/advanced/07_Pipeline_Orchestration.ipynb
@@ -121,10 +121,8 @@
" on_error=\"skip\"\n",
")\n",
"\n",
- "try:\n",
- " results = engine.execute(pipeline_with_error_handling, input_data)\n",
- "except Exception as e:\n",
- " print(f\"Error handled gracefully: {e}\")\n"
+ "results = engine.execute(pipeline_with_error_handling, input_data)\n",
+ "print(\"Pipeline executed successfully with error handling configured\")\n"
]
},
{
diff --git a/cookbook/introduction/05_Data_Normalization.ipynb b/cookbook/introduction/05_Data_Normalization.ipynb
index 5fa2f43a..92c15aa8 100644
--- a/cookbook/introduction/05_Data_Normalization.ipynb
+++ b/cookbook/introduction/05_Data_Normalization.ipynb
@@ -108,11 +108,8 @@
"date_formats = [\"2023-12-25\", \"12/25/2023\", \"December 25, 2023\", \"25 Dec 2023\"]\n",
"\n",
"for date_str in date_formats:\n",
- " try:\n",
- " normalized = date_normalizer.normalize_date(date_str)\n",
- " print(f\"{date_str} -> {normalized}\")\n",
- " except Exception as e:\n",
- " print(f\"{date_str} -> Error: {e}\")\n"
+ " normalized = date_normalizer.normalize_date(date_str)\n",
+ " print(f\"{date_str} -> {normalized}\")\n"
]
},
{
@@ -137,11 +134,8 @@
"numbers = [\"1,000\", \"1.5M\", \"$100\", \"50%\", \"3.14e2\"]\n",
"\n",
"for num_str in numbers:\n",
- " try:\n",
- " normalized = number_normalizer.normalize_number(num_str)\n",
- " print(f\"{num_str} -> {normalized}\")\n",
- " except Exception as e:\n",
- " print(f\"{num_str} -> Error: {e}\")\n"
+ " normalized = number_normalizer.normalize_number(num_str)\n",
+ " print(f\"{num_str} -> {normalized}\")\n"
]
},
{
diff --git a/cookbook/introduction/09_Your_First_Knowledge_Graph.ipynb b/cookbook/introduction/09_Your_First_Knowledge_Graph.ipynb
index 2b252c9b..236f0550 100644
--- a/cookbook/introduction/09_Your_First_Knowledge_Graph.ipynb
+++ b/cookbook/introduction/09_Your_First_Knowledge_Graph.ipynb
@@ -83,12 +83,10 @@
"print(f\"Content length: {len(sample_text)} characters\")\n",
"\n",
"# Ingest the file\n",
- "try:\n",
- " file_object = ingestor.ingest_file(sample_file, read_content=True)\n",
- " print(f\" File name: {file_object.name}\")\n",
- " print(f\" File type: {file_object.file_type}\")\n",
- " print(f\" Content available: {file_object.content is not None}\")\n",
- "except Exception as e:\n"
+ "file_object = ingestor.ingest_file(sample_file, read_content=True)\n",
+ "print(f\" File name: {file_object.name}\")\n",
+ "print(f\" File type: {file_object.file_type}\")\n",
+ "print(f\" Content available: {file_object.content is not None}\")\n"
]
},
{
@@ -110,18 +108,10 @@
"\n",
"parser = DocumentParser()\n",
"\n",
- "try:\n",
- " # Parse the document to extract text\n",
- " if 'file_object' in locals():\n",
- " parsed_content = parser.parse_document(str(sample_file))\n",
- " print(f\" Parsed content length: {len(parsed_content) if parsed_content else 0} characters\")\n",
- " print(f\" Preview: {parsed_content[:200] if parsed_content else 'N/A'}...\")\n",
- " else:\n",
- " # Fallback if ingestion failed\n",
- " parsed_content = parser.parse_document(str(sample_file))\n",
- " print(f\" Parsed content length: {len(parsed_content) if parsed_content else 0} characters\")\n",
- "except Exception as e:\n",
- " parsed_content = sample_text\n"
+ "# Parse the document to extract text\n",
+ "parsed_content = parser.parse_document(str(sample_file))\n",
+ "print(f\" Parsed content length: {len(parsed_content) if parsed_content else 0} characters\")\n",
+ "print(f\" Preview: {parsed_content[:200] if parsed_content else 'N/A'}...\")\n"
]
},
{
@@ -144,28 +134,24 @@
"source": [
"from semantica.semantic_extract import NamedEntityRecognizer, NERExtractor\n",
"\n",
- "try:\n",
- " ner = NamedEntityRecognizer()\n",
- " extractor = NERExtractor()\n",
- " \n",
- " print(f\"\\nText: {parsed_content[:100]}...\")\n",
- " \n",
- " # Simulated extraction results\n",
- " expected_entities = [\n",
- " {\"text\": \"Apple Inc.\", \"type\": \"Organization\", \"start\": 0, \"end\": 10},\n",
- " {\"text\": \"Steve Jobs\", \"type\": \"Person\", \"start\": 50, \"end\": 60},\n",
- " {\"text\": \"Steve Wozniak\", \"type\": \"Person\", \"start\": 62, \"end\": 75},\n",
- " {\"text\": \"Ronald Wayne\", \"type\": \"Person\", \"start\": 81, \"end\": 93},\n",
- " {\"text\": \"1976\", \"type\": \"Date\", \"start\": 97, \"end\": 101},\n",
- " {\"text\": \"Cupertino, California\", \"type\": \"Location\", \"start\": 130, \"end\": 151},\n",
- " {\"text\": \"Tim Cook\", \"type\": \"Person\", \"start\": 153, \"end\": 161},\n",
- " ]\n",
- " \n",
- " for entity in expected_entities:\n",
- " print(f\" - {entity['text']} ({entity['type']})\")\n",
- " \n",
- "except Exception as e:\n",
- " expected_entities = []\n"
+ "ner = NamedEntityRecognizer()\n",
+ "extractor = NERExtractor()\n",
+ "\n",
+ "print(f\"\\nText: {parsed_content[:100]}...\")\n",
+ "\n",
+ "# Simulated extraction results\n",
+ "expected_entities = [\n",
+ " {\"text\": \"Apple Inc.\", \"type\": \"Organization\", \"start\": 0, \"end\": 10},\n",
+ " {\"text\": \"Steve Jobs\", \"type\": \"Person\", \"start\": 50, \"end\": 60},\n",
+ " {\"text\": \"Steve Wozniak\", \"type\": \"Person\", \"start\": 62, \"end\": 75},\n",
+ " {\"text\": \"Ronald Wayne\", \"type\": \"Person\", \"start\": 81, \"end\": 93},\n",
+ " {\"text\": \"1976\", \"type\": \"Date\", \"start\": 97, \"end\": 101},\n",
+ " {\"text\": \"Cupertino, California\", \"type\": \"Location\", \"start\": 130, \"end\": 151},\n",
+ " {\"text\": \"Tim Cook\", \"type\": \"Person\", \"start\": 153, \"end\": 161},\n",
+ "]\n",
+ "\n",
+ "for entity in expected_entities:\n",
+ " print(f\" - {entity['text']} ({entity['type']})\")\n"
]
},
{
@@ -203,32 +189,28 @@
" {\"source\": \"entity_6\", \"target\": \"entity_0\", \"type\": \"ceo_of\"},\n",
"]\n",
"\n",
- "try:\n",
- " # Build the graph using NetworkX\n",
- " kg = nx.DiGraph()\n",
- " \n",
- " for entity in entities_data:\n",
- " kg.add_node(entity[\"id\"], name=entity[\"name\"], type=entity[\"type\"])\n",
- " \n",
- " for rel in relationships_data:\n",
- " source_name = entities_data[int(rel[\"source\"].split(\"_\")[1])][\"name\"]\n",
- " target_name = entities_data[int(rel[\"target\"].split(\"_\")[1])][\"name\"]\n",
- " kg.add_edge(rel[\"source\"], rel[\"target\"], type=rel[\"type\"])\n",
- " \n",
- " print(f\" Nodes (entities): {len(kg.nodes)}\")\n",
- " print(f\" Edges (relationships): {len(kg.edges)}\")\n",
- " \n",
- " for node_id in kg.nodes():\n",
- " node_data = kg.nodes[node_id]\n",
- " print(f\" Node: {node_data['name']} ({node_data['type']})\")\n",
- " \n",
- " for source, target, data in kg.edges(data=True):\n",
- " source_name = kg.nodes[source]['name']\n",
- " target_name = kg.nodes[target]['name']\n",
- " print(f\" {source_name} --[{data['type']}]--> {target_name}\")\n",
- " \n",
- "except Exception as e:\n",
- " kg = None\n"
+ "# Build the graph using NetworkX\n",
+ "kg = nx.DiGraph()\n",
+ "\n",
+ "for entity in entities_data:\n",
+ " kg.add_node(entity[\"id\"], name=entity[\"name\"], type=entity[\"type\"])\n",
+ "\n",
+ "for rel in relationships_data:\n",
+ " source_name = entities_data[int(rel[\"source\"].split(\"_\")[1])][\"name\"]\n",
+ " target_name = entities_data[int(rel[\"target\"].split(\"_\")[1])][\"name\"]\n",
+ " kg.add_edge(rel[\"source\"], rel[\"target\"], type=rel[\"type\"])\n",
+ "\n",
+ "print(f\" Nodes (entities): {len(kg.nodes)}\")\n",
+ "print(f\" Edges (relationships): {len(kg.edges)}\")\n",
+ "\n",
+ "for node_id in kg.nodes():\n",
+ " node_data = kg.nodes[node_id]\n",
+ " print(f\" Node: {node_data['name']} ({node_data['type']})\")\n",
+ "\n",
+ "for source, target, data in kg.edges(data=True):\n",
+ " source_name = kg.nodes[source]['name']\n",
+ " target_name = kg.nodes[target]['name']\n",
+ " print(f\" {source_name} --[{data['type']}]--> {target_name}\")\n"
]
},
{
@@ -248,40 +230,30 @@
"source": [
"from semantica.visualization import KGVisualizer\n",
"\n",
- "try:\n",
- " if kg is not None:\n",
- " visualizer = KGVisualizer()\n",
- " \n",
- " print(f\" Total entities: {len(kg.nodes)}\")\n",
- " print(f\" Total relationships: {len(kg.edges)}\")\n",
- " \n",
- " entity_types = {}\n",
- " for node_id in kg.nodes():\n",
- " entity_type = kg.nodes[node_id]['type']\n",
- " entity_types[entity_type] = entity_types.get(entity_type, 0) + 1\n",
- " \n",
- " for etype, count in entity_types.items():\n",
- " print(f\" - {etype}: {count}\")\n",
- " \n",
- " rel_types = {}\n",
- " for _, _, data in kg.edges(data=True):\n",
- " rel_type = data.get('type', 'unknown')\n",
- " rel_types[rel_type] = rel_types.get(rel_type, 0) + 1\n",
- " \n",
- " for rtype, count in rel_types.items():\n",
- " print(f\" - {rtype}: {count}\")\n",
- " \n",
- " \n",
- " else:\n",
- " \n",
- "except Exception as e:\n",
+ "visualizer = KGVisualizer()\n",
+ "\n",
+ "print(f\" Total entities: {len(kg.nodes)}\")\n",
+ "print(f\" Total relationships: {len(kg.edges)}\")\n",
+ "\n",
+ "entity_types = {}\n",
+ "for node_id in kg.nodes():\n",
+ " entity_type = kg.nodes[node_id]['type']\n",
+ " entity_types[entity_type] = entity_types.get(entity_type, 0) + 1\n",
+ "\n",
+ "for etype, count in entity_types.items():\n",
+ " print(f\" - {etype}: {count}\")\n",
+ "\n",
+ "rel_types = {}\n",
+ "for _, _, data in kg.edges(data=True):\n",
+ " rel_type = data.get('type', 'unknown')\n",
+ " rel_types[rel_type] = rel_types.get(rel_type, 0) + 1\n",
+ "\n",
+ "for rtype, count in rel_types.items():\n",
+ " print(f\" - {rtype}: {count}\")\n",
"\n",
"# Cleanup\n",
- "try:\n",
- " if sample_file.exists():\n",
- " sample_file.unlink()\n",
- "except:\n",
- " pass\n"
+ "if sample_file.exists():\n",
+ " sample_file.unlink()\n"
]
}
],
diff --git a/cookbook/use_cases/biomedical/01_Drug_Discovery_Pipeline.ipynb b/cookbook/use_cases/biomedical/01_Drug_Discovery_Pipeline.ipynb
index 12c70d38..bc2ad34a 100644
--- a/cookbook/use_cases/biomedical/01_Drug_Discovery_Pipeline.ipynb
+++ b/cookbook/use_cases/biomedical/01_Drug_Discovery_Pipeline.ipynb
@@ -176,75 +176,70 @@
"parsed_drug = structured_parser.parse_json(json.dumps(drug_data))\n",
"\n",
"# Ingest from drug APIs (example with public API)\n",
- "try:\n",
- " web_content = web_ingestor.ingest_url(drug_apis[0]) # PubChem API\n",
- " if web_content:\n",
- "except Exception as e:\n",
- " print(f\"⚠ Web ingestion (example): {str(e)[:100]}\")\n",
+ "web_content = web_ingestor.ingest_url(drug_apis[0]) # PubChem API\n",
+ "if web_content:\n",
+ " print(f\" Ingested drug API: {drug_apis[0]}\")\n",
"\n",
"# Database ingestion pattern\n",
- "try:\n",
- " db_data = db_ingestor.export_table(\n",
- " connection_string=db_connection_string,\n",
- " table_name=\"drug_target_interactions\",\n",
- " limit=1000\n",
- " )\n",
- " print(f\" Query pattern: {db_query}\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ Database connection (example pattern): Configure with real credentials\")\n",
- " db_data = {\"data\": drug_data}\n",
+ "db_data = db_ingestor.export_table(\n",
+ " connection_string=db_connection_string,\n",
+ " table_name=\"drug_target_interactions\",\n",
+ " limit=1000\n",
+ ")\n",
+ "print(f\" Query pattern: {db_query}\")\n",
"\n",
"# Optional: Ingest from MCP server\n",
"# Users can bring their own drug/protein database MCP server via URL\n",
"mcp_drug_data = []\n",
- "try:\n",
- " # Connect to biomedical database MCP server via URL\n",
- " # Example: http://localhost:8000/mcp or https://api.example.com/biomedical-mcp\n",
- " biomedical_mcp_url = \"http://localhost:8000/mcp\" # Replace with your MCP server URL\n",
- " \n",
- " mcp_ingestor.connect(\n",
- " \"biomedical_mcp_server\",\n",
- " url=biomedical_mcp_url,\n",
- " headers={\n",
- " \"Authorization\": \"Bearer your_token\",\n",
- " \"X-API-Key\": \"your_api_key\"\n",
- " } if \"api.example.com\" in biomedical_mcp_url else {}\n",
- " )\n",
- " \n",
- " # Ingest drug-target interactions from MCP server\n",
- " mcp_data = mcp_ingestor.ingest_resources(\n",
- " \"biomedical_mcp_server\",\n",
- " resource_uris=[\"resource://drugs/interactions\", \"resource://proteins/targets\"]\n",
- " )\n",
- " mcp_drug_data.extend(mcp_data)\n",
- " \n",
- " # Or use tool-based ingestion to query drug interactions\n",
- " tool_data = mcp_ingestor.ingest_tool_output(\n",
- " \"biomedical_mcp_server\",\n",
- " tool_name=\"query_drug_interactions\",\n",
- " arguments={\n",
- " \"compound_id\": \"CID2244\",\n",
- " \"target_protein\": \"PTGS1\"\n",
- " }\n",
- " )\n",
- " if tool_data:\n",
- " mcp_drug_data.append(tool_data)\n",
- " \n",
- " # Parse MCP responses and merge with existing drug data\n",
- " for mcp_item in mcp_drug_data:\n",
- " parsed_mcp = mcp_parser.parse_response(mcp_item, response_type=\"json\")\n",
- " if isinstance(parsed_mcp, dict):\n",
- " if \"drug_targets\" in parsed_mcp or \"interactions\" in parsed_mcp:\n",
- " # Merge drug-target interactions from MCP\n",
- " mcp_interactions = parsed_mcp.get(\"drug_targets\", parsed_mcp.get(\"interactions\", []))\n",
- " drug_data.extend(mcp_interactions)\n",
- " elif \"compound_id\" in parsed_mcp:\n",
- " # Single drug-target interaction\n",
- " drug_data.append(parsed_mcp)\n",
- " \n",
- " mcp_ingestor.disconnect(\"biomedical_mcp_server\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ MCP ingestion skipped: {e}\")\n",
+ "# Connect to biomedical database MCP server via URL\n",
+ "# Example: http://localhost:8000/mcp or https://api.example.com/biomedical-mcp\n",
+ "biomedical_mcp_url = \"http://localhost:8000/mcp\" # Replace with your MCP server URL\n",
+ "\n",
+ "mcp_ingestor.connect(\n",
+ " \"biomedical_mcp_server\",\n",
+ " url=biomedical_mcp_url,\n",
+ " headers={\n",
+ " \"Authorization\": \"Bearer your_token\",\n",
+ " \"X-API-Key\": \"your_api_key\"\n",
+ " } if \"api.example.com\" in biomedical_mcp_url else {}\n",
+ ")\n",
+ "\n",
+ "# Ingest drug-target interactions from MCP server\n",
+ "mcp_data = mcp_ingestor.ingest_resources(\n",
+ " \"biomedical_mcp_server\",\n",
+ " resource_uris=[\"resource://drugs/interactions\", \"resource://proteins/targets\"]\n",
+ ")\n",
+ "mcp_drug_data.extend(mcp_data)\n",
+ "print(f\" Ingested {len(mcp_data)} MCP resources\")\n",
+ "\n",
+ "# Or use tool-based ingestion to query drug interactions\n",
+ "tool_data = mcp_ingestor.ingest_tool_output(\n",
+ " \"biomedical_mcp_server\",\n",
+ " tool_name=\"query_drug_interactions\",\n",
+ " arguments={\n",
+ " \"compound_id\": \"CID2244\",\n",
+ " \"target_protein\": \"PTGS1\"\n",
+ " }\n",
+ ")\n",
+ "if tool_data:\n",
+ " mcp_drug_data.append(tool_data)\n",
+ " print(f\" Retrieved tool data\")\n",
+ "\n",
+ "# Parse MCP responses and merge with existing drug data\n",
+ "for mcp_item in mcp_drug_data:\n",
+ " parsed_mcp = mcp_parser.parse_response(mcp_item, response_type=\"json\")\n",
+ " if isinstance(parsed_mcp, dict):\n",
+ " if \"drug_targets\" in parsed_mcp or \"interactions\" in parsed_mcp:\n",
+ " # Merge drug-target interactions from MCP\n",
+ " mcp_interactions = parsed_mcp.get(\"drug_targets\", parsed_mcp.get(\"interactions\", []))\n",
+ " drug_data.extend(mcp_interactions)\n",
+ " elif \"compound_id\" in parsed_mcp:\n",
+ " # Single drug-target interaction\n",
+ " drug_data.append(parsed_mcp)\n",
+ " print(f\" Parsed MCP item\")\n",
+ "\n",
+ "mcp_ingestor.disconnect(\"biomedical_mcp_server\")\n",
+ "print(f\" Disconnected from MCP server\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Local drug-target interactions: {len(drug_data)}\")\n",
diff --git a/cookbook/use_cases/biomedical/02_Genomic_Variant_Analysis.ipynb b/cookbook/use_cases/biomedical/02_Genomic_Variant_Analysis.ipynb
index 41590ec4..98dbd78c 100644
--- a/cookbook/use_cases/biomedical/02_Genomic_Variant_Analysis.ipynb
+++ b/cookbook/use_cases/biomedical/02_Genomic_Variant_Analysis.ipynb
@@ -189,33 +189,25 @@
"parsed_genomic = structured_parser.parse_json(json.dumps(genomic_data))\n",
"\n",
"# Ingest from genomic APIs (example with public API)\n",
- "try:\n",
- " web_content = web_ingestor.ingest_url(genomic_apis[0]) # Ensembl API\n",
- " if web_content:\n",
- "except Exception as e:\n",
- " print(f\"⚠ Web ingestion (example): {str(e)[:100]}\")\n",
+ "web_content = web_ingestor.ingest_url(genomic_apis[0]) # Ensembl API\n",
+ "if web_content:\n",
+ " print(f\" Ingested genomic API: {genomic_apis[0]}\")\n",
"\n",
"# Ingest from genomic feeds\n",
"feed_data_list = []\n",
"for feed_url in genomic_feeds:\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " feed_data_list.append(feed_data)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion failed for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " feed_data_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
"\n",
"# Database ingestion pattern\n",
- "try:\n",
- " db_data = db_ingestor.export_table(\n",
- " connection_string=db_connection_string,\n",
- " table_name=\"variants\",\n",
- " limit=1000\n",
- " )\n",
- " print(f\" Query pattern: {db_query}\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ Database connection (example pattern): Configure with real credentials\")\n",
- " db_data = {\"data\": genomic_data}\n",
+ "db_data = db_ingestor.export_table(\n",
+ " connection_string=db_connection_string,\n",
+ " table_name=\"variants\",\n",
+ " limit=1000\n",
+ ")\n",
+ "print(f\" Query pattern: {db_query}\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Local variants: {len(genomic_data)}\")\n",
diff --git a/cookbook/use_cases/blockchain/01_DeFi_Protocol_Intelligence.ipynb b/cookbook/use_cases/blockchain/01_DeFi_Protocol_Intelligence.ipynb
index d94856bf..154bad55 100644
--- a/cookbook/use_cases/blockchain/01_DeFi_Protocol_Intelligence.ipynb
+++ b/cookbook/use_cases/blockchain/01_DeFi_Protocol_Intelligence.ipynb
@@ -164,33 +164,25 @@
"parsed_defi = structured_parser.parse_json(json.dumps(defi_data))\n",
"\n",
"# Ingest from DeFi APIs (example with public API)\n",
- "try:\n",
- " web_content = web_ingestor.ingest_url(defi_apis[2]) # GitHub API\n",
- " if web_content:\n",
- "except Exception as e:\n",
- " print(f\"⚠ Web ingestion (example): {str(e)[:100]}\")\n",
+ "web_content = web_ingestor.ingest_url(defi_apis[2]) # GitHub API\n",
+ "if web_content:\n",
+ " print(f\" Ingested DeFi API: {defi_apis[2]}\")\n",
"\n",
"# Ingest from DeFi feeds\n",
"feed_data_list = []\n",
"for feed_url in defi_feeds:\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " feed_data_list.append(feed_data)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion failed for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " feed_data_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
"\n",
"# Database ingestion pattern\n",
- "try:\n",
- " db_data = db_ingestor.export_table(\n",
- " connection_string=db_connection_string,\n",
- " table_name=\"defi_protocols\",\n",
- " limit=1000\n",
- " )\n",
- " print(f\" Query pattern: {db_query}\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ Database connection (example pattern): Configure with real credentials\")\n",
- " db_data = {\"data\": defi_data}\n",
+ "db_data = db_ingestor.export_table(\n",
+ " connection_string=db_connection_string,\n",
+ " table_name=\"defi_protocols\",\n",
+ " limit=1000\n",
+ ")\n",
+ "print(f\" Query pattern: {db_query}\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Local protocols: {len(defi_data)}\")\n",
diff --git a/cookbook/use_cases/blockchain/02_Transaction_Network_Analysis.ipynb b/cookbook/use_cases/blockchain/02_Transaction_Network_Analysis.ipynb
index ea4f2215..cf0b6a8f 100644
--- a/cookbook/use_cases/blockchain/02_Transaction_Network_Analysis.ipynb
+++ b/cookbook/use_cases/blockchain/02_Transaction_Network_Analysis.ipynb
@@ -164,23 +164,17 @@
"parsed_transactions = structured_parser.parse_json(json.dumps(transaction_data))\n",
"\n",
"# Ingest from blockchain APIs (example with public API)\n",
- "try:\n",
- " web_content = web_ingestor.ingest_url(blockchain_apis[2]) # CoinGecko public API\n",
- " if web_content:\n",
- "except Exception as e:\n",
- " print(f\"⚠ Web ingestion (example): {str(e)[:100]}\")\n",
+ "web_content = web_ingestor.ingest_url(blockchain_apis[2]) # CoinGecko public API\n",
+ "if web_content:\n",
+ " print(f\" Ingested blockchain API: {blockchain_apis[2]}\")\n",
"\n",
"# Database ingestion pattern (would connect to real database)\n",
- "try:\n",
- " db_data = db_ingestor.export_table(\n",
- " connection_string=db_connection_string,\n",
- " table_name=\"transactions\",\n",
- " limit=10000\n",
- " )\n",
- " print(f\" Query pattern: {db_query}\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ Database connection (example pattern): Configure with real credentials\")\n",
- " db_data = {\"data\": transaction_data}\n",
+ "db_data = db_ingestor.export_table(\n",
+ " connection_string=db_connection_string,\n",
+ " table_name=\"transactions\",\n",
+ " limit=10000\n",
+ ")\n",
+ "print(f\" Query pattern: {db_query}\")\n",
"\n",
"# Streaming ingestion pattern\n",
"for stream_source in stream_sources:\n",
diff --git a/cookbook/use_cases/cybersecurity/02_Incident_Analysis.ipynb b/cookbook/use_cases/cybersecurity/02_Incident_Analysis.ipynb
index 7fbce4b1..d5c24e7c 100644
--- a/cookbook/use_cases/cybersecurity/02_Incident_Analysis.ipynb
+++ b/cookbook/use_cases/cybersecurity/02_Incident_Analysis.ipynb
@@ -157,12 +157,10 @@
"\n",
"threat_feed_list = []\n",
"for feed_url in security_feeds:\n",
- " try:\n",
- " threat_feed = feed_ingestor.ingest_feed(feed_url)\n",
- " if threat_feed:\n",
- " threat_feed_list.append(threat_feed)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " threat_feed = feed_ingestor.ingest_feed(feed_url)\n",
+ " if threat_feed:\n",
+ " threat_feed_list.append(threat_feed)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
"\n",
"print(f\"Ingested {len([file_objects]) if file_objects else 0} JSON log files\")\n",
"print(f\"Ingested {len([file_objects_xml]) if file_objects_xml else 0} XML event files\")\n",
diff --git a/cookbook/use_cases/cybersecurity/03_Threat_Correlation.ipynb b/cookbook/use_cases/cybersecurity/03_Threat_Correlation.ipynb
index 01c5a6a7..0c9124c6 100644
--- a/cookbook/use_cases/cybersecurity/03_Threat_Correlation.ipynb
+++ b/cookbook/use_cases/cybersecurity/03_Threat_Correlation.ipynb
@@ -99,33 +99,27 @@
"# Ingest from real RSS feeds\n",
"feed_data_list = []\n",
"for feed_url in threat_feeds:\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " feed_data_list.append(feed_data)\n",
- " print(f\" Items: {len(feed_data.items) if hasattr(feed_data, 'items') else 0}\")\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion failed for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " feed_data_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
+ " print(f\" Items: {len(feed_data.items) if hasattr(feed_data, 'items') else 0}\")\n",
"\n",
"# Ingest from web APIs (example with public API)\n",
- "try:\n",
- " web_content = web_ingestor.ingest_url(\"https://api.github.com/repos/mitre/cti\")\n",
- " if web_content:\n",
- "except Exception as e:\n",
- " print(f\"⚠ Web ingestion (example): {str(e)[:100]}\")\n",
+ "web_content = web_ingestor.ingest_url(\"https://api.github.com/repos/mitre/cti\")\n",
+ "if web_content:\n",
+ " print(f\" Ingested web content\")\n",
"\n",
"# Database ingestion pattern (would connect to real database)\n",
- "try:\n",
- " # Example: Export from threat intelligence database\n",
- " db_data = db_ingestor.export_table(\n",
- " connection_string=db_connection_string,\n",
- " table_name=\"threat_indicators\",\n",
- " limit=1000\n",
- " )\n",
- " print(f\" Query pattern: {db_query}\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ Database connection (example pattern): Configure with real credentials\")\n",
- " # Simulate database structure for demonstration\n",
+ "# Example: Export from threat intelligence database\n",
+ "db_data = db_ingestor.export_table(\n",
+ " connection_string=db_connection_string,\n",
+ " table_name=\"threat_indicators\",\n",
+ " limit=1000\n",
+ ")\n",
+ "print(f\" Query pattern: {db_query}\")\n",
+ "# Simulate database structure for demonstration if needed\n",
+ "if not db_data:\n",
" db_data = {\n",
" \"data\": [\n",
" {\"ioc\": \"192.168.1.100\", \"ioc_type\": \"IP\", \"timestamp\": datetime.now().isoformat(), \"severity\": \"high\", \"source\": \"threat_feed\"},\n",
diff --git a/cookbook/use_cases/cybersecurity/04_Threat_Intelligence_Hybrid_RAG.ipynb b/cookbook/use_cases/cybersecurity/04_Threat_Intelligence_Hybrid_RAG.ipynb
index 7642716a..209c4660 100644
--- a/cookbook/use_cases/cybersecurity/04_Threat_Intelligence_Hybrid_RAG.ipynb
+++ b/cookbook/use_cases/cybersecurity/04_Threat_Intelligence_Hybrid_RAG.ipynb
@@ -161,13 +161,11 @@
"\n",
"threat_feed_list = []\n",
"for feed_url in threat_intel_feeds:\n",
- " try:\n",
- " threat_feed = feed_ingestor.ingest_feed(feed_url)\n",
- " if threat_feed:\n",
- " threat_feed_list.append(threat_feed)\n",
- " print(f\" Items: {len(threat_feed.items) if hasattr(threat_feed, 'items') else 0}\")\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " threat_feed = feed_ingestor.ingest_feed(feed_url)\n",
+ " if threat_feed:\n",
+ " threat_feed_list.append(threat_feed)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
+ " print(f\" Items: {len(threat_feed.items) if hasattr(threat_feed, 'items') else 0}\")\n",
"\n",
"# Real web sources for threat intelligence\n",
"threat_web_sources = [\n",
@@ -178,72 +176,71 @@
"\n",
"web_content_list = []\n",
"for web_url in threat_web_sources[:1]: # Process first URL\n",
- " try:\n",
- " web_content = web_ingestor.ingest_url(web_url)\n",
- " if web_content:\n",
- " web_content_list.append(web_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Web ingestion for {web_url}: {str(e)[:100]}\")\n",
+ " web_content = web_ingestor.ingest_url(web_url)\n",
+ " if web_content:\n",
+ " web_content_list.append(web_content)\n",
+ " print(f\" Ingested web source: {web_url}\")\n",
"\n",
"# Optional: Ingest from MCP server\n",
"# Users can bring their own threat intelligence MCP server via URL\n",
"mcp_threat_data = []\n",
- "try:\n",
- " # Connect to threat intelligence MCP server via URL\n",
- " # Example: http://localhost:8000/mcp or https://api.example.com/threat-mcp\n",
- " threat_mcp_url = \"http://localhost:8000/mcp\" # Replace with your MCP server URL\n",
- " \n",
- " mcp_ingestor.connect(\n",
- " \"threat_mcp_server\",\n",
- " url=threat_mcp_url,\n",
- " headers={\n",
- " \"Authorization\": \"Bearer your_token\",\n",
- " \"X-API-Key\": \"your_api_key\"\n",
- " } if \"api.example.com\" in threat_mcp_url else {}\n",
- " )\n",
- " \n",
- " # Ingest threat indicators from MCP server\n",
- " mcp_data = mcp_ingestor.ingest_resources(\n",
- " \"threat_mcp_server\",\n",
- " resource_uris=[\"resource://threats/feed\", \"resource://vulnerabilities/database\"]\n",
- " )\n",
- " mcp_threat_data.extend(mcp_data)\n",
- " \n",
- " # Or use tool-based ingestion to query threat indicators\n",
- " tool_data = mcp_ingestor.ingest_tool_output(\n",
- " \"threat_mcp_server\",\n",
- " tool_name=\"query_threat_indicators\",\n",
- " arguments={\n",
- " \"indicator_type\": \"IP\",\n",
- " \"date_range\": {\n",
- " \"start\": (datetime.now() - timedelta(days=7)).isoformat(),\n",
- " \"end\": datetime.now().isoformat()\n",
- " }\n",
+ "# Connect to threat intelligence MCP server via URL\n",
+ "# Example: http://localhost:8000/mcp or https://api.example.com/threat-mcp\n",
+ "threat_mcp_url = \"http://localhost:8000/mcp\" # Replace with your MCP server URL\n",
+ "\n",
+ "mcp_ingestor.connect(\n",
+ " \"threat_mcp_server\",\n",
+ " url=threat_mcp_url,\n",
+ " headers={\n",
+ " \"Authorization\": \"Bearer your_token\",\n",
+ " \"X-API-Key\": \"your_api_key\"\n",
+ " } if \"api.example.com\" in threat_mcp_url else {}\n",
+ ")\n",
+ "\n",
+ "# Ingest threat indicators from MCP server\n",
+ "mcp_data = mcp_ingestor.ingest_resources(\n",
+ " \"threat_mcp_server\",\n",
+ " resource_uris=[\"resource://threats/feed\", \"resource://vulnerabilities/database\"]\n",
+ ")\n",
+ "mcp_threat_data.extend(mcp_data)\n",
+ "print(f\" Ingested MCP resources: {len(mcp_data)}\")\n",
+ "\n",
+ "# Or use tool-based ingestion to query threat indicators\n",
+ "tool_data = mcp_ingestor.ingest_tool_output(\n",
+ " \"threat_mcp_server\",\n",
+ " tool_name=\"query_threat_indicators\",\n",
+ " arguments={\n",
+ " \"indicator_type\": \"IP\",\n",
+ " \"date_range\": {\n",
+ " \"start\": (datetime.now() - timedelta(days=7)).isoformat(),\n",
+ " \"end\": datetime.now().isoformat()\n",
" }\n",
- " )\n",
- " if tool_data:\n",
- " mcp_threat_data.append(tool_data)\n",
- " \n",
- " # Parse MCP responses and merge with existing threat data\n",
- " for mcp_item in mcp_threat_data:\n",
- " parsed_mcp = mcp_parser.parse_response(mcp_item, response_type=\"json\")\n",
- " if isinstance(parsed_mcp, dict):\n",
- " if \"threat_indicators\" in parsed_mcp:\n",
- " # Merge threat indicators from MCP\n",
- " if parsed_json and parsed_json.data:\n",
- " parsed_json.data.extend(parsed_mcp.get(\"threat_indicators\", []))\n",
- " else:\n",
- " parsed_json.data = parsed_mcp.get(\"threat_indicators\", [])\n",
- " elif \"threat_id\" in parsed_mcp:\n",
- " # Single threat indicator\n",
- " if parsed_json and parsed_json.data:\n",
- " parsed_json.data.append(parsed_mcp)\n",
- " else:\n",
- " parsed_json.data = [parsed_mcp]\n",
- " \n",
- " mcp_ingestor.disconnect(\"threat_mcp_server\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ MCP ingestion skipped: {e}\")\n",
+ " }\n",
+ ")\n",
+ "if tool_data:\n",
+ " mcp_threat_data.append(tool_data)\n",
+ " print(f\" Retrieved tool data\")\n",
+ "\n",
+ "# Parse MCP responses and merge with existing threat data\n",
+ "for mcp_item in mcp_threat_data:\n",
+ " parsed_mcp = mcp_parser.parse_response(mcp_item, response_type=\"json\")\n",
+ " if isinstance(parsed_mcp, dict):\n",
+ " if \"threat_indicators\" in parsed_mcp:\n",
+ " # Merge threat indicators from MCP\n",
+ " if parsed_json and parsed_json.data:\n",
+ " parsed_json.data.extend(parsed_mcp.get(\"threat_indicators\", []))\n",
+ " else:\n",
+ " parsed_json.data = parsed_mcp.get(\"threat_indicators\", [])\n",
+ " elif \"threat_id\" in parsed_mcp:\n",
+ " # Single threat indicator\n",
+ " if parsed_json and parsed_json.data:\n",
+ " parsed_json.data.append(parsed_mcp)\n",
+ " else:\n",
+ " parsed_json.data = [parsed_mcp]\n",
+ " print(f\" Parsed MCP item\")\n",
+ "\n",
+ "mcp_ingestor.disconnect(\"threat_mcp_server\")\n",
+ "print(f\" Disconnected from MCP server\")\n",
"\n",
"print(f\"Ingested {len([file_objects_json]) if file_objects_json else 0} JSON threat intelligence files\")\n",
"print(f\"Ingested {len([file_objects_xml]) if file_objects_xml else 0} XML threat intelligence files\")\n",
diff --git a/cookbook/use_cases/cybersecurity/05_Threat_Intelligence_Integration.ipynb b/cookbook/use_cases/cybersecurity/05_Threat_Intelligence_Integration.ipynb
index 972c6aad..639395e3 100644
--- a/cookbook/use_cases/cybersecurity/05_Threat_Intelligence_Integration.ipynb
+++ b/cookbook/use_cases/cybersecurity/05_Threat_Intelligence_Integration.ipynb
@@ -76,33 +76,29 @@
"# Example: http://localhost:8000/mcp or https://api.example.com/threat-mcp\n",
"threat_mcp_url = \"http://localhost:8000/mcp\"\n",
"\n",
- "try:\n",
- " # Connect to MCP server with authentication (if required)\n",
- " mcp_ingestor.connect(\n",
- " \"threat_server\",\n",
- " url=threat_mcp_url,\n",
- " headers={\n",
- " \"Authorization\": \"Bearer your_token\",\n",
- " \"X-API-Key\": \"your_api_key\"\n",
- " } if \"api.example.com\" in threat_mcp_url else {}\n",
- " )\n",
- " \n",
- " # List available resources (threat feeds, vulnerability databases)\n",
- " resources = mcp_ingestor.list_available_resources(\"threat_server\")\n",
- " print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
- " for resource in resources[:5]: # Show first 5\n",
- " print(f\" - {resource.uri}: {resource.name}\")\n",
- " if resource.description:\n",
- " print(f\" {resource.description[:80]}...\")\n",
- " \n",
- " # List available tools (threat queries, IOC checks)\n",
- " tools = mcp_ingestor.list_available_tools(\"threat_server\")\n",
- " print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
- " for tool in tools[:5]: # Show first 5\n",
- " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Connection failed: {e}\")\n"
+ "# Connect to MCP server with authentication (if required)\n",
+ "mcp_ingestor.connect(\n",
+ " \"threat_server\",\n",
+ " url=threat_mcp_url,\n",
+ " headers={\n",
+ " \"Authorization\": \"Bearer your_token\",\n",
+ " \"X-API-Key\": \"your_api_key\"\n",
+ " } if \"api.example.com\" in threat_mcp_url else {}\n",
+ ")\n",
+ "\n",
+ "# List available resources (threat feeds, vulnerability databases)\n",
+ "resources = mcp_ingestor.list_available_resources(\"threat_server\")\n",
+ "print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
+ "for resource in resources[:5]: # Show first 5\n",
+ " print(f\" - {resource.uri}: {resource.name}\")\n",
+ " if resource.description:\n",
+ " print(f\" {resource.description[:80]}...\")\n",
+ "\n",
+ "# List available tools (threat queries, IOC checks)\n",
+ "tools = mcp_ingestor.list_available_tools(\"threat_server\")\n",
+ "print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
+ "for tool in tools[:5]: # Show first 5\n",
+ " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n"
]
},
{
@@ -130,53 +126,47 @@
"\n",
"# Method 1: Resource-based ingestion\n",
"# Ingest from MCP resources (threat feeds, vulnerability databases)\n",
- "try:\n",
- " # Example: Ingest threat feed resource\n",
- " threat_feeds = mcp_ingestor.ingest_resources(\n",
- " \"threat_server\",\n",
- " resource_uris=[\"resource://threats/feed\", \"resource://vulnerabilities/database\"]\n",
- " )\n",
- " \n",
- " for item in threat_feeds:\n",
- " threat_data.append(item)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Resource ingestion: {e}\")\n",
+ "threat_feeds = mcp_ingestor.ingest_resources(\n",
+ " \"threat_server\",\n",
+ " resource_uris=[\"resource://threats/feed\", \"resource://vulnerabilities/database\"]\n",
+ ")\n",
+ "\n",
+ "for item in threat_feeds:\n",
+ " threat_data.append(item)\n",
+ " print(f\" Ingested resource: {item}\")\n",
"\n",
"# Method 2: Tool-based ingestion\n",
"# Call MCP tools to retrieve data dynamically\n",
- "try:\n",
- " # Example: Query threat indicators\n",
- " threat_indicators = mcp_ingestor.ingest_tool_output(\n",
- " \"threat_server\",\n",
- " tool_name=\"query_threat_indicators\",\n",
- " arguments={\n",
- " \"indicator_type\": \"IP\",\n",
- " \"date_range\": {\n",
- " \"start\": (datetime.now() - timedelta(days=7)).isoformat(),\n",
- " \"end\": datetime.now().isoformat()\n",
- " }\n",
- " }\n",
- " )\n",
- " \n",
- " if threat_indicators:\n",
- " threat_data.append(threat_indicators)\n",
- " \n",
- " # Example: Check IOC (Indicators of Compromise)\n",
- " ioc_check = mcp_ingestor.ingest_tool_output(\n",
- " \"threat_server\",\n",
- " tool_name=\"check_ioc\",\n",
- " arguments={\n",
- " \"ioc_type\": \"hash\",\n",
- " \"ioc_value\": \"abc123def456\"\n",
+ "# Example: Query threat indicators\n",
+ "threat_indicators = mcp_ingestor.ingest_tool_output(\n",
+ " \"threat_server\",\n",
+ " tool_name=\"query_threat_indicators\",\n",
+ " arguments={\n",
+ " \"indicator_type\": \"IP\",\n",
+ " \"date_range\": {\n",
+ " \"start\": (datetime.now() - timedelta(days=7)).isoformat(),\n",
+ " \"end\": datetime.now().isoformat()\n",
" }\n",
- " )\n",
- " \n",
- " if ioc_check:\n",
- " threat_data.append(ioc_check)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Tool-based ingestion: {e}\")\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "if threat_indicators:\n",
+ " threat_data.append(threat_indicators)\n",
+ " print(f\" Retrieved threat indicators\")\n",
+ "\n",
+ "# Example: Check IOC (Indicators of Compromise)\n",
+ "ioc_check = mcp_ingestor.ingest_tool_output(\n",
+ " \"threat_server\",\n",
+ " tool_name=\"check_ioc\",\n",
+ " arguments={\n",
+ " \"ioc_type\": \"hash\",\n",
+ " \"ioc_value\": \"abc123def456\"\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "if ioc_check:\n",
+ " threat_data.append(ioc_check)\n",
+ " print(f\" Retrieved IOC check results\")\n",
"\n",
"# Sample threat intelligence data (if MCP server is not available)\n",
"if not threat_data:\n",
@@ -246,17 +236,14 @@
"\n",
"# Parse MCP responses\n",
"for data_item in threat_data:\n",
- " try:\n",
- " # Parse MCP response (handles JSON, XML, text, binary)\n",
- " if isinstance(data_item, dict):\n",
- " parsed_item = data_item\n",
- " else:\n",
- " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
- " \n",
- " parsed_threat_data.append(parsed_item)\n",
- " \n",
- " except Exception as e:\n",
- " print(f\"⚠ Parsing error: {e}\")\n",
+ " # Parse MCP response (handles JSON, XML, text, binary)\n",
+ " if isinstance(data_item, dict):\n",
+ " parsed_item = data_item\n",
+ " else:\n",
+ " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
+ " \n",
+ " parsed_threat_data.append(parsed_item)\n",
+ " print(f\" Parsed data item\")\n",
"\n",
"# Extract threat indicators and vulnerabilities\n",
"threat_indicators = []\n",
@@ -547,10 +534,8 @@
"\n",
"\n",
"# Cleanup: Disconnect from MCP server\n",
- "try:\n",
- " mcp_ingestor.disconnect(\"threat_server\")\n",
- "except:\n",
- " pass\n",
+ "mcp_ingestor.disconnect(\"threat_server\")\n",
+ "print(\" Disconnected from MCP server\")\n",
"\n",
"print(f\"📊 Total modules used: 20+\")\n"
]
diff --git a/cookbook/use_cases/cybersecurity/06_Vulnerability_Tracking.ipynb b/cookbook/use_cases/cybersecurity/06_Vulnerability_Tracking.ipynb
index f897392a..ca0418c2 100644
--- a/cookbook/use_cases/cybersecurity/06_Vulnerability_Tracking.ipynb
+++ b/cookbook/use_cases/cybersecurity/06_Vulnerability_Tracking.ipynb
@@ -108,34 +108,27 @@
"# Ingest from real CVE feeds\n",
"cve_feed_list = []\n",
"for feed_url in vulnerability_feeds:\n",
- " try:\n",
- " cve_feed = feed_ingestor.ingest_feed(feed_url)\n",
- " if cve_feed:\n",
- " cve_feed_list.append(cve_feed)\n",
- " print(f\" Items: {len(cve_feed.items) if hasattr(cve_feed, 'items') else 0}\")\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " cve_feed = feed_ingestor.ingest_feed(feed_url)\n",
+ " if cve_feed:\n",
+ " cve_feed_list.append(cve_feed)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
+ " print(f\" Items: {len(cve_feed.items) if hasattr(cve_feed, 'items') else 0}\")\n",
"\n",
"# Ingest from real CVE APIs\n",
"cve_api_data = []\n",
"for api_url in cve_apis[:1]: # Process first API\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " cve_api_data.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " cve_api_data.append(api_content)\n",
+ " print(f\" Ingested CVE API: {api_url}\")\n",
"\n",
"# Database ingestion pattern\n",
- "try:\n",
- " db_data = db_ingestor.export_table(\n",
- " connection_string=db_connection_string,\n",
- " table_name=\"vulnerabilities\",\n",
- " limit=1000\n",
- " )\n",
- " print(f\" Query pattern: {db_query}\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ Database connection (example pattern): Configure with real credentials\")\n",
+ "db_data = db_ingestor.export_table(\n",
+ " connection_string=db_connection_string,\n",
+ " table_name=\"vulnerabilities\",\n",
+ " limit=1000\n",
+ ")\n",
+ "print(f\" Query pattern: {db_query}\")\n",
"\n",
"print(f\"\\n📊 CVE Ingestion Summary:\")\n",
"print(f\" Vulnerability feeds: {len(cve_feed_list)}\")\n",
diff --git a/cookbook/use_cases/finance/01_Financial_Data_Integration.ipynb b/cookbook/use_cases/finance/01_Financial_Data_Integration.ipynb
index b7fad568..1f8ffed1 100644
--- a/cookbook/use_cases/finance/01_Financial_Data_Integration.ipynb
+++ b/cookbook/use_cases/finance/01_Financial_Data_Integration.ipynb
@@ -75,30 +75,26 @@
"# Example: http://localhost:8000/mcp or https://api.example.com/financial-mcp\n",
"financial_mcp_url = \"http://localhost:8000/mcp\"\n",
"\n",
- "try:\n",
- " # Connect to MCP server\n",
- " mcp_ingestor.connect(\n",
- " \"financial_server\",\n",
- " url=financial_mcp_url,\n",
- " headers={\"Authorization\": \"Bearer your_token\"} if \"api.example.com\" in financial_mcp_url else {}\n",
- " )\n",
- " \n",
- " # List available resources (datasets, market data feeds)\n",
- " resources = mcp_ingestor.list_available_resources(\"financial_server\")\n",
- " print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
- " for resource in resources[:5]: # Show first 5\n",
- " print(f\" - {resource.uri}: {resource.name}\")\n",
- " if resource.description:\n",
- " print(f\" {resource.description[:80]}...\")\n",
- " \n",
- " # List available tools (queries, calculations)\n",
- " tools = mcp_ingestor.list_available_tools(\"financial_server\")\n",
- " print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
- " for tool in tools[:5]: # Show first 5\n",
- " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Connection failed: {e}\")\n"
+ "# Connect to MCP server\n",
+ "mcp_ingestor.connect(\n",
+ " \"financial_server\",\n",
+ " url=financial_mcp_url,\n",
+ " headers={\"Authorization\": \"Bearer your_token\"} if \"api.example.com\" in financial_mcp_url else {}\n",
+ ")\n",
+ "\n",
+ "# List available resources (datasets, market data feeds)\n",
+ "resources = mcp_ingestor.list_available_resources(\"financial_server\")\n",
+ "print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
+ "for resource in resources[:5]: # Show first 5\n",
+ " print(f\" - {resource.uri}: {resource.name}\")\n",
+ " if resource.description:\n",
+ " print(f\" {resource.description[:80]}...\")\n",
+ "\n",
+ "# List available tools (queries, calculations)\n",
+ "tools = mcp_ingestor.list_available_tools(\"financial_server\")\n",
+ "print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
+ "for tool in tools[:5]: # Show first 5\n",
+ " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n"
]
},
{
@@ -125,47 +121,42 @@
"\n",
"# Method 1: Resource-based ingestion\n",
"# Ingest from MCP resources (pre-defined datasets)\n",
- "try:\n",
- " # Example: Ingest market data resource\n",
- " resource_data = mcp_ingestor.ingest_resources(\n",
- " \"financial_server\",\n",
- " resource_uris=[\"resource://market_data/daily\", \"resource://market_data/stocks\"]\n",
- " )\n",
- " \n",
- " for item in resource_data:\n",
- " financial_data.append(item)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Resource ingestion: {e}\")\n",
+ "# Example: Ingest market data resource\n",
+ "resource_data = mcp_ingestor.ingest_resources(\n",
+ " \"financial_server\",\n",
+ " resource_uris=[\"resource://market_data/daily\", \"resource://market_data/stocks\"]\n",
+ ")\n",
+ "\n",
+ "for item in resource_data:\n",
+ " financial_data.append(item)\n",
+ " print(f\" Ingested resource: {item}\")\n",
"\n",
"# Method 2: Tool-based ingestion\n",
"# Call MCP tools to retrieve data dynamically\n",
- "try:\n",
- " # Example: Get stock prices for specific symbols\n",
- " stock_prices = mcp_ingestor.ingest_tool_output(\n",
- " \"financial_server\",\n",
- " tool_name=\"get_stock_prices\",\n",
- " arguments={\n",
- " \"symbols\": [\"AAPL\", \"MSFT\", \"GOOGL\", \"TSLA\"],\n",
- " \"date\": datetime.now().isoformat()\n",
- " }\n",
- " )\n",
- " \n",
- " if stock_prices:\n",
- " financial_data.append(stock_prices)\n",
- " \n",
- " # Example: Get market metrics\n",
- " market_metrics = mcp_ingestor.ingest_tool_output(\n",
- " \"financial_server\",\n",
- " tool_name=\"get_market_metrics\",\n",
- " arguments={\"sector\": \"Technology\"}\n",
- " )\n",
- " \n",
- " if market_metrics:\n",
- " financial_data.append(market_metrics)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Tool-based ingestion: {e}\")\n",
+ "# Example: Get stock prices for specific symbols\n",
+ "stock_prices = mcp_ingestor.ingest_tool_output(\n",
+ " \"financial_server\",\n",
+ " tool_name=\"get_stock_prices\",\n",
+ " arguments={\n",
+ " \"symbols\": [\"AAPL\", \"MSFT\", \"GOOGL\", \"TSLA\"],\n",
+ " \"date\": datetime.now().isoformat()\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "if stock_prices:\n",
+ " financial_data.append(stock_prices)\n",
+ " print(f\" Retrieved stock prices for {len(stock_prices) if isinstance(stock_prices, list) else 1} symbols\")\n",
+ "\n",
+ "# Example: Get market metrics\n",
+ "market_metrics = mcp_ingestor.ingest_tool_output(\n",
+ " \"financial_server\",\n",
+ " tool_name=\"get_market_metrics\",\n",
+ " arguments={\"sector\": \"Technology\"}\n",
+ ")\n",
+ "\n",
+ "if market_metrics:\n",
+ " financial_data.append(market_metrics)\n",
+ " print(f\" Retrieved market metrics\")\n",
"\n",
"# Sample financial data (if MCP server is not available)\n",
"if not financial_data:\n",
@@ -243,19 +234,16 @@
"\n",
"# Parse MCP responses\n",
"for data_item in financial_data:\n",
- " try:\n",
- " # Parse MCP response (handles JSON, text, binary)\n",
- " if isinstance(data_item, dict):\n",
- " # If it's already structured, use it directly\n",
- " parsed_item = data_item\n",
- " else:\n",
- " # Parse using MCP parser\n",
- " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
- " \n",
- " parsed_financial_data.append(parsed_item)\n",
- " \n",
- " except Exception as e:\n",
- " print(f\"⚠ Parsing error: {e}\")\n",
+ " # Parse MCP response (handles JSON, text, binary)\n",
+ " if isinstance(data_item, dict):\n",
+ " # If it's already structured, use it directly\n",
+ " parsed_item = data_item\n",
+ " else:\n",
+ " # Parse using MCP parser\n",
+ " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
+ " \n",
+ " parsed_financial_data.append(parsed_item)\n",
+ " print(f\" Parsed data item\")\n",
"\n",
"# Extract stock prices from parsed data\n",
"stock_prices = []\n",
@@ -515,10 +503,8 @@
"\n",
"\n",
"# Cleanup: Disconnect from MCP server\n",
- "try:\n",
- " mcp_ingestor.disconnect(\"financial_server\")\n",
- "except:\n",
- " pass\n",
+ "mcp_ingestor.disconnect(\"financial_server\")\n",
+ "print(\" Disconnected from MCP server\")\n",
"\n",
"print(f\"📊 Total modules used: 20+\")\n"
]
diff --git a/cookbook/use_cases/finance/02_Financial_Reports_Analysis.ipynb b/cookbook/use_cases/finance/02_Financial_Reports_Analysis.ipynb
index f89dd3d8..6b9d1865 100644
--- a/cookbook/use_cases/finance/02_Financial_Reports_Analysis.ipynb
+++ b/cookbook/use_cases/finance/02_Financial_Reports_Analysis.ipynb
@@ -123,19 +123,15 @@
"# Ingest from financial feeds\n",
"financial_feed_list = []\n",
"for feed_url in financial_feeds[:2]: # Process first 2 feeds\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " financial_feed_list.append(feed_data)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " financial_feed_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
"\n",
"# Ingest from SEC EDGAR (example)\n",
- "try:\n",
- " web_content = web_ingestor.ingest_url(\"https://www.sec.gov/cgi-bin/browse-edgar\")\n",
- " if web_content:\n",
- "except Exception as e:\n",
- " print(f\"⚠ SEC EDGAR ingestion (example): {str(e)[:100]}\")\n",
+ "web_content = web_ingestor.ingest_url(\"https://www.sec.gov/cgi-bin/browse-edgar\")\n",
+ "if web_content:\n",
+ " print(f\" Ingested SEC EDGAR content\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Financial reports ingested: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/finance/04_Investment_Analysis_Hybrid_RAG.ipynb b/cookbook/use_cases/finance/04_Investment_Analysis_Hybrid_RAG.ipynb
index cb9ba13a..b5afba61 100644
--- a/cookbook/use_cases/finance/04_Investment_Analysis_Hybrid_RAG.ipynb
+++ b/cookbook/use_cases/finance/04_Investment_Analysis_Hybrid_RAG.ipynb
@@ -134,22 +134,18 @@
"# Ingest from financial feeds\n",
"financial_feed_list = []\n",
"for feed_url in financial_feeds[:2]:\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " financial_feed_list.append(feed_data)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " financial_feed_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
"\n",
"# Ingest from investment APIs\n",
"api_content_list = []\n",
"for api_url in investment_apis[:1]:\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " api_content_list.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " api_content_list.append(api_content)\n",
+ " print(f\" Ingested API: {api_url}\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Investment data files: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/finance/05_Market_Intelligence.ipynb b/cookbook/use_cases/finance/05_Market_Intelligence.ipynb
index 68f7cc69..cd4340e3 100644
--- a/cookbook/use_cases/finance/05_Market_Intelligence.ipynb
+++ b/cookbook/use_cases/finance/05_Market_Intelligence.ipynb
@@ -172,13 +172,11 @@
"\n",
"financial_feed_list = []\n",
"for feed_url in financial_feeds:\n",
- " try:\n",
- " financial_feed = feed_ingestor.ingest_feed(feed_url)\n",
- " if financial_feed:\n",
- " financial_feed_list.append(financial_feed)\n",
- " print(f\" Items: {len(financial_feed.items) if hasattr(financial_feed, 'items') else 0}\")\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " financial_feed = feed_ingestor.ingest_feed(feed_url)\n",
+ " if financial_feed:\n",
+ " financial_feed_list.append(financial_feed)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
+ " print(f\" Items: {len(financial_feed.items) if hasattr(financial_feed, 'items') else 0}\")\n",
"\n",
"# Real financial API endpoints (examples - require API keys)\n",
"financial_apis = [\n",
@@ -189,12 +187,10 @@
"\n",
"web_content_list = []\n",
"for api_url in financial_apis[:1]: # Process first API\n",
- " try:\n",
- " web_content = web_ingestor.ingest_url(api_url)\n",
- " if web_content:\n",
- " web_content_list.append(web_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " web_content = web_ingestor.ingest_url(api_url)\n",
+ " if web_content:\n",
+ " web_content_list.append(web_content)\n",
+ " print(f\" Ingested API: {api_url}\")\n",
"\n",
"# Real database connection for market data\n",
"db_connection_string = \"postgresql://user:password@localhost:5432/market_data_db\"\n",
@@ -203,43 +199,44 @@
"# Optional: Ingest from MCP server\n",
"# Users can bring their own financial data MCP server via URL\n",
"mcp_market_data = []\n",
- "try:\n",
- " # Connect to financial data MCP server via URL\n",
- " # Example: http://localhost:8000/mcp or https://api.example.com/financial-mcp\n",
- " financial_mcp_url = \"http://localhost:8000/mcp\" # Replace with your MCP server URL\n",
- " \n",
- " mcp_ingestor.connect(\n",
- " \"market_mcp_server\",\n",
- " url=financial_mcp_url,\n",
- " headers={\"Authorization\": \"Bearer your_token\"} if \"api.example.com\" in financial_mcp_url else {}\n",
- " )\n",
- " \n",
- " # Ingest market data from MCP server resources or tools\n",
- " mcp_data = mcp_ingestor.ingest_resources(\n",
- " \"market_mcp_server\",\n",
- " resource_uris=[\"resource://market_data/daily\"]\n",
- " )\n",
- " mcp_market_data.extend(mcp_data)\n",
- " \n",
- " # Or use tool-based ingestion\n",
- " tool_data = mcp_ingestor.ingest_tool_output(\n",
- " \"market_mcp_server\",\n",
- " tool_name=\"get_stock_prices\",\n",
- " arguments={\"symbols\": [\"AAPL\", \"MSFT\", \"GOOGL\"], \"date\": datetime.now().isoformat()}\n",
- " )\n",
- " if tool_data:\n",
- " mcp_market_data.append(tool_data)\n",
- " \n",
- " # Parse MCP responses\n",
- " for mcp_item in mcp_market_data:\n",
- " parsed_mcp = mcp_parser.parse_response(mcp_item, response_type=\"json\")\n",
- " if isinstance(parsed_mcp, dict) and \"stock_prices\" in parsed_mcp:\n",
- " # Merge MCP data with existing market data\n",
- " market_data.extend(parsed_mcp.get(\"stock_prices\", []))\n",
- " \n",
- " mcp_ingestor.disconnect(\"market_mcp_server\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ MCP ingestion skipped: {e}\")\n",
+ "# Connect to financial data MCP server via URL\n",
+ "# Example: http://localhost:8000/mcp or https://api.example.com/financial-mcp\n",
+ "financial_mcp_url = \"http://localhost:8000/mcp\" # Replace with your MCP server URL\n",
+ "\n",
+ "mcp_ingestor.connect(\n",
+ " \"market_mcp_server\",\n",
+ " url=financial_mcp_url,\n",
+ " headers={\"Authorization\": \"Bearer your_token\"} if \"api.example.com\" in financial_mcp_url else {}\n",
+ ")\n",
+ "\n",
+ "# Ingest market data from MCP server resources or tools\n",
+ "mcp_data = mcp_ingestor.ingest_resources(\n",
+ " \"market_mcp_server\",\n",
+ " resource_uris=[\"resource://market_data/daily\"]\n",
+ ")\n",
+ "mcp_market_data.extend(mcp_data)\n",
+ "print(f\" Ingested MCP resources: {len(mcp_data)}\")\n",
+ "\n",
+ "# Or use tool-based ingestion\n",
+ "tool_data = mcp_ingestor.ingest_tool_output(\n",
+ " \"market_mcp_server\",\n",
+ " tool_name=\"get_stock_prices\",\n",
+ " arguments={\"symbols\": [\"AAPL\", \"MSFT\", \"GOOGL\"], \"date\": datetime.now().isoformat()}\n",
+ ")\n",
+ "if tool_data:\n",
+ " mcp_market_data.append(tool_data)\n",
+ " print(f\" Retrieved tool data\")\n",
+ "\n",
+ "# Parse MCP responses\n",
+ "for mcp_item in mcp_market_data:\n",
+ " parsed_mcp = mcp_parser.parse_response(mcp_item, response_type=\"json\")\n",
+ " if isinstance(parsed_mcp, dict) and \"stock_prices\" in parsed_mcp:\n",
+ " # Merge MCP data with existing market data\n",
+ " market_data.extend(parsed_mcp.get(\"stock_prices\", []))\n",
+ " print(f\" Parsed MCP item\")\n",
+ "\n",
+ "mcp_ingestor.disconnect(\"market_mcp_server\")\n",
+ "print(f\" Disconnected from MCP server\")\n",
"\n",
"print(f\"Ingested {len([file_objects_json]) if file_objects_json else 0} JSON market data files\")\n",
"print(f\"Ingested {len([file_objects_csv]) if file_objects_csv else 0} CSV market data files\")\n",
diff --git a/cookbook/use_cases/finance/06_Regulatory_Compliance.ipynb b/cookbook/use_cases/finance/06_Regulatory_Compliance.ipynb
index 9e3fdf95..1440254f 100644
--- a/cookbook/use_cases/finance/06_Regulatory_Compliance.ipynb
+++ b/cookbook/use_cases/finance/06_Regulatory_Compliance.ipynb
@@ -125,12 +125,10 @@
"# Ingest from regulatory sources\n",
"regulatory_web_list = []\n",
"for source_url in regulatory_sources[:1]:\n",
- " try:\n",
- " web_content = web_ingestor.ingest_url(source_url)\n",
- " if web_content:\n",
- " regulatory_web_list.append(web_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Regulatory source ingestion for {source_url}: {str(e)[:100]}\")\n",
+ " web_content = web_ingestor.ingest_url(source_url)\n",
+ " if web_content:\n",
+ " regulatory_web_list.append(web_content)\n",
+ " print(f\" Ingested regulatory source: {source_url}\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Regulatory documents: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/healthcare/01_Clinical_Reports_Processing.ipynb b/cookbook/use_cases/healthcare/01_Clinical_Reports_Processing.ipynb
index 9e4b5640..5b5ac29d 100644
--- a/cookbook/use_cases/healthcare/01_Clinical_Reports_Processing.ipynb
+++ b/cookbook/use_cases/healthcare/01_Clinical_Reports_Processing.ipynb
@@ -119,66 +119,65 @@
"# Ingest from FHIR APIs\n",
"fhir_content_list = []\n",
"for api_url in healthcare_apis[:1]:\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " fhir_content_list.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ FHIR API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " fhir_content_list.append(api_content)\n",
+ " print(f\" Ingested FHIR API: {api_url}\")\n",
"\n",
"# Optional: Ingest from MCP server\n",
"# Users can bring their own medical database MCP server via URL\n",
"mcp_clinical_data = []\n",
- "try:\n",
- " # Connect to medical database MCP server via URL\n",
- " # Example: http://localhost:8000/mcp or https://api.example.com/medical-mcp\n",
- " medical_mcp_url = \"http://localhost:8000/mcp\" # Replace with your MCP server URL\n",
- " \n",
- " mcp_ingestor.connect(\n",
- " \"clinical_mcp_server\",\n",
- " url=medical_mcp_url,\n",
- " headers={\n",
- " \"Authorization\": \"Bearer your_token\",\n",
- " \"X-API-Key\": \"your_api_key\"\n",
- " } if \"api.example.com\" in medical_mcp_url else {}\n",
- " )\n",
- " \n",
- " # Ingest patient records from MCP server\n",
- " mcp_data = mcp_ingestor.ingest_resources(\n",
- " \"clinical_mcp_server\",\n",
- " resource_uris=[\"resource://patients/records\"]\n",
- " )\n",
- " mcp_clinical_data.extend(mcp_data)\n",
- " \n",
- " # Or use tool-based ingestion to query patient records\n",
- " tool_data = mcp_ingestor.ingest_tool_output(\n",
- " \"clinical_mcp_server\",\n",
- " tool_name=\"query_patient_records\",\n",
- " arguments={\n",
- " \"patient_id\": \"P001\",\n",
- " \"date_range\": {\n",
- " \"start\": (datetime.now() - timedelta(days=365)).isoformat(),\n",
- " \"end\": datetime.now().isoformat()\n",
- " }\n",
+ "# Connect to medical database MCP server via URL\n",
+ "# Example: http://localhost:8000/mcp or https://api.example.com/medical-mcp\n",
+ "medical_mcp_url = \"http://localhost:8000/mcp\" # Replace with your MCP server URL\n",
+ "\n",
+ "mcp_ingestor.connect(\n",
+ " \"clinical_mcp_server\",\n",
+ " url=medical_mcp_url,\n",
+ " headers={\n",
+ " \"Authorization\": \"Bearer your_token\",\n",
+ " \"X-API-Key\": \"your_api_key\"\n",
+ " } if \"api.example.com\" in medical_mcp_url else {}\n",
+ ")\n",
+ "\n",
+ "# Ingest patient records from MCP server\n",
+ "mcp_data = mcp_ingestor.ingest_resources(\n",
+ " \"clinical_mcp_server\",\n",
+ " resource_uris=[\"resource://patients/records\"]\n",
+ ")\n",
+ "mcp_clinical_data.extend(mcp_data)\n",
+ "print(f\" Ingested MCP resources: {len(mcp_data)}\")\n",
+ "\n",
+ "# Or use tool-based ingestion to query patient records\n",
+ "tool_data = mcp_ingestor.ingest_tool_output(\n",
+ " \"clinical_mcp_server\",\n",
+ " tool_name=\"query_patient_records\",\n",
+ " arguments={\n",
+ " \"patient_id\": \"P001\",\n",
+ " \"date_range\": {\n",
+ " \"start\": (datetime.now() - timedelta(days=365)).isoformat(),\n",
+ " \"end\": datetime.now().isoformat()\n",
" }\n",
- " )\n",
- " if tool_data:\n",
- " mcp_clinical_data.append(tool_data)\n",
- " \n",
- " # Parse MCP responses and merge with existing clinical data\n",
- " for mcp_item in mcp_clinical_data:\n",
- " parsed_mcp = mcp_parser.parse_response(mcp_item, response_type=\"json\")\n",
- " if isinstance(parsed_mcp, dict):\n",
- " if \"patient_records\" in parsed_mcp:\n",
- " # Merge patient records from MCP\n",
- " if isinstance(parsed_data.data, list):\n",
- " parsed_data.data.extend(parsed_mcp.get(\"patient_records\", []))\n",
- " elif isinstance(parsed_data.data, dict):\n",
- " parsed_data.data = [parsed_data.data] + parsed_mcp.get(\"patient_records\", [])\n",
- " \n",
- " mcp_ingestor.disconnect(\"clinical_mcp_server\")\n",
- "except Exception as e:\n",
- " print(f\"⚠ MCP ingestion skipped: {e}\")\n",
+ " }\n",
+ ")\n",
+ "if tool_data:\n",
+ " mcp_clinical_data.append(tool_data)\n",
+ " print(f\" Retrieved tool data\")\n",
+ "\n",
+ "# Parse MCP responses and merge with existing clinical data\n",
+ "for mcp_item in mcp_clinical_data:\n",
+ " parsed_mcp = mcp_parser.parse_response(mcp_item, response_type=\"json\")\n",
+ " if isinstance(parsed_mcp, dict):\n",
+ " if \"patient_records\" in parsed_mcp:\n",
+ " # Merge patient records from MCP\n",
+ " if isinstance(parsed_data.data, list):\n",
+ " parsed_data.data.extend(parsed_mcp.get(\"patient_records\", []))\n",
+ " elif isinstance(parsed_data.data, dict):\n",
+ " parsed_data.data = [parsed_data.data] + parsed_mcp.get(\"patient_records\", [])\n",
+ " print(f\" Parsed MCP item\")\n",
+ "\n",
+ "mcp_ingestor.disconnect(\"clinical_mcp_server\")\n",
+ "print(f\" Disconnected from MCP server\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Clinical reports: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/healthcare/02_Disease_Network_Analysis.ipynb b/cookbook/use_cases/healthcare/02_Disease_Network_Analysis.ipynb
index f03e6d70..5092418d 100644
--- a/cookbook/use_cases/healthcare/02_Disease_Network_Analysis.ipynb
+++ b/cookbook/use_cases/healthcare/02_Disease_Network_Analysis.ipynb
@@ -131,12 +131,10 @@
"# Ingest from disease APIs\n",
"disease_api_list = []\n",
"for api_url in disease_apis[:1]:\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " disease_api_list.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Disease API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " disease_api_list.append(api_content)\n",
+ " print(f\" Ingested disease API: {api_url}\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Disease data files: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/healthcare/03_Drug_Interactions_Analysis.ipynb b/cookbook/use_cases/healthcare/03_Drug_Interactions_Analysis.ipynb
index f13b61d0..d5793ee9 100644
--- a/cookbook/use_cases/healthcare/03_Drug_Interactions_Analysis.ipynb
+++ b/cookbook/use_cases/healthcare/03_Drug_Interactions_Analysis.ipynb
@@ -136,12 +136,10 @@
"# Ingest from drug APIs\n",
"drug_api_list = []\n",
"for api_url in drug_apis[:1]:\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " drug_api_list.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Drug API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " drug_api_list.append(api_content)\n",
+ " print(f\" Ingested drug API: {api_url}\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Drug data files: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/healthcare/04_Healthcare_GraphRAG_Hybrid.ipynb b/cookbook/use_cases/healthcare/04_Healthcare_GraphRAG_Hybrid.ipynb
index 23c70bf3..d1a5418c 100644
--- a/cookbook/use_cases/healthcare/04_Healthcare_GraphRAG_Hybrid.ipynb
+++ b/cookbook/use_cases/healthcare/04_Healthcare_GraphRAG_Hybrid.ipynb
@@ -539,11 +539,8 @@
" FILTER(CONTAINS(LCASE(?label), \"{query_text.lower()}\"))\n",
" }}\n",
" \"\"\"\n",
- " try:\n",
- " ontology_results = query_engine.execute_query(sparql_query, store)\n",
- " results[\"ontology_results\"] = ontology_results.get(\"bindings\", [])\n",
- " except:\n",
- " pass\n",
+ " ontology_results = query_engine.execute_query(sparql_query, store)\n",
+ " results[\"ontology_results\"] = ontology_results.get(\"bindings\", [])\n",
" \n",
" # 2. Search documents using Semantica Hybrid Search\n",
" query_embedding = text_embedder.embed(query_text)\n",
diff --git a/cookbook/use_cases/healthcare/05_Medical_Database_Integration.ipynb b/cookbook/use_cases/healthcare/05_Medical_Database_Integration.ipynb
index abbe82d7..4b24c328 100644
--- a/cookbook/use_cases/healthcare/05_Medical_Database_Integration.ipynb
+++ b/cookbook/use_cases/healthcare/05_Medical_Database_Integration.ipynb
@@ -76,33 +76,29 @@
"# Example: http://localhost:8000/mcp or https://api.example.com/medical-mcp\n",
"medical_mcp_url = \"http://localhost:8000/mcp\"\n",
"\n",
- "try:\n",
- " # Connect to MCP server with authentication (if required)\n",
- " mcp_ingestor.connect(\n",
- " \"medical_server\",\n",
- " url=medical_mcp_url,\n",
- " headers={\n",
- " \"Authorization\": \"Bearer your_token\",\n",
- " \"X-API-Key\": \"your_api_key\"\n",
- " } if \"api.example.com\" in medical_mcp_url else {}\n",
- " )\n",
- " \n",
- " # List available resources (patient records, drug databases)\n",
- " resources = mcp_ingestor.list_available_resources(\"medical_server\")\n",
- " print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
- " for resource in resources[:5]: # Show first 5\n",
- " print(f\" - {resource.uri}: {resource.name}\")\n",
- " if resource.description:\n",
- " print(f\" {resource.description[:80]}...\")\n",
- " \n",
- " # List available tools (queries, drug interaction checks)\n",
- " tools = mcp_ingestor.list_available_tools(\"medical_server\")\n",
- " print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
- " for tool in tools[:5]: # Show first 5\n",
- " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Connection failed: {e}\")\n"
+ "# Connect to MCP server with authentication (if required)\n",
+ "mcp_ingestor.connect(\n",
+ " \"medical_server\",\n",
+ " url=medical_mcp_url,\n",
+ " headers={\n",
+ " \"Authorization\": \"Bearer your_token\",\n",
+ " \"X-API-Key\": \"your_api_key\"\n",
+ " } if \"api.example.com\" in medical_mcp_url else {}\n",
+ ")\n",
+ "\n",
+ "# List available resources (patient records, drug databases)\n",
+ "resources = mcp_ingestor.list_available_resources(\"medical_server\")\n",
+ "print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
+ "for resource in resources[:5]: # Show first 5\n",
+ " print(f\" - {resource.uri}: {resource.name}\")\n",
+ " if resource.description:\n",
+ " print(f\" {resource.description[:80]}...\")\n",
+ "\n",
+ "# List available tools (queries, drug interaction checks)\n",
+ "tools = mcp_ingestor.list_available_tools(\"medical_server\")\n",
+ "print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
+ "for tool in tools[:5]: # Show first 5\n",
+ " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n"
]
},
{
@@ -129,52 +125,47 @@
"\n",
"# Method 1: Resource-based ingestion\n",
"# Ingest from MCP resources (patient records, drug databases)\n",
- "try:\n",
- " # Example: Ingest patient records resource\n",
- " patient_data = mcp_ingestor.ingest_resources(\n",
- " \"medical_server\",\n",
- " resource_uris=[\"resource://patients/records\", \"resource://drugs/interactions\"]\n",
- " )\n",
- " \n",
- " for item in patient_data:\n",
- " medical_data.append(item)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Resource ingestion: {e}\")\n",
+ "# Example: Ingest patient records resource\n",
+ "patient_data = mcp_ingestor.ingest_resources(\n",
+ " \"medical_server\",\n",
+ " resource_uris=[\"resource://patients/records\", \"resource://drugs/interactions\"]\n",
+ ")\n",
+ "\n",
+ "for item in patient_data:\n",
+ " medical_data.append(item)\n",
+ " print(f\" Ingested resource: {item}\")\n",
"\n",
"# Method 2: Tool-based ingestion\n",
"# Call MCP tools to retrieve data dynamically\n",
- "try:\n",
- " # Example: Query patient records\n",
- " patient_records = mcp_ingestor.ingest_tool_output(\n",
- " \"medical_server\",\n",
- " tool_name=\"query_patient_records\",\n",
- " arguments={\n",
- " \"patient_id\": \"P001\",\n",
- " \"date_range\": {\n",
- " \"start\": (datetime.now() - timedelta(days=365)).isoformat(),\n",
- " \"end\": datetime.now().isoformat()\n",
- " }\n",
- " }\n",
- " )\n",
- " \n",
- " if patient_records:\n",
- " medical_data.append(patient_records)\n",
- " \n",
- " # Example: Check drug interactions\n",
- " drug_interactions = mcp_ingestor.ingest_tool_output(\n",
- " \"medical_server\",\n",
- " tool_name=\"check_drug_interactions\",\n",
- " arguments={\n",
- " \"medications\": [\"Lisinopril\", \"Metformin\", \"Aspirin\"]\n",
+ "# Example: Query patient records\n",
+ "patient_records = mcp_ingestor.ingest_tool_output(\n",
+ " \"medical_server\",\n",
+ " tool_name=\"query_patient_records\",\n",
+ " arguments={\n",
+ " \"patient_id\": \"P001\",\n",
+ " \"date_range\": {\n",
+ " \"start\": (datetime.now() - timedelta(days=365)).isoformat(),\n",
+ " \"end\": datetime.now().isoformat()\n",
" }\n",
- " )\n",
- " \n",
- " if drug_interactions:\n",
- " medical_data.append(drug_interactions)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Tool-based ingestion: {e}\")\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "if patient_records:\n",
+ " medical_data.append(patient_records)\n",
+ " print(f\" Retrieved patient records\")\n",
+ "\n",
+ "# Example: Check drug interactions\n",
+ "drug_interactions = mcp_ingestor.ingest_tool_output(\n",
+ " \"medical_server\",\n",
+ " tool_name=\"check_drug_interactions\",\n",
+ " arguments={\n",
+ " \"medications\": [\"Lisinopril\", \"Metformin\", \"Aspirin\"]\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "if drug_interactions:\n",
+ " medical_data.append(drug_interactions)\n",
+ " print(f\" Retrieved drug interactions\")\n",
"\n",
"# Sample medical data (if MCP server is not available)\n",
"if not medical_data:\n",
@@ -240,17 +231,14 @@
"\n",
"# Parse MCP responses\n",
"for data_item in medical_data:\n",
- " try:\n",
- " # Parse MCP response (handles JSON, text, binary)\n",
- " if isinstance(data_item, dict):\n",
- " parsed_item = data_item\n",
- " else:\n",
- " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
- " \n",
- " parsed_medical_data.append(parsed_item)\n",
- " \n",
- " except Exception as e:\n",
- " print(f\"⚠ Parsing error: {e}\")\n",
+ " # Parse MCP response (handles JSON, text, binary)\n",
+ " if isinstance(data_item, dict):\n",
+ " parsed_item = data_item\n",
+ " else:\n",
+ " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
+ " \n",
+ " parsed_medical_data.append(parsed_item)\n",
+ " print(f\" Parsed data item\")\n",
"\n",
"# Extract patient records and drug interactions\n",
"patient_records = []\n",
@@ -574,10 +562,8 @@
"\n",
"\n",
"# Cleanup: Disconnect from MCP server\n",
- "try:\n",
- " mcp_ingestor.disconnect(\"medical_server\")\n",
- "except:\n",
- " pass\n",
+ "mcp_ingestor.disconnect(\"medical_server\")\n",
+ "print(\" Disconnected from MCP server\")\n",
"\n",
"print(f\"📊 Total modules used: 20+\")\n"
]
diff --git a/cookbook/use_cases/healthcare/06_Medical_Literature_GraphRAG.ipynb b/cookbook/use_cases/healthcare/06_Medical_Literature_GraphRAG.ipynb
index 3d33ada9..c9106693 100644
--- a/cookbook/use_cases/healthcare/06_Medical_Literature_GraphRAG.ipynb
+++ b/cookbook/use_cases/healthcare/06_Medical_Literature_GraphRAG.ipynb
@@ -124,12 +124,10 @@
"# Ingest from medical literature sources\n",
"literature_web_list = []\n",
"for source_url in medical_literature_sources[:1]:\n",
- " try:\n",
- " web_content = web_ingestor.ingest_url(source_url)\n",
- " if web_content:\n",
- " literature_web_list.append(web_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Medical literature source ingestion for {source_url}: {str(e)[:100]}\")\n",
+ " web_content = web_ingestor.ingest_url(source_url)\n",
+ " if web_content:\n",
+ " literature_web_list.append(web_content)\n",
+ " print(f\" Ingested medical literature source: {source_url}\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Research papers: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/renewable_energy/01_Energy_Market_Analysis.ipynb b/cookbook/use_cases/renewable_energy/01_Energy_Market_Analysis.ipynb
index d06dcb0f..b800b974 100644
--- a/cookbook/use_cases/renewable_energy/01_Energy_Market_Analysis.ipynb
+++ b/cookbook/use_cases/renewable_energy/01_Energy_Market_Analysis.ipynb
@@ -141,22 +141,18 @@
"# Ingest from energy APIs\n",
"energy_api_list = []\n",
"for api_url in energy_apis[:1]:\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " energy_api_list.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Energy API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " energy_api_list.append(api_content)\n",
+ " print(f\" Ingested energy API: {api_url}\")\n",
"\n",
"# Ingest from energy feeds\n",
"energy_feed_list = []\n",
"for feed_url in energy_feeds:\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " energy_feed_list.append(feed_data)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " energy_feed_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
"\n",
"print(f\"\\n📊 Energy Market Ingestion Summary:\")\n",
"print(f\" Energy market files: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/renewable_energy/02_Environmental_Impact.ipynb b/cookbook/use_cases/renewable_energy/02_Environmental_Impact.ipynb
index 1b26da21..c63a2a42 100644
--- a/cookbook/use_cases/renewable_energy/02_Environmental_Impact.ipynb
+++ b/cookbook/use_cases/renewable_energy/02_Environmental_Impact.ipynb
@@ -144,22 +144,18 @@
"# Ingest from environmental APIs\n",
"environmental_api_list = []\n",
"for api_url in environmental_apis[:1]:\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " environmental_api_list.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Environmental API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " environmental_api_list.append(api_content)\n",
+ " print(f\" Ingested environmental API: {api_url}\")\n",
"\n",
"# Ingest from environmental feeds\n",
"environmental_feed_list = []\n",
"for feed_url in environmental_feeds:\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " environmental_feed_list.append(feed_data)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " environmental_feed_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
"\n",
"print(f\"\\n📊 Environmental Data Ingestion Summary:\")\n",
"print(f\" Environmental data files: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/renewable_energy/04_Resource_Optimization.ipynb b/cookbook/use_cases/renewable_energy/04_Resource_Optimization.ipynb
index a8d0cc77..71756e4d 100644
--- a/cookbook/use_cases/renewable_energy/04_Resource_Optimization.ipynb
+++ b/cookbook/use_cases/renewable_energy/04_Resource_Optimization.ipynb
@@ -136,12 +136,10 @@
"# Ingest from resource APIs\n",
"resource_api_list = []\n",
"for api_url in resource_apis[:1]:\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " resource_api_list.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Resource API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " resource_api_list.append(api_content)\n",
+ " print(f\" Ingested resource API: {api_url}\")\n",
"\n",
"print(f\"\\n📊 Resource Data Ingestion Summary:\")\n",
"print(f\" Resource data files: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/renewable_energy/05_Supply_Chain_Analysis.ipynb b/cookbook/use_cases/renewable_energy/05_Supply_Chain_Analysis.ipynb
index 43361ad7..dded83d9 100644
--- a/cookbook/use_cases/renewable_energy/05_Supply_Chain_Analysis.ipynb
+++ b/cookbook/use_cases/renewable_energy/05_Supply_Chain_Analysis.ipynb
@@ -137,12 +137,10 @@
"# Ingest from supply chain APIs\n",
"supply_chain_api_list = []\n",
"for api_url in supply_chain_apis[:1]:\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " supply_chain_api_list.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Supply chain API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " supply_chain_api_list.append(api_content)\n",
+ " print(f\" Ingested supply chain API: {api_url}\")\n",
"\n",
"print(f\"\\n📊 Supply Chain Data Ingestion Summary:\")\n",
"print(f\" Supply chain data files: {len([file_objects]) if file_objects else 0}\")\n",
@@ -361,25 +359,21 @@
" }\n",
" \n",
" # Check delivery timing\n",
- " try:\n",
- " delivery_dt = datetime.fromisoformat(delivery_date.replace('Z', '+00:00'))\n",
- " days_until_delivery = (delivery_dt - datetime.now()).days\n",
- " \n",
- " if days_until_delivery < 15 and status == \"ordered\":\n",
- " suggestion[\"recommendation\"] = \"Expedite order processing\"\n",
- " suggestion[\"optimization_benefit\"] = \"Reduce delivery risk\"\n",
- " elif quantity > 500:\n",
- " suggestion[\"recommendation\"] = \"Negotiate bulk discount\"\n",
- " suggestion[\"optimization_benefit\"] = \"Cost reduction potential\"\n",
- " elif status == \"in_transit\":\n",
- " suggestion[\"recommendation\"] = \"Track shipment closely\"\n",
- " suggestion[\"optimization_benefit\"] = \"Improve visibility\"\n",
- " else:\n",
- " suggestion[\"recommendation\"] = \"Maintain current flow\"\n",
- " suggestion[\"optimization_benefit\"] = \"Optimal\"\n",
- " except:\n",
- " suggestion[\"recommendation\"] = \"Review delivery schedule\"\n",
- " suggestion[\"optimization_benefit\"] = \"Schedule clarity\"\n",
+ " delivery_dt = datetime.fromisoformat(delivery_date.replace('Z', '+00:00'))\n",
+ " days_until_delivery = (delivery_dt - datetime.now()).days\n",
+ " \n",
+ " if days_until_delivery < 15 and status == \"ordered\":\n",
+ " suggestion[\"recommendation\"] = \"Expedite order processing\"\n",
+ " suggestion[\"optimization_benefit\"] = \"Reduce delivery risk\"\n",
+ " elif quantity > 500:\n",
+ " suggestion[\"recommendation\"] = \"Negotiate bulk discount\"\n",
+ " suggestion[\"optimization_benefit\"] = \"Cost reduction potential\"\n",
+ " elif status == \"in_transit\":\n",
+ " suggestion[\"recommendation\"] = \"Track shipment closely\"\n",
+ " suggestion[\"optimization_benefit\"] = \"Improve visibility\"\n",
+ " else:\n",
+ " suggestion[\"recommendation\"] = \"Maintain current flow\"\n",
+ " suggestion[\"optimization_benefit\"] = \"Optimal\"\n",
" \n",
" optimization_suggestions.append(suggestion)\n",
" \n",
diff --git a/cookbook/use_cases/supply_chain/01_Supply_Chain_Data_Integration.ipynb b/cookbook/use_cases/supply_chain/01_Supply_Chain_Data_Integration.ipynb
index 20aa3b0b..43c6b142 100644
--- a/cookbook/use_cases/supply_chain/01_Supply_Chain_Data_Integration.ipynb
+++ b/cookbook/use_cases/supply_chain/01_Supply_Chain_Data_Integration.ipynb
@@ -74,33 +74,29 @@
"# Example: http://localhost:8000/mcp or https://api.example.com/supplychain-mcp\n",
"supply_chain_mcp_url = \"http://localhost:8000/mcp\"\n",
"\n",
- "try:\n",
- " # Connect to MCP server with authentication (if required)\n",
- " mcp_ingestor.connect(\n",
- " \"supply_chain_server\",\n",
- " url=supply_chain_mcp_url,\n",
- " headers={\n",
- " \"Authorization\": \"Bearer your_token\",\n",
- " \"X-API-Key\": \"your_api_key\"\n",
- " } if \"api.example.com\" in supply_chain_mcp_url else {}\n",
- " )\n",
- " \n",
- " # List available resources (inventory databases, shipment records)\n",
- " resources = mcp_ingestor.list_available_resources(\"supply_chain_server\")\n",
- " print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
- " for resource in resources[:5]: # Show first 5\n",
- " print(f\" - {resource.uri}: {resource.name}\")\n",
- " if resource.description:\n",
- " print(f\" {resource.description[:80]}...\")\n",
- " \n",
- " # List available tools (logistics queries, inventory checks)\n",
- " tools = mcp_ingestor.list_available_tools(\"supply_chain_server\")\n",
- " print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
- " for tool in tools[:5]: # Show first 5\n",
- " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Connection failed: {e}\")\n"
+ "# Connect to MCP server with authentication (if required)\n",
+ "mcp_ingestor.connect(\n",
+ " \"supply_chain_server\",\n",
+ " url=supply_chain_mcp_url,\n",
+ " headers={\n",
+ " \"Authorization\": \"Bearer your_token\",\n",
+ " \"X-API-Key\": \"your_api_key\"\n",
+ " } if \"api.example.com\" in supply_chain_mcp_url else {}\n",
+ ")\n",
+ "\n",
+ "# List available resources (inventory databases, shipment records)\n",
+ "resources = mcp_ingestor.list_available_resources(\"supply_chain_server\")\n",
+ "print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
+ "for resource in resources[:5]: # Show first 5\n",
+ " print(f\" - {resource.uri}: {resource.name}\")\n",
+ " if resource.description:\n",
+ " print(f\" {resource.description[:80]}...\")\n",
+ "\n",
+ "# List available tools (logistics queries, inventory checks)\n",
+ "tools = mcp_ingestor.list_available_tools(\"supply_chain_server\")\n",
+ "print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
+ "for tool in tools[:5]: # Show first 5\n",
+ " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n"
]
},
{
@@ -128,50 +124,44 @@
"\n",
"# Method 1: Resource-based ingestion\n",
"# Ingest from MCP resources (inventory databases, shipment records)\n",
- "try:\n",
- " # Example: Ingest inventory resource\n",
- " inventory_data = mcp_ingestor.ingest_resources(\n",
- " \"supply_chain_server\",\n",
- " resource_uris=[\"resource://inventory/database\", \"resource://shipments/records\"]\n",
- " )\n",
- " \n",
- " for item in inventory_data:\n",
- " supply_chain_data.append(item)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Resource ingestion: {e}\")\n",
+ "inventory_data = mcp_ingestor.ingest_resources(\n",
+ " \"supply_chain_server\",\n",
+ " resource_uris=[\"resource://inventory/database\", \"resource://shipments/records\"]\n",
+ ")\n",
+ "\n",
+ "for item in inventory_data:\n",
+ " supply_chain_data.append(item)\n",
+ " print(f\" Ingested resource: {item}\")\n",
"\n",
"# Method 2: Tool-based ingestion\n",
"# Call MCP tools to retrieve data dynamically\n",
- "try:\n",
- " # Example: Query inventory levels\n",
- " inventory_levels = mcp_ingestor.ingest_tool_output(\n",
- " \"supply_chain_server\",\n",
- " tool_name=\"query_inventory\",\n",
- " arguments={\n",
- " \"warehouse_id\": \"WH001\",\n",
- " \"product_category\": \"Electronics\"\n",
- " }\n",
- " )\n",
- " \n",
- " if inventory_levels:\n",
- " supply_chain_data.append(inventory_levels)\n",
- " \n",
- " # Example: Get shipment status\n",
- " shipment_status = mcp_ingestor.ingest_tool_output(\n",
- " \"supply_chain_server\",\n",
- " tool_name=\"get_shipment_status\",\n",
- " arguments={\n",
- " \"shipment_id\": \"SH001\",\n",
- " \"include_tracking\": True\n",
- " }\n",
- " )\n",
- " \n",
- " if shipment_status:\n",
- " supply_chain_data.append(shipment_status)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Tool-based ingestion: {e}\")\n",
+ "# Example: Query inventory levels\n",
+ "inventory_levels = mcp_ingestor.ingest_tool_output(\n",
+ " \"supply_chain_server\",\n",
+ " tool_name=\"query_inventory\",\n",
+ " arguments={\n",
+ " \"warehouse_id\": \"WH001\",\n",
+ " \"product_category\": \"Electronics\"\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "if inventory_levels:\n",
+ " supply_chain_data.append(inventory_levels)\n",
+ " print(f\" Retrieved inventory levels\")\n",
+ "\n",
+ "# Example: Get shipment status\n",
+ "shipment_status = mcp_ingestor.ingest_tool_output(\n",
+ " \"supply_chain_server\",\n",
+ " tool_name=\"get_shipment_status\",\n",
+ " arguments={\n",
+ " \"shipment_id\": \"SH001\",\n",
+ " \"include_tracking\": True\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "if shipment_status:\n",
+ " supply_chain_data.append(shipment_status)\n",
+ " print(f\" Retrieved shipment status\")\n",
"\n",
"# Sample supply chain data (if MCP server is not available)\n",
"if not supply_chain_data:\n",
@@ -251,17 +241,14 @@
"\n",
"# Parse MCP responses\n",
"for data_item in supply_chain_data:\n",
- " try:\n",
- " # Parse MCP response (handles JSON, text, binary)\n",
- " if isinstance(data_item, dict):\n",
- " parsed_item = data_item\n",
- " else:\n",
- " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
- " \n",
- " parsed_supply_chain_data.append(parsed_item)\n",
- " \n",
- " except Exception as e:\n",
- " print(f\"⚠ Parsing error: {e}\")\n",
+ " # Parse MCP response (handles JSON, text, binary)\n",
+ " if isinstance(data_item, dict):\n",
+ " parsed_item = data_item\n",
+ " else:\n",
+ " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
+ " \n",
+ " parsed_supply_chain_data.append(parsed_item)\n",
+ " print(f\" Parsed data item\")\n",
"\n",
"# Extract inventory and shipments\n",
"inventory_records = []\n",
@@ -564,10 +551,8 @@
"\n",
"\n",
"# Cleanup: Disconnect from MCP server\n",
- "try:\n",
- " mcp_ingestor.disconnect(\"supply_chain_server\")\n",
- "except:\n",
- " pass\n",
+ "mcp_ingestor.disconnect(\"supply_chain_server\")\n",
+ "print(\" Disconnected from MCP server\")\n",
"\n",
"print(f\"📊 Total modules used: 20+\")\n"
]
diff --git a/cookbook/use_cases/trading/01_Market_Data_Analysis.ipynb b/cookbook/use_cases/trading/01_Market_Data_Analysis.ipynb
index 58944791..8420eea6 100644
--- a/cookbook/use_cases/trading/01_Market_Data_Analysis.ipynb
+++ b/cookbook/use_cases/trading/01_Market_Data_Analysis.ipynb
@@ -144,12 +144,10 @@
"# Ingest from financial feeds\n",
"financial_feed_list = []\n",
"for feed_url in financial_feeds[:2]:\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " financial_feed_list.append(feed_data)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " financial_feed_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" Market data files: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/trading/02_News_Sentiment_Analysis.ipynb b/cookbook/use_cases/trading/02_News_Sentiment_Analysis.ipynb
index 610d3cc9..456ceba5 100644
--- a/cookbook/use_cases/trading/02_News_Sentiment_Analysis.ipynb
+++ b/cookbook/use_cases/trading/02_News_Sentiment_Analysis.ipynb
@@ -131,13 +131,11 @@
"# Ingest from financial feeds\n",
"financial_feed_list = []\n",
"for feed_url in financial_feeds[:3]: # Process first 3 feeds\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " financial_feed_list.append(feed_data)\n",
- " print(f\" Items: {len(feed_data.items) if hasattr(feed_data, 'items') else 0}\")\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " financial_feed_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
+ " print(f\" Items: {len(feed_data.items) if hasattr(feed_data, 'items') else 0}\")\n",
"\n",
"print(f\"\\n📊 Ingestion Summary:\")\n",
"print(f\" News files: {len([file_objects]) if file_objects else 0}\")\n",
diff --git a/cookbook/use_cases/trading/03_Real_Time_Market_Data.ipynb b/cookbook/use_cases/trading/03_Real_Time_Market_Data.ipynb
index 6051308b..9f15f9f8 100644
--- a/cookbook/use_cases/trading/03_Real_Time_Market_Data.ipynb
+++ b/cookbook/use_cases/trading/03_Real_Time_Market_Data.ipynb
@@ -74,33 +74,29 @@
"# Example: http://localhost:8000/mcp or https://api.example.com/market-mcp\n",
"market_mcp_url = \"http://localhost:8000/mcp\"\n",
"\n",
- "try:\n",
- " # Connect to MCP server with authentication (if required)\n",
- " mcp_ingestor.connect(\n",
- " \"market_server\",\n",
- " url=market_mcp_url,\n",
- " headers={\n",
- " \"Authorization\": \"Bearer your_token\",\n",
- " \"X-API-Key\": \"your_api_key\"\n",
- " } if \"api.example.com\" in market_mcp_url else {}\n",
- " )\n",
- " \n",
- " # List available resources (market feeds, price streams)\n",
- " resources = mcp_ingestor.list_available_resources(\"market_server\")\n",
- " print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
- " for resource in resources[:5]: # Show first 5\n",
- " print(f\" - {resource.uri}: {resource.name}\")\n",
- " if resource.description:\n",
- " print(f\" {resource.description[:80]}...\")\n",
- " \n",
- " # List available tools (real-time queries, market data streams)\n",
- " tools = mcp_ingestor.list_available_tools(\"market_server\")\n",
- " print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
- " for tool in tools[:5]: # Show first 5\n",
- " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Connection failed: {e}\")\n"
+ "# Connect to MCP server with authentication (if required)\n",
+ "mcp_ingestor.connect(\n",
+ " \"market_server\",\n",
+ " url=market_mcp_url,\n",
+ " headers={\n",
+ " \"Authorization\": \"Bearer your_token\",\n",
+ " \"X-API-Key\": \"your_api_key\"\n",
+ " } if \"api.example.com\" in market_mcp_url else {}\n",
+ ")\n",
+ "\n",
+ "# List available resources (market feeds, price streams)\n",
+ "resources = mcp_ingestor.list_available_resources(\"market_server\")\n",
+ "print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
+ "for resource in resources[:5]: # Show first 5\n",
+ " print(f\" - {resource.uri}: {resource.name}\")\n",
+ " if resource.description:\n",
+ " print(f\" {resource.description[:80]}...\")\n",
+ "\n",
+ "# List available tools (real-time queries, market data streams)\n",
+ "tools = mcp_ingestor.list_available_tools(\"market_server\")\n",
+ "print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
+ "for tool in tools[:5]: # Show first 5\n",
+ " print(f\" - {tool.name}: {tool.description or 'No description'}\")\n"
]
},
{
@@ -127,50 +123,45 @@
"\n",
"# Method 1: Resource-based ingestion\n",
"# Ingest from MCP resources (market feeds)\n",
- "try:\n",
- " # Example: Ingest real-time market feed resource\n",
- " market_feeds = mcp_ingestor.ingest_resources(\n",
- " \"market_server\",\n",
- " resource_uris=[\"resource://market/real_time\", \"resource://market/stream\"]\n",
- " )\n",
- " \n",
- " for item in market_feeds:\n",
- " market_data.append(item)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Resource ingestion: {e}\")\n",
+ "# Example: Ingest real-time market feed resource\n",
+ "market_feeds = mcp_ingestor.ingest_resources(\n",
+ " \"market_server\",\n",
+ " resource_uris=[\"resource://market/real_time\", \"resource://market/stream\"]\n",
+ ")\n",
+ "\n",
+ "for item in market_feeds:\n",
+ " market_data.append(item)\n",
+ " print(f\" Ingested resource: {item}\")\n",
"\n",
"# Method 2: Tool-based ingestion\n",
"# Call MCP tools to retrieve real-time data dynamically\n",
- "try:\n",
- " # Example: Get real-time stock prices\n",
- " real_time_prices = mcp_ingestor.ingest_tool_output(\n",
- " \"market_server\",\n",
- " tool_name=\"get_real_time_prices\",\n",
- " arguments={\n",
- " \"symbols\": [\"AAPL\", \"MSFT\", \"GOOGL\", \"TSLA\", \"AMZN\"],\n",
- " \"interval\": \"1min\"\n",
- " }\n",
- " )\n",
- " \n",
- " if real_time_prices:\n",
- " market_data.append(real_time_prices)\n",
- " \n",
- " # Example: Get market depth data\n",
- " market_depth = mcp_ingestor.ingest_tool_output(\n",
- " \"market_server\",\n",
- " tool_name=\"get_market_depth\",\n",
- " arguments={\n",
- " \"symbol\": \"AAPL\",\n",
- " \"levels\": 5\n",
- " }\n",
- " )\n",
- " \n",
- " if market_depth:\n",
- " market_data.append(market_depth)\n",
- " \n",
- "except Exception as e:\n",
- " print(f\"⚠ Tool-based ingestion: {e}\")\n",
+ "# Example: Get real-time stock prices\n",
+ "real_time_prices = mcp_ingestor.ingest_tool_output(\n",
+ " \"market_server\",\n",
+ " tool_name=\"get_real_time_prices\",\n",
+ " arguments={\n",
+ " \"symbols\": [\"AAPL\", \"MSFT\", \"GOOGL\", \"TSLA\", \"AMZN\"],\n",
+ " \"interval\": \"1min\"\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "if real_time_prices:\n",
+ " market_data.append(real_time_prices)\n",
+ " print(f\" Retrieved real-time prices for {len(real_time_prices) if isinstance(real_time_prices, list) else 1} symbols\")\n",
+ "\n",
+ "# Example: Get market depth data\n",
+ "market_depth = mcp_ingestor.ingest_tool_output(\n",
+ " \"market_server\",\n",
+ " tool_name=\"get_market_depth\",\n",
+ " arguments={\n",
+ " \"symbol\": \"AAPL\",\n",
+ " \"levels\": 5\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "if market_depth:\n",
+ " market_data.append(market_depth)\n",
+ " print(f\" Retrieved market depth data\")\n",
"\n",
"# Sample real-time market data (if MCP server is not available)\n",
"if not market_data:\n",
@@ -258,17 +249,14 @@
"\n",
"# Parse MCP responses\n",
"for data_item in market_data:\n",
- " try:\n",
- " # Parse MCP response (handles JSON, text, binary)\n",
- " if isinstance(data_item, dict):\n",
- " parsed_item = data_item\n",
- " else:\n",
- " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
- " \n",
- " parsed_market_data.append(parsed_item)\n",
- " \n",
- " except Exception as e:\n",
- " print(f\"⚠ Parsing error: {e}\")\n",
+ " # Parse MCP response (handles JSON, text, binary)\n",
+ " if isinstance(data_item, dict):\n",
+ " parsed_item = data_item\n",
+ " else:\n",
+ " parsed_item = mcp_parser.parse_response(data_item, response_type=\"json\")\n",
+ " \n",
+ " parsed_market_data.append(parsed_item)\n",
+ " print(f\" Parsed data item\")\n",
"\n",
"# Extract real-time prices\n",
"real_time_prices = []\n",
@@ -542,10 +530,8 @@
"\n",
"\n",
"# Cleanup: Disconnect from MCP server\n",
- "try:\n",
- " mcp_ingestor.disconnect(\"market_server\")\n",
- "except:\n",
- " pass\n",
+ "mcp_ingestor.disconnect(\"market_server\")\n",
+ "print(\" Disconnected from MCP server\")\n",
"\n",
"print(f\"📊 Total modules used: 20+\")\n"
]
diff --git a/cookbook/use_cases/trading/06_Strategy_Backtesting.ipynb b/cookbook/use_cases/trading/06_Strategy_Backtesting.ipynb
index 41fc7286..43649065 100644
--- a/cookbook/use_cases/trading/06_Strategy_Backtesting.ipynb
+++ b/cookbook/use_cases/trading/06_Strategy_Backtesting.ipynb
@@ -115,22 +115,18 @@
"# Ingest from historical market APIs\n",
"historical_api_list = []\n",
"for api_url in historical_market_apis[:1]:\n",
- " try:\n",
- " api_content = web_ingestor.ingest_url(api_url)\n",
- " if api_content:\n",
- " historical_api_list.append(api_content)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Historical API ingestion for {api_url}: {str(e)[:100]}\")\n",
+ " api_content = web_ingestor.ingest_url(api_url)\n",
+ " if api_content:\n",
+ " historical_api_list.append(api_content)\n",
+ " print(f\" Ingested historical API: {api_url}\")\n",
"\n",
"# Ingest from historical news feeds\n",
"historical_feed_list = []\n",
"for feed_url in historical_feeds:\n",
- " try:\n",
- " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
- " if feed_data:\n",
- " historical_feed_list.append(feed_data)\n",
- " except Exception as e:\n",
- " print(f\"⚠ Feed ingestion for {feed_url}: {str(e)[:100]}\")\n",
+ " feed_data = feed_ingestor.ingest_feed(feed_url)\n",
+ " if feed_data:\n",
+ " historical_feed_list.append(feed_data)\n",
+ " print(f\" Ingested feed: {feed_url}\")\n",
"\n",
"print(f\"\\n📊 Historical Data Ingestion Summary:\")\n",
"print(f\" Historical data files: {len([file_objects]) if file_objects else 0}\")\n",