airflow.providers.weaviate.hooks.weaviate¶
Module Contents¶
Classes¶
Interact with Weaviate database to store vectors. This hook uses the conn_id. |
- class airflow.providers.weaviate.hooks.weaviate.WeaviateHook(conn_id=default_conn_name, *args, **kwargs)[source]¶
Bases:
airflow.hooks.base.BaseHookInteract with Weaviate database to store vectors. This hook uses the conn_id.
- Parameters
conn_id (str) – The connection id to use when connecting to Weaviate. <howto/connection:weaviate>
- classmethod get_connection_form_widgets()[source]¶
Returns connection widgets to add to connection form.
- create_schema(schema_json)[source]¶
Create a new Schema.
Instead of adding classes one by one , you can upload a full schema in JSON format at once.
- query_with_vector(embeddings, class_name, *properties, certainty=0.7, limit=1)[source]¶
Query weaviate database with near vectors.
This method uses a vector search using a Get query. we are using a with_near_vector to provide weaviate with a query with vector itself. This is needed for query a Weaviate class with a custom, external vectorizer. Weaviate then converts this into a vector through the inference API (OpenAI in this particular example) and uses that vector as the basis for a vector search.
- query_without_vector(search_text, class_name, *properties, limit=1)[source]¶
Query using near text.
This method uses a vector search using a Get query. we are using a nearText operator to provide weaviate with a query search_text. Weaviate then converts this into a vector through the inference API (OpenAI in this particular example) and uses that vector as the basis for a vector search.
- get_or_create_object(data_object=None, class_name=None, vector=None, consistency_level=None, tenant=None, **kwargs)[source]¶
Get or Create a new object.
Returns the object if already exists
- Parameters
data_object (dict | str | None) – Object to be added. If type is str it should be either a URL or a file. This is required to create a new object.
class_name (str | None) – Class name associated with the object given. This is required to create a new object.
vector (Sequence | None) – Vector associated with the object given. This argument is only used when creating object.
consistency_level (weaviate.ConsistencyLevel | None) – Consistency level to be used. Applies to both create and get operations.
kwargs – Additional parameters to be passed to weaviate_client.data_object.create() and weaviate_client.data_object.get()
- Tenant
Tenant to be used. Applies to both create and get operations.
- get_object(**kwargs)[source]¶
Get objects or an object from weaviate.
- Parameters
kwargs – parameters to be passed to weaviate_client.data_object.get() or weaviate_client.data_object.get_by_id()
- get_all_objects(after=None, as_dataframe=False, **kwargs)[source]¶
Get all objects from weaviate.
if after is provided, it will be used as the starting point for the listing.
- delete_object(uuid, **kwargs)[source]¶
Delete an object from weaviate.
- Parameters
uuid (weaviate.types.UUID | str) – uuid of the object to be deleted
kwargs – Optional parameters to be passed to weaviate_client.data_object.delete()
- update_object(data_object, class_name, uuid, **kwargs)[source]¶
Update an object in weaviate.
- Parameters
data_object (dict | str) – The object states the fields that should be updated. Fields not specified in the ‘data_object’ remain unchanged. Fields that are None will not be changed. If type is str it should be either an URL or a file.
class_name (str) – Class name associated with the object given.
uuid (weaviate.types.UUID | str) – uuid of the object to be updated
kwargs – Optional parameters to be passed to weaviate_client.data_object.update()
- replace_object(data_object, class_name, uuid, **kwargs)[source]¶
Replace an object in weaviate.
- Parameters
data_object (dict | str) – The object states the fields that should be updated. Fields not specified in the ‘data_object’ will be set to None. If type is str it should be either an URL or a file.
class_name (str) – Class name associated with the object given.
uuid (weaviate.types.UUID | str) – uuid of the object to be replaced
kwargs – Optional parameters to be passed to weaviate_client.data_object.replace()