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

# Dynamic Aggregate Provider (experimental)

> The Dynamic Aggregate Provider is an experimental Atoti Java SDK feature that allows partial aggregate provider configurations to be added or removed at runtime without restarting the application, enabled by setting activeviam.feature.experimental.dynamic_aggregate_provider.enabled to true

## Introduction

The [aggregate provider configuration](./aggregate_provider) is key to accelerate the users queries. It is a compromise between memory usage and speed.
The [AI Optimizer](./ai_optimizer) can recommend a provider configuration tailored to your query history.
It is now possible to use this recommendation (or any provider description) to change the provider configuration dynamically without restarting the application.

## Enabling the dynamic aggregate provider feature

The dynamic aggregate provider must be enabled by setting the system
property `activeviam.feature.experimental.dynamic_aggregate_provider.enabled` to `true`.

## Adding a partial provider

First, define the partial provider:

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
final PartialProviderDefinition provider =
    new PartialProviderDefinition(
        "MyProvider",
        IAggregateProviderDefinition.BITMAP_PLUGIN_TYPE,
        List.of(LevelIdentifier.simple("id")),
        List.of("value.SUM"),
        PartialProviderFilters.noFilter(),
        new Properties(),
        null);
```

Then call the API to add the partial provider to the aggregate provider configuration:

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
DynamicAggregateProvider.updateAggregateProviders(
    manager, t -> t.addNewPartialAggregateProvider(CUBE, provider));
```

## Removing a partial provider

To delete an existing provider, we simply use its name:

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
DynamicAggregateProvider.updateAggregateProviders(
    manager, t -> t.removePartialAggregateProvider(CUBE, "MyProvider"));
```

## Batching operations

It is possible to add and remove several partial providers at once.

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
DynamicAggregateProvider.updateAggregateProviders(
    manager,
    t -> {
      t.addNewPartialAggregateProvider(CUBE, provider1)
          .addNewPartialAggregateProvider(CUBE, provider2);
    });
```

## Querying during updates

When the aggregate provider configuration is updated, ongoing queries are not impacted:
the previous version is still queryable.
