diff --git a/datastew/repository/weaviate.py b/datastew/repository/weaviate.py index 70c1ea8..312bd92 100644 --- a/datastew/repository/weaviate.py +++ b/datastew/repository/weaviate.py @@ -459,7 +459,11 @@ def _sentence_embedder_exists(self, name: str) -> bool: "operator": "Equal", "valueText": name }).do() - return len(result["data"]["Get"]["Mapping"]) > 0 + result_data = result["data"]["Get"]["Mapping"] + if result_data is not None: + return len(result_data) > 0 + else: + return False except Exception as e: raise RuntimeError(f"Failed to check if sentence embedder exists: {e}") @@ -470,7 +474,11 @@ def _terminology_exists(self, name: str) -> bool: "operator": "Equal", "valueText": name }).do() - return len(result["data"]["Get"]["Terminology"]) > 0 + result_data = result["data"]["Get"]["Terminology"] + if result_data is not None: + return len(result_data) > 0 + else: + return False except Exception as e: raise RuntimeError(f"Failed to check if terminology exists: {e}") @@ -481,7 +489,11 @@ def _concept_exists(self, concept_id: str) -> bool: "operator": "Equal", "valueText": concept_id }).do() - return len(result["data"]["Get"]["Concept"]) > 0 + result_data = result["data"]["Get"]["Concept"] + if result_data is not None: + return len(result_data) > 0 + else: + return False except Exception as e: raise RuntimeError(f"Failed to check if concept exists: {e}") @@ -491,6 +503,10 @@ def _mapping_exists(self, embedding) -> bool: "vector": embedding, "distance": float(0) # Ensure distance is explicitly casted to float }).do() - return len(result["data"]["Get"]["Mapping"]) > 0 + result_data = result["data"]["Get"]["Mapping"] + if result_data is not None: + return len(result_data) > 0 + else: + return False except Exception as e: raise RuntimeError(f"Failed to check if mapping exists: {e}")