From cd437a9cfb0e1140372d27ee979ea5e20dbf0bed Mon Sep 17 00:00:00 2001 From: KaifAhmad1 Date: Wed, 24 Dec 2025 13:00:10 +0530 Subject: [PATCH] Fix GraphRAG notebook: embedding dimension check, update LLM model to llama-3.3-70b-versatile, fix file ingestion, graph metrics access, and export methods --- .../advanced_rag/01_GraphRAG_Complete.ipynb | 10 +- .../advanced_rag/graphrag_kg.graphml | 254 +++++++ .../use_cases/advanced_rag/graphrag_kg.json | 678 ++++++++++++++++++ 3 files changed, 937 insertions(+), 5 deletions(-) create mode 100644 cookbook/use_cases/advanced_rag/graphrag_kg.graphml create mode 100644 cookbook/use_cases/advanced_rag/graphrag_kg.json diff --git a/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb b/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb index ff4d1b7a..96d90041 100644 --- a/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb +++ b/cookbook/use_cases/advanced_rag/01_GraphRAG_Complete.ipynb @@ -2250,7 +2250,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 86, "metadata": {}, "outputs": [ { @@ -2259,8 +2259,8 @@ "text": [ "\n", "Exporting knowledge graph...\n", - " Warning: JSON export error: 'GraphExporter' object has no attribute 'export_json'\n", - " Warning: GraphML export error: 'GraphExporter' object has no attribute 'export_graphml'\n", + " Exported to JSON: graphrag_kg.json\n", + " Exported to GraphML: graphrag_kg.graphml\n", "\n", "Phase 7 Complete. Graph visualized and exported.\n" ] @@ -2276,14 +2276,14 @@ "\n", "# Export to JSON (human-readable, easy to process)\n", "try:\n", - " exporter.export_json(kg_final, \"graphrag_kg.json\")\n", + " exporter.export_knowledge_graph(kg_final, \"graphrag_kg.json\", format=\"json\")\n", " print(\" Exported to JSON: graphrag_kg.json\")\n", "except Exception as e:\n", " print(f\" Warning: JSON export error: {e}\")\n", "\n", "# Export to GraphML (standard graph format)\n", "try:\n", - " exporter.export_graphml(kg_final, \"graphrag_kg.graphml\")\n", + " exporter.export_knowledge_graph(kg_final, \"graphrag_kg.graphml\", format=\"graphml\")\n", " print(\" Exported to GraphML: graphrag_kg.graphml\")\n", "except Exception as e:\n", " print(f\" Warning: GraphML export error: {e}\")\n", diff --git a/cookbook/use_cases/advanced_rag/graphrag_kg.graphml b/cookbook/use_cases/advanced_rag/graphrag_kg.graphml new file mode 100644 index 00000000..fb324a1e --- /dev/null +++ b/cookbook/use_cases/advanced_rag/graphrag_kg.graphml @@ -0,0 +1,254 @@ + + + + + + + + + + Makeup and Beauty Blog + ORG + 1.0 + + + Monday Poll + EVENT + 1.0 + + + 2007 + DATE + 1.0 + + + Rosacea + CONCEPT + 1.0 + + + Dr. Bailey + PERSON + 1.0 + + + Green Tea Antioxidant Skin Therapy + PRODUCT + 1.0 + + + Vol. 892 + EVENT + 1.0 + + + Laneige + ORG + 1.0 + + + Sausalito + GPE + 1.0 + + + Ulta + ORG + 1.0 + + + December 15, 2025 + DATE + 1.0 + + + Jo Malone + ORG + 1 + + + Trader Joe + ORG + 1 + + + hawaii + GPE + 1.0 + + + Benzoyl Peroxide Cream + PRODUCT + 1 + + + Facial dandruff + CONCEPT + 1 + + + Calming Zinc Soap + PRODUCT + 1 + + + Hydrate + CONCEPT + 1.0 + + + Daily Moisturizing Face Cream + PRODUCT + 1.0 + + + Omega Enriched Face Booster Oil + PRODUCT + 1.0 + + + + hosts + 0.9 + + + occurs on + 0.9 + + + publishes + 0.9 + + + has + 0.9 + + + has + 0.9 + + + hosts + 0.9 + + + posts + 0.9 + + + posts + 0.9 + + + has been active since + 0.9 + + + related_to + 0.9 + + + related_to + 0.9 + + + hosts + 0.9 + + + posts + 0.9 + + + posts + 0.9 + + + located_in + 0.9 + + + prescribes + 0.9 + + + part of + 0.9 + + + uses + 0.9 + + + part of + 0.9 + + + uses + 0.9 + + + often occurs with + 0.9 + + + needs to be addressed + 0.9 + + + is often sufficient to control + 0.9 + + + is often sufficient to control + 0.9 + + + is often sufficient to control + 0.9 + + + is often sufficient to control + 0.9 + + + produces + 0.9 + + + produces + 0.9 + + + prescribes + 0.9 + + + prescribes + 0.9 + + + is_achieved_by + 0.9 + + + can_be_combined_with + 0.9 + + + contains + 0.9 + + + contains + 0.9 + + + can_be_replaced_with + 0.9 + + + \ No newline at end of file diff --git a/cookbook/use_cases/advanced_rag/graphrag_kg.json b/cookbook/use_cases/advanced_rag/graphrag_kg.json new file mode 100644 index 00000000..c204fc9b --- /dev/null +++ b/cookbook/use_cases/advanced_rag/graphrag_kg.json @@ -0,0 +1,678 @@ +{ + "nodes": [ + { + "id": "makeup_and_beauty_blog", + "label": "Makeup and Beauty Blog", + "type": "ORG", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "makeup_and_beauty_blog", + "name": "Makeup and Beauty Blog", + "source": null + }, + { + "id": "makeup_and_beauty_blog", + "name": "Makeup and Beauty Blog", + "source": null + }, + { + "id": "makeup_and_beauty_blog_monday_poll,_vol._893", + "name": "Makeup and Beauty Blog Monday Poll, Vol. 893", + "source": null + }, + { + "id": "makeup_and_beauty_blog_monday_poll", + "name": "Makeup and Beauty Blog Monday Poll", + "source": null + }, + { + "id": "mbb", + "name": "MBB", + "source": null + } + ], + "merge_count": 5 + } + } + }, + { + "id": "monday_poll", + "label": "Monday Poll", + "type": "EVENT", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "monday_poll", + "name": "Monday Poll", + "source": null + }, + { + "id": "monday_poll", + "name": "Monday Poll", + "source": null + }, + { + "id": "monday", + "name": "Monday", + "source": null + }, + { + "id": "holiday", + "name": "holiday", + "source": null + }, + { + "id": "holiday", + "name": "holiday", + "source": null + } + ], + "merge_count": 5 + } + } + }, + { + "id": "2007", + "label": "2007", + "type": "DATE", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "2007", + "name": "2007", + "source": null + }, + { + "id": "2007", + "name": "2007", + "source": null + }, + { + "id": "2024", + "name": "2024", + "source": null + } + ], + "merge_count": 3 + } + } + }, + { + "id": "rosacea", + "label": "Rosacea", + "type": "CONCEPT", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "rosacea", + "name": "Rosacea", + "source": null + }, + { + "id": "rosacea", + "name": "rosacea", + "source": null + }, + { + "id": "rosacea_treatment_routine", + "name": "rosacea treatment routine", + "source": null + }, + { + "id": "rosie", + "name": "Rosie", + "source": null + }, + { + "id": "rosacea_therapy_skin_care_kit", + "name": "Rosacea Therapy Skin Care Kit", + "source": null + }, + { + "id": "marnie", + "name": "Marnie", + "source": null + }, + { + "id": "cavallo_point", + "name": "Cavallo Point", + "source": null + }, + { + "id": "castor_seed_oil", + "name": "castor seed oil", + "source": null + } + ], + "merge_count": 8 + } + } + }, + { + "id": "dr._bailey", + "label": "Dr. Bailey", + "type": "PERSON", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "dr._bailey", + "name": "Dr. Bailey", + "source": null + }, + { + "id": "dr._bailey", + "name": "Dr. Bailey", + "source": null + }, + { + "id": "dr._bailey's_skincare", + "name": "Dr. Bailey's Skincare", + "source": null + }, + { + "id": "dr._bailey's_skincare", + "name": "Dr. Bailey's Skincare", + "source": null + } + ], + "merge_count": 4 + } + } + }, + { + "id": "green_tea_antioxidant_skin_therapy", + "label": "Green Tea Antioxidant Skin Therapy", + "type": "PRODUCT", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "green_tea_antioxidant_skin_therapy", + "name": "Green Tea Antioxidant Skin Therapy", + "source": null + }, + { + "id": "green_tea_antioxidant_skin_therapy", + "name": "Green Tea Antioxidant Skin Therapy", + "source": null + } + ], + "merge_count": 2 + } + } + }, + { + "id": "vol._892", + "label": "Vol. 892", + "type": "EVENT", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "vol._892", + "name": "Vol. 892", + "source": null + }, + { + "id": "vol._891", + "name": "Vol. 891", + "source": null + } + ], + "merge_count": 2 + } + } + }, + { + "id": "laneige", + "label": "Laneige", + "type": "ORG", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "laneige", + "name": "Laneige", + "source": null + }, + { + "id": "lanikai", + "name": "Lanikai", + "source": null + } + ], + "merge_count": 2 + } + } + }, + { + "id": "sausalito", + "label": "Sausalito", + "type": "GPE", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "sausalito", + "name": "Sausalito", + "source": null + }, + { + "id": "sea_buckthorn", + "name": "sea buckthorn", + "source": null + } + ], + "merge_count": 2 + } + } + }, + { + "id": "ulta", + "label": "Ulta", + "type": "ORG", + "attributes": { + "confidence": 1.0, + "provenance": { + "merged_from": [ + { + "id": "ulta", + "name": "Ulta", + "source": null + }, + { + "id": "clotrimazole", + "name": "clotrimazole", + "source": null + } + ], + "merge_count": 2 + } + } + }, + { + "id": "december_15,_2025", + "label": "December 15, 2025", + "type": "DATE", + "attributes": { + "confidence": 1.0 + } + }, + { + "id": "jo_malone", + "label": "Jo Malone", + "type": "ORG", + "attributes": { + "confidence": 1 + } + }, + { + "id": "trader_joe", + "label": "Trader Joe", + "type": "ORG", + "attributes": { + "confidence": 1 + } + }, + { + "id": "hawaii", + "label": "hawaii", + "type": "GPE", + "attributes": { + "confidence": 1.0 + } + }, + { + "id": "benzoyl_peroxide_cream", + "label": "Benzoyl Peroxide Cream", + "type": "PRODUCT", + "attributes": { + "confidence": 1 + } + }, + { + "id": "facial_dandruff", + "label": "Facial dandruff", + "type": "CONCEPT", + "attributes": { + "confidence": 1 + } + }, + { + "id": "calming_zinc_soap", + "label": "Calming Zinc Soap", + "type": "PRODUCT", + "attributes": { + "confidence": 1 + } + }, + { + "id": "hydrate", + "label": "Hydrate", + "type": "CONCEPT", + "attributes": { + "confidence": 1.0 + } + }, + { + "id": "daily_moisturizing_face_cream", + "label": "Daily Moisturizing Face Cream", + "type": "PRODUCT", + "attributes": { + "confidence": 1.0 + } + }, + { + "id": "omega_enriched_face_booster_oil", + "label": "Omega Enriched Face Booster Oil", + "type": "PRODUCT", + "attributes": { + "confidence": 1.0 + } + } + ], + "edges": [ + { + "source": "Makeup and Beauty Blog", + "target": "Monday Poll", + "type": "hosts", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Monday Poll", + "target": "December 15, 2025", + "type": "occurs on", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "Makeup and Beauty Blog Monday Poll, Vol. 893", + "type": "publishes", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "Monday", + "type": "has", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "2007", + "type": "has", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "Monday Poll", + "type": "hosts", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "Makeup and Beauty Blog Monday Poll", + "type": "posts", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "Vol. 892", + "type": "posts", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "2007", + "type": "has been active since", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "MBB", + "target": "Makeup and Beauty Blog", + "type": "related_to", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "Makeup and Beauty Blog", + "type": "related_to", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "Monday Poll", + "type": "hosts", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "Vol. 891", + "type": "posts", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Makeup and Beauty Blog", + "target": "Monday Poll", + "type": "posts", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Cavallo Point", + "target": "Sausalito", + "type": "located_in", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Dr. Bailey", + "target": "Green Tea Antioxidant Skin Therapy", + "type": "prescribes", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Green Tea Antioxidant Skin Therapy", + "target": "Rosacea Therapy Skin Care Kit", + "type": "part of", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Dr. Bailey", + "target": "Rosacea Therapy Skin Care Kit", + "type": "uses", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Rosacea Therapy Skin Care Kit", + "target": "rosacea treatment routine", + "type": "part of", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Dr. Bailey", + "target": "rosacea treatment routine", + "type": "uses", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Facial dandruff", + "target": "rosacea", + "type": "often occurs with", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Facial dandruff", + "target": "rosacea", + "type": "needs to be addressed", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Calming Zinc Soap", + "target": "Facial dandruff", + "type": "is often sufficient to control", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Calming Zinc Soap", + "target": "rosacea", + "type": "is often sufficient to control", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Green Tea Antioxidant Skin Therapy", + "target": "Facial dandruff", + "type": "is often sufficient to control", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Green Tea Antioxidant Skin Therapy", + "target": "rosacea", + "type": "is often sufficient to control", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Dr. Bailey's Skincare", + "target": "Calming Zinc Soap", + "type": "produces", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Dr. Bailey's Skincare", + "target": "Green Tea Antioxidant Skin Therapy", + "type": "produces", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Dr. Bailey", + "target": "Calming Zinc Soap", + "type": "prescribes", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Dr. Bailey", + "target": "Green Tea Antioxidant Skin Therapy", + "type": "prescribes", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Hydrate", + "target": "Daily Moisturizing Face Cream", + "type": "is_achieved_by", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Daily Moisturizing Face Cream", + "target": "Omega Enriched Face Booster Oil", + "type": "can_be_combined_with", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Omega Enriched Face Booster Oil", + "target": "castor seed oil", + "type": "contains", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Omega Enriched Face Booster Oil", + "target": "sea buckthorn", + "type": "contains", + "attributes": { + "confidence": 0.9 + } + }, + { + "source": "Daily Moisturizing Face Cream", + "target": "Omega Enriched Face Booster Oil", + "type": "can_be_replaced_with", + "attributes": { + "confidence": 0.9 + } + } + ], + "metadata": { + "num_entities": 20, + "num_relationships": 35, + "temporal_enabled": false, + "timestamp": "2025-12-24T12:46:41.535755", + "entity_resolution_applied": true + } +} \ No newline at end of file