weaviate.gql package
GraphQL module used to create get and/or aggregate GraphQL requests from Weaviate.
Submodules
weaviate.gql.aggregate module
GraphQL Aggregate command.
- class weaviate.gql.aggregate.AggregateBuilder(class_name: str)[source]
Bases:
GraphQLAggregateBuilder class used to aggregate Weaviate objects.
Initialize a AggregateBuilder class instance.
Parameters
- class_namestr
Class name of the objects to be aggregated.
- build() str[source]
Build the query and return the string.
Returns
- str
The GraphQL query as a string.
- with_fields(field: str) AggregateBuilder[source]
Include a field in the aggregate query.
Parameters
- fieldstr
Field to include in the aggregate query. e.g. ‘<property_name> { count }’
Returns
- weaviate.gql.aggregate.AggregateBuilder
Updated AggregateBuilder.
- with_group_by_filter(properties: List[str]) AggregateBuilder[source]
Add a group by filter to the query. Might requires the user to set an additional group by clause using with_fields(..).
Parameters
- propertieslist of str
list of properties that are included in the group by filter. Generates a filter like: ‘groupBy: [“property1”, “property2”]’ from a list [“property1”, “property2”]
Returns
- weaviate.gql.aggregate.AggregateBuilder
Updated AggregateBuilder.
- with_hybrid(content: dict) AggregateBuilder[source]
Get objects using bm25 and vector, then combine the results using a reciprocal ranking algorithm.
Parameters
- contentdict
The content of the hybrid filter to set.
- with_limit(limit: int) AggregateBuilder[source]
Set limit to limit the number of returned results from the aggregation query.
Parameters
- limitint
The limit.
Returns
- weaviate.gql.aggregate.AggregateBuilder
Updated AggregateBuilder.
- with_meta_count() AggregateBuilder[source]
Set Meta Count to True.
Returns
- weaviate.gql.aggregate.AggregateBuilder
Updated AggregateBuilder.
- with_near_audio(content: dict, encode: bool = True) AggregateBuilder[source]
Set nearAudio filter.
Parameters
- contentdict
The content of the nearAudio filter to set. See examples below.
- encodebool, optional
Whether to encode the content[“audio”] to base64 and convert to string. If True, the content[“audio”] can be an audio path or a file opened in binary read mode. If False, the content[“audio”] MUST be a base64 encoded string (NOT bytes, i.e. NOT binary string that looks like this: b’BASE64ENCODED’ but simple ‘BASE64ENCODED’). By default True.
Returns
- weaviate.gql.aggregate.AggregateBuilder
The updated AggregateBuilder.
Raises
- AttributeError
If another ‘near’ filter was already set.
- with_near_depth(content: dict, encode: bool = True) AggregateBuilder[source]
Set nearDepth filter.
Parameters
- contentdict
The content of the nearDepth filter to set. See examples below.
- encodebool, optional
Whether to encode the content[“depth”] to base64 and convert to string. If True, the content[“depth”] can be an depth path or a file opened in binary read mode. If False, the content[“depth”] MUST be a base64 encoded string (NOT bytes, i.e. NOT binary string that looks like this: b’BASE64ENCODED’ but simple ‘BASE64ENCODED’). By default True.
Returns
- weaviate.gql.aggregate.AggregateBuilder
The updated AggregateBuilder.
Raises
- AttributeError
If another ‘near’ filter was already set.
- with_near_image(content: dict, encode: bool = True) AggregateBuilder[source]
Set nearImage filter.
Parameters
- contentdict
The content of the nearImage filter to set. See examples below.
- encodebool, optional
Whether to encode the content[“image”] to base64 and convert to string. If True, the content[“image”] can be an image path or a file opened in binary read mode. If False, the content[“image”] MUST be a base64 encoded string (NOT bytes, i.e. NOT binary string that looks like this: b’BASE64ENCODED’ but simple ‘BASE64ENCODED’). By default True.
Returns
- weaviate.gql.aggregate.AggregateBuilder
The updated AggregateBuilder.
Raises
- AttributeError
If another ‘near’ filter was already set.
- with_near_imu(content: dict, encode: bool = True) AggregateBuilder[source]
Set nearIMU filter.
Parameters
- contentdict
The content of the nearIMU filter to set. See examples below.
- encodebool, optional
Whether to encode the content[“thermal”] to base64 and convert to string. If True, the content[“thermal”] can be an thermal path or a file opened in binary read mode. If False, the content[“thermal”] MUST be a base64 encoded string (NOT bytes, i.e. NOT binary string that looks like this: b’BASE64ENCODED’ but simple ‘BASE64ENCODED’). By default True.
Returns
- weaviate.gql.aggregate.AggregateBuilder
The updated AggregateBuilder.
Raises
- AttributeError
If another ‘near’ filter was already set.
- with_near_object(content: dict) AggregateBuilder[source]
Set nearObject filter.
Parameters
- contentdict
The content of the nearObject filter to set. See examples below.
Returns
- weaviate.gql.aggregate.AggregateBuilder
Updated AggregateBuilder.
Raises
- AttributeError
If another ‘near’ filter was already set.
- with_near_text(content: dict) AggregateBuilder[source]
Set nearText filter. This filter can be used with text modules (text2vec). E.g.: text2vec-contextionary, text2vec-transformers. NOTE: The ‘autocorrect’ field is enabled only with the text-spellcheck Weaviate module.
Parameters
- contentdict
The content of the nearText filter to set. See examples below.
Returns
- weaviate.gql.aggregate.AggregateBuilder
Updated AggregateBuilder.
Raises
- AttributeError
If another ‘near’ filter was already set.
- with_near_thermal(content: dict, encode: bool = True) AggregateBuilder[source]
Set nearThermal filter.
Parameters
- contentdict
The content of the nearThermal filter to set. See examples below.
- encodebool, optional
Whether to encode the content[“thermal”] to base64 and convert to string. If True, the content[“thermal”] can be an thermal path or a file opened in binary read mode. If False, the content[“thermal”] MUST be a base64 encoded string (NOT bytes, i.e. NOT binary string that looks like this: b’BASE64ENCODED’ but simple ‘BASE64ENCODED’). By default True.
Returns
- weaviate.gql.aggregate.AggregateBuilder
The updated AggregateBuilder.
Raises
- AttributeError
If another ‘near’ filter was already set.
- with_near_vector(content: dict) AggregateBuilder[source]
Set nearVector filter.
Parameters
- contentdict
The content of the nearVector filter to set. See examples below.
Returns
- weaviate.gql.aggregate.AggregateBuilder
Updated AggregateBuilder.
Raises
- AttributeError
If another ‘near’ filter was already set.
- with_near_video(content: dict, encode: bool = True) AggregateBuilder[source]
Set nearVideo filter.
Parameters
- contentdict
The content of the nearVideo filter to set. See examples below.
- encodebool, optional
Whether to encode the content[“video”] to base64 and convert to string. If True, the content[“video”] can be an video path or a file opened in binary read mode. If False, the content[“video”] MUST be a base64 encoded string (NOT bytes, i.e. NOT binary string that looks like this: b’BASE64ENCODED’ but simple ‘BASE64ENCODED’). By default True.
Returns
- weaviate.gql.aggregate.AggregateBuilder
The updated AggregateBuilder.
Raises
- AttributeError
If another ‘near’ filter was already set.
- with_object_limit(limit: int) AggregateBuilder[source]
Set objectLimit to limit vector search results used within the aggregation query only when with near<MEDIA> filter.
Parameters
- limitint
The object limit.
Returns
- weaviate.gql.aggregate.AggregateBuilder
Updated AggregateBuilder.
- with_tenant(tenant: str) AggregateBuilder[source]
Sets a tenant for the query.
- with_where(content: dict) AggregateBuilder[source]
Set ‘where’ filter.
Parameters
- contentdict
The where filter to include in the aggregate query. See examples below.
Returns
- weaviate.gql.aggregate.AggregateBuilder
Updated AggregateBuilder.
weaviate.gql.filter module
GraphQL filters for Get and Aggregate commands. GraphQL abstract class for GraphQL commands to inherit from.
- class weaviate.gql.filter.Ask(content: dict)[source]
Bases:
FilterAsk class used to filter weaviate objects by asking a question.
Initialize a Ask class instance.
Parameters
- contentlist
The content of the ask clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- TypeError
If ‘content’ has key “properties” but the type is not list or str.
- class weaviate.gql.filter.Filter(content: dict)[source]
Bases:
ABCA base abstract class for all filters.
Initialize a Filter class instance.
Parameters
- contentdict
The content of the Filter clause.
- property content: dict
- class weaviate.gql.filter.GraphQL[source]
Bases:
ABCA base abstract class for GraphQL commands, such as Get, Aggregate.
- class weaviate.gql.filter.MediaType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum- AUDIO = 'audio'
- DEPTH = 'depth'
- IMAGE = 'image'
- IMU = 'imu'
- THERMAL = 'thermal'
- VIDEO = 'video'
- class weaviate.gql.filter.NearAudio(content: dict)[source]
Bases:
NearMediaNearAudio class used to filter weaviate objects.
Initialize a NearAudio class instance.
Parameters
- contentlist
The content of the nearAudio clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- TypeError
If ‘content[“audio”]’ is not of type str.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- class weaviate.gql.filter.NearDepth(content: dict)[source]
Bases:
NearMediaNearDepth class used to filter weaviate objects.
Initialize a NearDepth class instance.
Parameters
- contentlist
The content of the nearDepth clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- TypeError
If ‘content[“depth”]’ is not of type str.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- class weaviate.gql.filter.NearIMU(content: dict)[source]
Bases:
NearMediaNearIMU class used to filter weaviate objects.
Initialize a NearIMU class instance.
Parameters
- contentlist
The content of the nearIMU clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- TypeError
If ‘content[“imu”]’ is not of type str.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- class weaviate.gql.filter.NearImage(content: dict)[source]
Bases:
NearMediaNearImage class used to filter weaviate objects.
Initialize a NearImage class instance.
Parameters
- contentlist
The content of the nearImage clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- TypeError
If ‘content[“image”]’ is not of type str.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- class weaviate.gql.filter.NearMedia(content: dict, media_type: MediaType)[source]
Bases:
FilterInitialize a NearMedia class instance.
Parameters
- contentlist
The content of the near<Media> clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- TypeError
If ‘content[“<media>”]’ is not of type str.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- class weaviate.gql.filter.NearObject(content: dict, is_server_version_14: bool)[source]
Bases:
FilterNearObject class used to filter weaviate objects.
Initialize a NearVector class instance.
Parameters
- contentlist
The content of the nearVector clause.
- is_server_version_14bool
Whether the Server version is >= 1.14.0.
Raises
- TypeError
If ‘content’ is not of type dict.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- TypeError
If ‘id’/’beacon’ key does not have a value of type str!
- class weaviate.gql.filter.NearText(content: dict)[source]
Bases:
FilterNearText class used to filter weaviate objects. Can be used with text models only (text2vec). E.g.: text2vec-contextionary, text2vec-transformers.
Initialize a NearText class instance.
Parameters
- contentdict
The content of the nearText clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- class weaviate.gql.filter.NearThermal(content: dict)[source]
Bases:
NearMediaNearThermal class used to filter weaviate objects.
Initialize a NearThermal class instance.
Parameters
- contentlist
The content of the nearThermal clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- TypeError
If ‘content[“thermal”]’ is not of type str.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- class weaviate.gql.filter.NearVector(content: dict)[source]
Bases:
FilterNearVector class used to filter weaviate objects.
Initialize a NearVector class instance.
Parameters
- contentlist
The content of the nearVector clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- KeyError
If ‘content’ does not contain “vector”.
- TypeError
If ‘content[“vector”]’ is not of type list.
- AttributeError
If invalid ‘content’ keys are provided.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- class weaviate.gql.filter.NearVideo(content: dict)[source]
Bases:
NearMediaNearVideo class used to filter weaviate objects.
Initialize a NearVideo class instance.
Parameters
- contentlist
The content of the nearVideo clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- TypeError
If ‘content[“video”]’ is not of type str.
- ValueError
If ‘content’ has key “certainty”/”distance” but the value is not float.
- class weaviate.gql.filter.Sort(content: dict | list)[source]
Bases:
FilterSort filter class used to sort weaviate objects.
Initialize a Where filter class instance.
Parameters
- contentlist or dict
The content of the sort filter clause or a single clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- ValueError
If a mandatory key is missing in the filter content.
- add(content: dict | list) None[source]
Add more sort clauses to the already existing sort clauses.
Parameters
- contentlist or dict
The content of the sort filter clause or a single clause to be added to the already existing ones.
Raises
- TypeError
If ‘content’ is not of type dict.
- ValueError
If a mandatory key is missing in the filter content.
- class weaviate.gql.filter.Where(content: dict)[source]
Bases:
FilterWhere filter class used to filter weaviate objects.
Initialize a Where filter class instance.
Parameters
- contentdict
The content of the where filter clause.
Raises
- TypeError
If ‘content’ is not of type dict.
- ValueError
If a mandatory key is missing in the filter content.