> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encord.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Beta.curation query

Queries that describe a set of files in Curation.

A query is a scope plus a list of conditions, all of which must hold. Build one with [Scope](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#scope-objects) and
[F](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#f-objects), and rank a search's results by similarity with [RankBy](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#rankby-objects). A query does nothing on its own: it's an
input to the methods that search, count or link files.

```python theme={"dark"}
from datetime import datetime, timedelta, timezone

from encord.beta.curation_query import CurationQuery, F, Scope
from encord.orm.storage import StorageItemType

query = CurationQuery(
    scope=Scope.folder("5f8364e8-8ccd-4f9f-9066-91e055da920d"),  # or a StorageFolder
    filters=[
        F.data_type.eq(StorageItemType.IMAGE),
        F.uploaded_at.gte(datetime.now(timezone.utc) - timedelta(days=1)),
    ],
)
```

`to_dict` and `from_dict` convert a query to and from a JSON-compatible dict, so it can be kept in config.

Methods that act on the files a query matches, such as [link\_query\_items()](https://docs.encord.com/sdk-documentation/sdk-references/dataset.md#link_query_items), run as
jobs and report on them with [QueryItemsJob](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#queryitemsjob-objects).

## FolderScope Objects

```python theme={"dark"}
class FolderScope(_QueryModel)
```

The files in a folder and its subfolders. Create one with [folder()](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#folder).

## FileNameCondition Objects

```python theme={"dark"}
class FileNameCondition(_QueryModel)
```

A condition on the file name. Create one with `F.file_name`.

## DataTypeCondition Objects

```python theme={"dark"}
class DataTypeCondition(_QueryModel)
```

A condition on the file's data type. Create one with `F.data_type`.

## MimeTypeCondition Objects

```python theme={"dark"}
class MimeTypeCondition(_QueryModel)
```

A condition on the file's MIME type. Create one with `F.mime_type`.

## UploadedAtCondition Objects

```python theme={"dark"}
class UploadedAtCondition(_QueryModel)
```

A condition on when the file was uploaded. Create one with `F.uploaded_at`.

## MetadataCondition Objects

```python theme={"dark"}
class MetadataCondition(_QueryModel)
```

A condition on a key in your organization's metadata schema. Create one with `F.metadata`.

## MetricCondition Objects

```python theme={"dark"}
class MetricCondition(_QueryModel)
```

A condition on a metric of the file. Create one with `F.metric`.

## FrameMetadataCondition Objects

```python theme={"dark"}
class FrameMetadataCondition(_QueryModel)
```

A condition on a key of a frame's metadata. Create one with `F.frame.metadata`.

## FrameMetricCondition Objects

```python theme={"dark"}
class FrameMetricCondition(_QueryModel)
```

A condition on a metric of a frame. Create one with `F.frame.metric`.

## SimilarToFilesRank Objects

```python theme={"dark"}
class SimilarToFilesRank(_QueryModel)
```

Ranks files by similarity to other files. Create one with [similar\_to\_files()](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#similar_to_files).

## SimilarToTextRank Objects

```python theme={"dark"}
class SimilarToTextRank(_QueryModel)
```

Ranks files by similarity to a description. Create one with [similar\_to\_text()](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#similar_to_text).

## CurationQuery Objects

```python theme={"dark"}
class CurationQuery(BaseDTO)
```

The files in `scope` that meet every condition in `filters`.

A query can have at most 64 filters. With no filters, it matches every file.

With `rank_by`, which needs premium access to Index, the query matches only its `top_k` most similar files, and
leaves out files without embeddings. [query\_storage\_items()](https://docs.encord.com/sdk-documentation/sdk-references/user_client.md#query_storage_items) returns them
most similar first.

## Scope Objects

```python theme={"dark"}
class Scope()
```

Creates the scope of a [CurationQuery](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#curationquery-objects).

#### folder

```python theme={"dark"}
@staticmethod
def folder(folder: Union["StorageFolder", UUID, str]) -> FolderScope
```

Returns the scope for a folder and its subfolders.

**Arguments**:

* `folder` - The folder, or its UUID.

**Returns**:

* `FolderScope` - The scope for that folder.

## RankBy Objects

```python theme={"dark"}
class RankBy()
```

Creates the ranking of a [CurationQuery](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#curationquery-objects), by similarity on the files' embeddings.

The scope's top-level folder must be upgraded in Index to compute embeddings.

#### similar\_to\_files

```python theme={"dark"}
@staticmethod
def similar_to_files(files: List[Union["StorageItem", UUID, str]],
                     top_k: int = _DEFAULT_TOP_K) -> SimilarToFilesRank
```

Ranks files by similarity to `files`, 1 to 100 files you can see, and leaves those files out. The query
matches the `top_k` most similar files, 1 to 1,000.

Files without embeddings are ignored, so if none of `files` has one, the query matches no files.

#### similar\_to\_text

```python theme={"dark"}
@staticmethod
def similar_to_text(text: str,
                    top_k: int = _DEFAULT_TOP_K) -> SimilarToTextRank
```

Ranks files by similarity to a description, such as "a dog on a beach", of at most 75 tokens. The query
matches the `top_k` most similar files, 1 to 1,000.

Searching, counting or linking raises [InvalidArgumentsError](https://docs.encord.com/sdk-documentation/sdk-references/exceptions.md#invalidargumentserror-objects) for longer text.

## \_FileNameField Objects

```python theme={"dark"}
class _FileNameField()
```

#### eq

```python theme={"dark"}
def eq(name: str) -> FileNameCondition
```

Matches files with exactly this name.

#### is\_in

```python theme={"dark"}
def is_in(names: List[str]) -> FileNameCondition
```

Matches files whose name is one of `names`.

#### not\_in

```python theme={"dark"}
def not_in(names: List[str]) -> FileNameCondition
```

Matches files whose name is none of `names`.

#### contains\_text

```python theme={"dark"}
def contains_text(text: str) -> FileNameCondition
```

Matches files whose name contains `text`, ignoring case.

#### not\_contains\_text

```python theme={"dark"}
def not_contains_text(text: str) -> FileNameCondition
```

Matches files whose name doesn't contain `text`, ignoring case.

## \_DataTypeField Objects

```python theme={"dark"}
class _DataTypeField()
```

#### eq

```python theme={"dark"}
def eq(data_type: StorageItemType) -> DataTypeCondition
```

Matches files of this type.

#### is\_in

```python theme={"dark"}
def is_in(data_types: List[StorageItemType]) -> DataTypeCondition
```

Matches files of any of these types.

#### not\_in

```python theme={"dark"}
def not_in(data_types: List[StorageItemType]) -> DataTypeCondition
```

Matches files of none of these types.

## \_MimeTypeField Objects

```python theme={"dark"}
class _MimeTypeField()
```

#### eq

```python theme={"dark"}
def eq(mime_type: str) -> MimeTypeCondition
```

Matches files with this MIME type, such as `image/jpeg`.

#### is\_in

```python theme={"dark"}
def is_in(mime_types: List[str]) -> MimeTypeCondition
```

Matches files with any of these MIME types.

#### not\_in

```python theme={"dark"}
def not_in(mime_types: List[str]) -> MimeTypeCondition
```

Matches files with none of these MIME types.

## \_UploadedAtField Objects

```python theme={"dark"}
class _UploadedAtField()
```

#### gte

```python theme={"dark"}
def gte(time: datetime) -> UploadedAtCondition
```

Matches files uploaded at or after `time`, which must have a timezone.

#### lte

```python theme={"dark"}
def lte(time: datetime) -> UploadedAtCondition
```

Matches files uploaded at or before `time`, which must have a timezone.

## \_MetadataField Objects

```python theme={"dark"}
class _MetadataField()
```

#### eq

```python theme={"dark"}
def eq(value: Union[str, float, bool]) -> MetadataCondition
```

Matches files whose value for the key is `value`.

#### is\_in

```python theme={"dark"}
def is_in(values: List[str]) -> MetadataCondition
```

Matches files whose value for the key is one of `values`.

#### not\_in

```python theme={"dark"}
def not_in(values: List[str]) -> MetadataCondition
```

Matches files whose value for the key is none of `values`.

#### contains\_text

```python theme={"dark"}
def contains_text(text: str) -> MetadataCondition
```

Matches files whose value for the key contains `text`, ignoring case.

#### not\_contains\_text

```python theme={"dark"}
def not_contains_text(text: str) -> MetadataCondition
```

Matches files whose value for the key doesn't contain `text`, ignoring case.

#### gte

```python theme={"dark"}
def gte(bound: Union[float, datetime]) -> MetadataCondition
```

Matches files whose value for the key is `bound` or more: a number, or a datetime with a timezone.

#### lte

```python theme={"dark"}
def lte(bound: Union[float, datetime]) -> MetadataCondition
```

Matches files whose value for the key is `bound` or less: a number, or a datetime with a timezone.

## \_MetricField Objects

```python theme={"dark"}
class _MetricField()
```

#### gte

```python theme={"dark"}
def gte(bound: float) -> MetricCondition
```

Matches files whose metric is `bound` or more.

#### lte

```python theme={"dark"}
def lte(bound: float) -> MetricCondition
```

Matches files whose metric is `bound` or less.

## \_FrameMetadataField Objects

```python theme={"dark"}
class _FrameMetadataField()
```

#### eq

```python theme={"dark"}
def eq(value: Union[str, float, bool]) -> FrameMetadataCondition
```

Matches frames whose value for the key is `value`.

#### is\_in

```python theme={"dark"}
def is_in(values: List[str]) -> FrameMetadataCondition
```

Matches frames whose value for the key is one of `values`.

#### contains\_text

```python theme={"dark"}
def contains_text(text: str) -> FrameMetadataCondition
```

Matches frames whose value for the key contains `text`, ignoring case.

#### gte

```python theme={"dark"}
def gte(bound: Union[float, datetime]) -> FrameMetadataCondition
```

Matches frames whose value for the key is `bound` or more: a number, or a datetime with a timezone.

#### lte

```python theme={"dark"}
def lte(bound: Union[float, datetime]) -> FrameMetadataCondition
```

Matches frames whose value for the key is `bound` or less: a number, or a datetime with a timezone.

## \_FrameMetricField Objects

```python theme={"dark"}
class _FrameMetricField()
```

#### gte

```python theme={"dark"}
def gte(bound: float) -> FrameMetricCondition
```

Matches frames whose metric is `bound` or more.

#### lte

```python theme={"dark"}
def lte(bound: float) -> FrameMetricCondition
```

Matches frames whose metric is `bound` or less.

## \_FrameFields Objects

```python theme={"dark"}
class _FrameFields()
```

#### metadata

```python theme={"dark"}
def metadata(key: str) -> _FrameMetadataField
```

A key in your organization's metadata schema, on a frame.

#### metric

```python theme={"dark"}
def metric(name: FrameMetricName) -> _FrameMetricField
```

A metric of a frame.

## F Objects

```python theme={"dark"}
class F()
```

The fields a query can filter on. Each operator returns a condition for [filters](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#curationquery-objects).

* `F.file_name`: `eq`, `is_in` and `not_in` match the whole name. `contains_text` and `not_contains_text` match
  part of it, ignoring case.
* `F.data_type`: `eq`, `is_in` and `not_in`, with any [StorageItemType](https://docs.encord.com/sdk-documentation/sdk-references/orm.storage.md#storageitemtype-objects) except
  `DICOM_FILE`.
* `F.mime_type`: `eq`, `is_in` and `not_in`, with values such as `image/jpeg`.
* `F.uploaded_at`: `gte` and `lte`, each including its bound. Times must have a timezone.
* `F.metadata(key)`: a key in your organization's metadata schema, which needs premium access to Index. The key's
  type decides its operators: text takes `eq`, `is_in`, `not_in`, `contains_text` and `not_contains_text`; enum
  and uuid take `eq`, `is_in` and `not_in`; number takes `eq`, `gte` and `lte`; datetime takes `gte` and `lte`;
  boolean takes `eq`. It matches only files that have the key. To filter on a key outside the schema, add it with
  [add\_scalar()](https://docs.encord.com/sdk-documentation/sdk-references/metadata_schema.md#add_scalar) first.
* `F.metric(name)`: the file's size, `fileSize`, in bytes, with `gte` and `lte`. It needs premium access to Index.
* `F.frame.metadata(key)`: like `F.metadata(key)`, on a frame, without `not_in` and `not_contains_text`.
* `F.frame.metric(name)`: a metric of a frame, with `gte` and `lte`. `width`, `height` and `area` are in pixels,
  and they and `aspectRatio` are always available. `brightness`, `contrast`, `sharpness`, `red`, `green` and `blue`
  run from 0 to 1 and need the scope's top-level folder to be upgraded in Index to compute quality metrics.
  `uniqueness` and `diversity` run from 0 to 1 and need it to compute advanced quality metrics.

A file matches the `F.frame` conditions when one of its frames meets all of them, and they need premium access to
Index. An image's only frame is the image itself, and files without frames, such as audio files, never match them.

Lists must contain between 1 and 1,000 values. Conditions on one field combine, so `gte` and `lte` together give
a range.

#### metadata

```python theme={"dark"}
@staticmethod
def metadata(key: str) -> _MetadataField
```

A key in your organization's metadata schema.

#### metric

```python theme={"dark"}
@staticmethod
def metric(name: MetricName) -> _MetricField
```

A metric of the file.

## QueryItemsJobState Objects

```python theme={"dark"}
class QueryItemsJobState(CamelStrEnum)
```

State of a [QueryItemsJob](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#queryitemsjob-objects).

**Values:**

* **PENDING:** The job hasn't ended yet. Its `processed` and `total` say how far it has got.
* **SUCCEEDED:** The job finished, and processed every file.
* **FAILED:** The job failed. Files it had already processed stay processed; its `error` says why.
* **CANCELLED:** The job was cancelled before it finished. Files it had already processed stay processed.
* **UNKNOWN:** A state this SDK version does not recognize. Upgrade the SDK to see it.

#### \_missing\_

```python theme={"dark"}
@classmethod
def _missing_(cls, value: Any) -> "QueryItemsJobState"
```

Return UNKNOWN for any state added to the platform after this SDK version.

## QueryItemsJobFailure Objects

```python theme={"dark"}
class QueryItemsJobFailure(BaseDTO)
```

A file that a [QueryItemsJob](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#queryitemsjob-objects) couldn't process.

#### reason

Why, as a code such as `link_failed`.

## QueryItemsJobError Objects

```python theme={"dark"}
class QueryItemsJobError(BaseDTO)
```

Why a [QueryItemsJob](https://docs.encord.com/sdk-documentation/sdk-references/beta.curation_query.md#queryitemsjob-objects) failed.

#### code

A code such as `link_failed`.

## QueryItemsJob Objects

```python theme={"dark"}
class QueryItemsJob(BaseDTO)
```

A job that acts on the files a query matches, such as linking them to a dataset. Counts are in files.

#### finished\_at

When the job ended, or None until its state is final.

#### processed

Files the job has processed so far, whether or not it succeeded with them.

#### total

Files the job will process, or None until it has worked that out.

#### applied

Files the job processed successfully.

#### skipped

Files the job left as they were, or None for jobs that don't report them, such as dataset links.

#### failed

Files the job couldn't process.

#### failures

The first 100 files the job couldn't process.

#### error

Why the job failed, once its state is `FAILED`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.