airflow.providers.weaviate.hooks.weaviate

Module Contents

Classes

WeaviateHook

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

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

conn_name_attr = 'conn_id'[source]
default_conn_name = 'weaviate_default'[source]
conn_type = 'weaviate'[source]
hook_name = 'Weaviate'[source]
classmethod get_connection_form_widgets()[source]

Returns connection widgets to add to connection form.

classmethod get_ui_field_behaviour()[source]

Returns custom field behaviour.

get_conn()[source]

Return connection for the hook.

conn()[source]

Returns a Weaviate client.

get_client()[source]

Returns a Weaviate client.

test_connection()[source]
create_class(class_json)[source]

Create a new class.

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.

Parameters

schema_json (dict[str, Any]) – The schema to create

batch_data(class_name, data, batch_config_params=None)[source]
delete_class(class_name)[source]

Delete an existing class.

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.

create_object(data_object, class_name, **kwargs)[source]

Create a new object.

Parameters
  • data_object (dict | str) – Object to be added. If type is str it should be either a URL or a file.

  • class_name (str) – Class name associated with the object given.

  • kwargs – Additional parameters to be passed to weaviate_client.data_object.create()

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.

Parameters
  • after (str | weaviate.types.UUID | None) – uuid of the object to start listing from

  • as_dataframe (bool) – if True, returns a pandas dataframe

  • kwargs – parameters to be passed to weaviate_client.data_object.get()

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

validate_object(data_object, class_name, **kwargs)[source]

Validate an object in weaviate.

Parameters
  • data_object (dict | str) – The object to be validated. If type is str it should be either an URL or a file.

  • class_name (str) – Class name associated with the object given.

  • kwargs – Optional parameters to be passed to weaviate_client.data_object.validate()

object_exists(uuid, **kwargs)[source]

Check if an object exists in weaviate.

Parameters
  • uuid (str | weaviate.types.UUID) – The UUID of the object that may or may not exist within Weaviate.

  • kwargs – Optional parameters to be passed to weaviate_client.data_object.exists()

Was this entry helpful?