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


##########
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:
   > I was thinking they would be optional parameters and also add a note in 
the docstring so folks don't have to read code to figure out other kwargs they 
could pass in.
    
   There are a lot of parameters for both create/get methods and they are not 
equal. You can see them here: 
https://weaviate-python-client.readthedocs.io/en/stable/weaviate.data.html. So 
I had to pick out the mandatory ones but I think it should be optional.
   
   For the other methods like `get_object` and `create_object`, we can list out 
the parameters but I feel it's too much for a hook's method, more like 
repeating what's in the client. Using hooks instead of operators is a low-level 
access in my opinion and I expect anyone using it to look up the parameters as 
described in the docstring. ~However, thinking about it more, I will list it 
for `get_object` and `create_object` even though it's not really what I like~
   
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to