rg.Query
¶
To collect records based on searching criteria, you can use the Query
and Filter
classes. The Query
class is used to define the search criteria, while the Filter
class is used to filter the search results. Filter
is passed to a Query
object so you can combine multiple filters to create complex search queries. A Query
object can also be passed to Dataset.records
to fetch records based on the search criteria.
Usage Examples¶
Searching for records with terms¶
To search for records with terms, you can use the Dataset.records
attribute with a query string. The search terms are used to search for records that contain the terms in the text field.
Filtering records by conditions¶
Argilla allows you to filter records based on conditions. You can use the Filter
class to define the conditions and pass them to the Dataset.records
attribute to fetch records based on the conditions. Conditions include "==", ">=", "<=", or "in". Conditions can be combined with dot notation to filter records based on metadata, suggestions, or responses.
# create a range from 10 to 20
range_filter = rg.Filter(
[
("metadata.count", ">=", 10),
("metadata.count", "<=", 20)
]
)
# query records with metadata count greater than 10 and less than 20
query = rg.Query(filters=range_filter, query="paris")
# iterate over the results
for record in dataset.records(query=query):
print(record)
Class Reference¶
rg.Query
¶
This class is used to map user queries to the internal query models
Source code in src/argilla_sdk/records/_search.py
__init__(*, query=None, filter=None)
¶
Create a query object for use in Argilla search requests.add()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
Union[str, None]
|
The query string that will be used to search. |
None
|
filter |
Union[Filter, None]
|
The filter object that will be used to filter the search results. |
None
|
Source code in src/argilla_sdk/records/_search.py
rg.Filter
¶
This class is used to map user filters to the internal filter models
Source code in src/argilla_sdk/records/_search.py
__init__(conditions=None)
¶
Create a filter object for use in Argilla search requests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions |
Union[List[Tuple[str, str, Any]], Tuple[str, str, Any], None]
|
The conditions that will be used to filter the search results. The conditions should be a list of tuples where each tuple contains the field, operator, and value. For example |
None
|