diff --git a/Demo_graph.ipynb b/Demo_graph.ipynb
index 2a78c6dc3..6e6cc4bc4 100644
--- a/Demo_graph.ipynb
+++ b/Demo_graph.ipynb
@@ -2466,7 +2466,7 @@
},
{
"cell_type": "code",
- "execution_count": 354,
+ "execution_count": 360,
"id": "a23a7517-64f2-4d9f-8cc0-f6dfdd0fe3c1",
"metadata": {},
"outputs": [
@@ -4093,10 +4093,10 @@
" \n",
" for uuid, items in grouped_data.items():\n",
" if uuid != id:\n",
- " print(\"this id is orig %s\", id)\n",
- " print(\"this uuid is relevant for search %s\", uuid)\n",
+ " # print(\"this id is orig %s\", id)\n",
+ " # print(\"this uuid is relevant for search %s\", uuid)\n",
" for item in items:\n",
- " results = qdrant_search(uuid, item['description'])\n",
+ " results = qdrant_search(id, item['description'])\n",
"\n",
" for result in results:\n",
" if result.score > 0.9: # Only consider hits with a score greater than 0.9\n",
@@ -4110,298 +4110,58 @@
" })\n",
" \n",
" \n",
- " print(item['description'])\n",
+ " # print(item['description'])\n",
" "
]
},
{
"cell_type": "code",
- "execution_count": 355,
+ "execution_count": 361,
"id": "cd2094ee-75d2-40a7-bd65-38392a53df4f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "{'f3b1dd35-0640-40a0-a664-fb037aeb43c7': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
+ "{'f3b1dd35-0640-40a0-a664-fb037aeb43c7': [],\n",
+ " 'c306c248-bbab-44a9-9ae2-448f992e415c': [],\n",
+ " 'dbcbc6c6-db82-48f3-8fa9-e3d372ff3483': [],\n",
+ " 'e81660f7-b9a2-4266-a468-404a49b05888': [],\n",
+ " '92ae1b09-3dfb-4e0b-920d-83341d1d8c7b': [],\n",
+ " '27a76d52-5b5e-4e8e-8726-29be55c8b2f1': [],\n",
+ " '4ef6847a-7036-4861-8df6-a209c53038ca': [],\n",
+ " '7b147696-3654-4e4c-b177-da5a1b44a2c0': [],\n",
+ " '97597864-a11a-4058-b854-8f21864c7e06': [{'collection_name_uuid': '771e3cc9-fb2f-422e-a8f8-e067d6b44e34',\n",
+ " 'searched_node_id': '79077e21-6c55-4174-8f73-a3dd7b4a39ce',\n",
+ " 'score': 0.9999994162338484,\n",
" 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
" 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 0.9999741956655729,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 1.0000000163660978,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 1.0000000118484735,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999993320994057,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " 'c306c248-bbab-44a9-9ae2-448f992e415c': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
+ " {'collection_name_uuid': '771e3cc9-fb2f-422e-a8f8-e067d6b44e34',\n",
+ " 'searched_node_id': 'd7b5b0ee-7fbe-4065-b09c-c0a38efef1bb',\n",
" 'score': 1.000000070957316,\n",
" 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
" 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
+ " {'collection_name_uuid': '771e3cc9-fb2f-422e-a8f8-e067d6b44e34',\n",
+ " 'searched_node_id': 'c4c5ad12-1d14-4c13-a6ea-8b0a53e3879c',\n",
" 'score': 1.0000000163660978,\n",
" 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
" 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
+ " {'collection_name_uuid': '771e3cc9-fb2f-422e-a8f8-e067d6b44e34',\n",
+ " 'searched_node_id': 'b1abfc01-dd15-4637-b872-9852666f0fa3',\n",
" 'score': 1.0000000118484735,\n",
" 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
" 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
+ " {'collection_name_uuid': '771e3cc9-fb2f-422e-a8f8-e067d6b44e34',\n",
+ " 'searched_node_id': '31bf1fcd-1b58-4402-aa51-66f9a5ae09e9',\n",
" 'score': 0.9999975523571477,\n",
" 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
" 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " 'dbcbc6c6-db82-48f3-8fa9-e3d372ff3483': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 1.000000070957316,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 1.0000000163660978,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 1.0000000118484735,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999994141190498,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " 'e81660f7-b9a2-4266-a468-404a49b05888': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 1.000000070957316,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 1.0000000163660978,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 1.0000000118484735,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999975523571477,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " '92ae1b09-3dfb-4e0b-920d-83341d1d8c7b': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 1.000000070957316,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 1.0000000163660978,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 0.9999984916797362,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999993320994057,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " '27a76d52-5b5e-4e8e-8726-29be55c8b2f1': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 0.9999994544043944,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 1.000000070957316,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 1.0000000163660978,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 1.0000000118484735,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999975523571477,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " '4ef6847a-7036-4861-8df6-a209c53038ca': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 1.000000070957316,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 1.0000000163660978,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 1.0000000118484735,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999975523571477,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " '7b147696-3654-4e4c-b177-da5a1b44a2c0': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 1.000000070957316,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 1.0000000163660978,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 1.0000000118484735,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999975523571477,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " '97597864-a11a-4058-b854-8f21864c7e06': [],\n",
- " '48c1a502-48b1-4240-87ac-6558d41e1b6f': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 1.000000070957316,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 1.0000000163660978,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 1.0000000118484735,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999975523571477,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " 'b40f5ed5-45cf-43f5-902c-d4928743f8fd': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 1.000000070957316,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 0.9999993471378945,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 1.0000000118484735,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999975523571477,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}],\n",
- " '771e3cc9-fb2f-422e-a8f8-e067d6b44e34': [{'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '58fc3b86-be82-4d50-9578-2b157924ef23',\n",
- " 'score': 1.0000000750922018,\n",
- " 'score_metadata': {'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'},\n",
- " 'score_id': '58fc3b86-be82-4d50-9578-2b157924ef23'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154',\n",
- " 'score': 1.000000070957316,\n",
- " 'score_metadata': {'meta': 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability'},\n",
- " 'score_id': 'e7929623-23e0-4b43-80b6-52fdbf4ce154'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '48191bec-b329-460e-8de3-7957ffa9909c',\n",
- " 'score': 1.0000000163660978,\n",
- " 'score_metadata': {'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"},\n",
- " 'score_id': '48191bec-b329-460e-8de3-7957ffa9909c'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d',\n",
- " 'score': 1.0000000118484735,\n",
- " 'score_metadata': {'meta': 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains'},\n",
- " 'score_id': '0915d7f3-9a6d-4461-af9d-d222079dd52d'},\n",
- " {'collection_name_uuid': '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'searched_node_id': '41a19992-d932-47c3-b1dc-41c4e673ab43',\n",
- " 'score': 0.9999975523571477,\n",
- " 'score_metadata': {'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'},\n",
- " 'score_id': '41a19992-d932-47c3-b1dc-41c4e673ab43'}]}"
+ " '48c1a502-48b1-4240-87ac-6558d41e1b6f': [],\n",
+ " 'b40f5ed5-45cf-43f5-902c-d4928743f8fd': [],\n",
+ " '771e3cc9-fb2f-422e-a8f8-e067d6b44e34': []}"
]
},
- "execution_count": 355,
+ "execution_count": 361,
"metadata": {},
"output_type": "execute_result"
}
@@ -4412,36 +4172,15 @@
},
{
"cell_type": "code",
- "execution_count": 317,
+ "execution_count": 377,
"id": "97302500-241e-41b3-9355-4523bcb4d01b",
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'27a76d52-5b5e-4e8e-8726-29be55c8b2f1',\n",
- " '48c1a502-48b1-4240-87ac-6558d41e1b6f',\n",
- " '4ef6847a-7036-4861-8df6-a209c53038ca',\n",
- " '771e3cc9-fb2f-422e-a8f8-e067d6b44e34',\n",
- " '7b147696-3654-4e4c-b177-da5a1b44a2c0',\n",
- " '92ae1b09-3dfb-4e0b-920d-83341d1d8c7b',\n",
- " '97597864-a11a-4058-b854-8f21864c7e06',\n",
- " 'b40f5ed5-45cf-43f5-902c-d4928743f8fd',\n",
- " 'c306c248-bbab-44a9-9ae2-448f992e415c',\n",
- " 'dbcbc6c6-db82-48f3-8fa9-e3d372ff3483',\n",
- " 'e81660f7-b9a2-4266-a468-404a49b05888',\n",
- " 'f3b1dd35-0640-40a0-a664-fb037aeb43c7'}"
- ]
- },
- "execution_count": 317,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
+ "\n",
"def connect_nodes_in_graph(graph, relationship_dict):\n",
" \"\"\"\n",
- " For each relationship in relationship_dict, check if both nodes exist in the graph.\n",
+ " For each relationship in relationship_dict, check if both nodes exist in the graph based on node attributes.\n",
" If they do, create a connection (edge) between them.\n",
"\n",
" :param graph: A NetworkX graph object\n",
@@ -4449,17 +4188,214 @@
" \"\"\"\n",
" for id, relationships in relationship_dict.items():\n",
" for relationship in relationships:\n",
- " searched_node_id = relationship['searched_node_id']\n",
- " score_id = relationship['score_id']\n",
+ " searched_node_attr_id = relationship['searched_node_id']\n",
+ " score_attr_id = relationship['score_id']\n",
" score = relationship['score']\n",
"\n",
- " # Check if both nodes exist in the graph\n",
- " if graph.has_node(searched_node_id) and graph.has_node(score_id):\n",
+ " # Initialize node keys for both searched_node and score_node\n",
+ " searched_node_key, score_node_key = None, None\n",
+ "\n",
+ " # Find nodes in the graph that match the searched_node_id and score_id from their attributes\n",
+ " for node, attrs in graph.nodes(data=True):\n",
+ " if 'id' in attrs: # Ensure there is an 'id' attribute\n",
+ " if attrs['id'] == searched_node_attr_id:\n",
+ " searched_node_key = node\n",
+ " elif attrs['id'] == score_attr_id:\n",
+ " score_node_key = node\n",
+ "\n",
+ " # If both nodes are found, no need to continue checking other nodes\n",
+ " if searched_node_key and score_node_key:\n",
+ " break\n",
+ "\n",
+ " # Check if both nodes were found in the graph\n",
+ " if searched_node_key is not None and score_node_key is not None:\n",
" # If both nodes exist, create an edge between them\n",
" # You can customize the edge attributes as needed, here we use 'score' as an attribute\n",
- " graph.add_edge(searched_node_id, score_id, weight=score, score_metadata=relationship.get('score_metadata'))\n"
+ " graph.add_edge(searched_node_key, score_node_key, weight=score, score_metadata=relationship.get('score_metadata'))\n",
+ "\n",
+ " return graph\n"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 378,
+ "id": "2c344176-8f70-4a0c-b528-0e85ed810984",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONNECTED_GRAPH = connect_nodes_in_graph(R, relationship_dict)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e86c07ad-0597-48ad-a9bb-f99d45297beb",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 372,
+ "id": "fce71784-66c3-4e96-8dbe-01b52478312d",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The graph has 249 edges.\n"
+ ]
+ }
+ ],
+ "source": [
+ "num_edges = CONNECTED_GRAPH.number_of_edges()\n",
+ "print(f\"The graph has {num_edges} edges.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 373,
+ "id": "1497b257-70f3-4eb1-94f5-fa234eafd574",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " source target relationship description\n",
+ "0 user123 Temporal created NaN\n",
+ "1 user123 Positional created NaN\n",
+ "2 user123 Propositions created NaN\n",
+ "3 user123 Personalization created NaN\n",
+ "4 user123 Natural Language Text created NaN\n"
+ ]
+ }
+ ],
+ "source": [
+ "edges = nx.to_pandas_edgelist(CONNECTED_GRAPH)\n",
+ "print(edges.head())"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 380,
+ "id": "6e2c0c8b-bbcf-43f1-a980-8122e195b48c",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Matching Node Keys: ['The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022 - 380ae041-a5e2-4057-a310-4442bb36b1a1 - 771e3cc9-fb2f-422e-a8f8-e067d6b44e34 - 31bf1fcd-1b58-4402-aa51-66f9a5ae09e9']\n"
+ ]
+ }
+ ],
+ "source": [
+ "target_id = '31bf1fcd-1b58-4402-aa51-66f9a5ae09e9'\n",
+ "\n",
+ "# Find the node key(s) with this ID\n",
+ "matching_nodes = [node for node, attrs in CONNECTED_GRAPH.nodes(data=True) if attrs.get('id') == target_id]\n",
+ "\n",
+ "print(\"Matching Node Keys:\", matching_nodes)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 381,
+ "id": "d1197355-706a-4b53-8238-3b599e2723c6",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Node with ID 31bf1fcd-1b58-4402-aa51-66f9a5ae09e9 (key: The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022 - 380ae041-a5e2-4057-a310-4442bb36b1a1 - 771e3cc9-fb2f-422e-a8f8-e067d6b44e34 - 31bf1fcd-1b58-4402-aa51-66f9a5ae09e9) connects to nodes: {'England and Wales saw a significant increase in dog attacks between 2018 and 2022, aligning with a rise in the number of dogs and changes in ownership dynamics - 380ae041-a5e2-4057-a310-4442bb36b1a1 - 771e3cc9-fb2f-422e-a8f8-e067d6b44e34 - 3c6e91ac-a064-4cdc-a77e-7ee289c441bb', 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022 - 08b965ee-470a-4133-979b-0003edef15d0 - 97597864-a11a-4058-b854-8f21864c7e06 - 41a19992-d932-47c3-b1dc-41c4e673ab43'}\n"
+ ]
+ }
+ ],
+ "source": [
+ "target_id = '31bf1fcd-1b58-4402-aa51-66f9a5ae09e9'\n",
+ "\n",
+ "# Find the node key(s) with this ID (assuming IDs are unique, there should be only one match)\n",
+ "matching_node_key = None\n",
+ "for node, attrs in CONNECTED_GRAPH.nodes(data=True):\n",
+ " if attrs.get('id') == target_id:\n",
+ " matching_node_key = node\n",
+ " break\n",
+ "\n",
+ "# If a matching node is found, list all nodes it's connected to\n",
+ "if matching_node_key is not None:\n",
+ " connected_nodes = set([connected_node for _, connected_node in CONNECTED_GRAPH.edges(matching_node_key)])\n",
+ " print(f\"Node with ID {target_id} (key: {matching_node_key}) connects to nodes: {connected_nodes}\")\n",
+ "else:\n",
+ " print(f\"No node found with ID {target_id}\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 379,
+ "id": "488dfddc-3774-4f8c-9478-117b94fc70f9",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "WARNING:graphistry.PlotterBase:Failed memoization speedup attempt due to Pandas internal hash function failing. Continuing without memoization speedups.This is fine, but for speedups around skipping re-uploads of previously seen tables, try identifying which columns have types that Pandas cannot hash, and convert them to hashable types like strings."
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " "
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 379,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import graphistry\n",
+ "import pandas as pd\n",
+ "\n",
+ "# Assuming Graphistry is already configured with API key\n",
+ "# graphistry.register(api=3, username='your_username', password='your_password')\n",
+ "\n",
+ "# Convert NetworkX graph to a Pandas DataFrame\n",
+ "edges = nx.to_pandas_edgelist(CONNECTED_GRAPH)\n",
+ "graphistry.register(api=3, username='Vasilije1990', password='Q@HLdgv5SMUsGxy') \n",
+ "\n",
+ "# Visualize the graph\n",
+ "graphistry.edges(edges, 'source', 'target').plot()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "11afb7e6-165d-46d3-8a09-7673bf7d6e8e",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
{
"cell_type": "code",
"execution_count": null,