ephraimbuddy commented on code in PR #35934:
URL: https://github.com/apache/airflow/pull/35934#discussion_r1410827434


##########
airflow/providers/weaviate/hooks/weaviate.py:
##########
@@ -193,3 +195,88 @@ def query_without_vector(
             .do()
         )
         return results
+
+    def create_object(self, data_object, class_name, **kwargs) -> str | 
dict[str, Any] | None:
+        """Create a new object.
+
+        data_object: Object to be added. If type is str it should be either a 
URL or a file.
+        class_name: Class name associated with the object given.
+        **kwargs: Additional parameters to be passed to 
weaviateclient.data_object.create()
+        """
+        client = self.get_conn()
+        # generate deterministic uuid if not provided
+        uuid = kwargs.pop("uuid", generate_uuid5(data_object))
+        try:
+            return client.data_object.create(data_object, class_name, 
uuid=uuid, **kwargs)
+        except ObjectAlreadyExistsException:
+            self.log.warning("Object with the UUID %s already exists", uuid)
+            return None
+
+    def get_or_create_object(self, data_object, class_name, **kwargs) -> str | 
dict[str, Any] | None:
+        """Get or Create a new object.
+
+        Returns the object if already exists
+        data_object: Object to be added. If type is str it should be either a 
URL or a file.
+        class_name: Class name associated with the object given.
+        **kwargs: Additional parameters to be passed to 
weaviateclient.data_object.create() and
+        weaviateclient.data_object.get()
+        """
+        vector = kwargs.pop("vector", None)
+        class_name = kwargs.pop("class_name", class_name)

Review Comment:
   Ah, the `class_name `shouldn't be popped since it's provided as a parameter 
but the `vector `popping is necessary because the `get_object` method doesn't 
need a vector parameter.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to