> [!WARNING]
>
> **Preview**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> You can process personal data for
>
> this feature
>
> as outlined in the
> [Cloud Data
> Processing Addendum](https://docs.cloud.google.com/terms/data-processing-addendum), subject to the obligations and restrictions described in the
> agreement under which you access Google Cloud.
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

Adaptive filtering in AlloyDB AI lets you optimize filtered vector
searches by dynamically selecting between inline filtering and pre-filtering
during query execution. You can activate adaptive filtering for your
AlloyDB instance by enabling the `scann.enable_preview_features`
database flag.

> [!NOTE]
> **Note:** Inline filtering is supported only when you use the [ScaNN](https://docs.cloud.google.com/alloydb/docs/ai/scann-vector-query-perf-overview.md.txt) algorithm. Inline filtering is not compatible with the Inverted File (IVF), Inverted File Flat (IVFFlat), or Hierarchical Navigable Small Worlds (HNSW) algorithms.

## Enable adaptive filtering

To enable adaptive filtering, you must set the [`scann.enable_preview_features`](https://docs.cloud.google.com/alloydb/docs/reference/alloydb-flags.md.txt#scann.enable_preview_features) flag to `on`.

> [!NOTE]
> **Note:** The `scann.enable_preview_features` flag is an umbrella for multiple preview features and enables all of them.

```bash
gcloud alloydb instances update INSTANCE_ID \
    --database-flags scann.enable_preview_features=on \
    --region=REGION \
    --cluster=CLUSTER_ID \
    --project=PROJECT_ID
```

Replace the following:

- `INSTANCE_ID`: the ID of the instance where you want to enable adaptive filtering.
- `REGION`: the region where your instance is located---for example, `us-central1`.
- `CLUSTER_ID`: the ID of the cluster where your instance is located.
- `PROJECT_ID`: the ID of the project where your cluster is located.

Setting this flag to `on` activates the adaptive filtering behavior, allowing the query optimizer to dynamically switch between inline and pre-filtering strategies.

## What's next

- [Filtered vector search in AlloyDB AI](https://docs.cloud.google.com/alloydb/docs/ai/filtered-vector-search-overview.md.txt)
- [Understand adaptive filtering in AlloyDB AI](https://docs.cloud.google.com/alloydb/docs/ai/adaptive-filtering.md.txt)