josh-fell commented on code in PR #35934:
URL: https://github.com/apache/airflow/pull/35934#discussion_r1412493461


##########
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:
   My thought was if the method is specifically looking for arguments that it 
would be nice to have explicitly listed in the signature even if it's optional 
and let the docstring tell users when they should use them. Definitely 
shouldn't list all of them between the two underlying calls.
   
   But having parameters like `vector` and `consistency_level` listed 
explicitly and stating that they are only used for creating new objects (if I 
understand the logic correctly). This lets users only need to look at the 
Airflow docs rather than the code here and/or Weaviate API to figure out what 
their options are.



-- 
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