Enrichment transform

Pydoc Pydoc




The enrichment transform lets you dynamically enrich data in a pipeline by doing a key-value lookup to a remote service. The transform uses RequestResponeIO internally. This feature uses client-side throttling to ensure that the remote service isn’t overloaded with requests. If service-side errors occur, like TooManyRequests and Timeout exceptions, it retries the requests by using exponential backoff.

This transform is available in Apache Beam 2.54.0 and later versions.

Examples

The following examples demonstrate how to create a pipeline that use the enrichment transform to enrich data from external services.

ServiceExample
Cloud BigtableEnrichment with Bigtable
Vertex AI Feature StoreEnrichment with Vertex AI Feature Store
Vertex AI Feature Store (Legacy)Enrichment with Legacy Vertex AI Feature Store

BigQuery Support

The enrichment transform supports integration with BigQuery to dynamically enrich data using BigQuery datasets. By leveraging BigQuery as an external data source, users can execute efficient lookups for data enrichment directly in their Apache Beam pipelines.

To use BigQuery for enrichment:

This integration is particularly beneficial for use cases that require augmenting real-time streaming data with information stored in BigQuery.


Batching

To optimize requests to external services, the enrichment transform uses batching. Instead of performing a lookup for each individual element, the transform groups multiple elements into a batch and performs a single lookup for the entire batch.

Advantages of Batching:

Users can configure the batch size by specifying parameters in their pipeline setup. Adjusting the batch size can help fine-tune the balance between throughput and latency.


Caching with with_redis_cache

For frequently used enrichment data, caching can significantly improve performance by reducing repeated calls to the remote service. Apache Beam’s with_redis_cache method allows you to integrate a Redis cache into the enrichment pipeline.

Benefits of Caching:

To enable caching:

  1. Set up a Redis instance accessible by your pipeline.
  2. Use the with_redis_cache method to configure the cache in your enrichment transform.
  3. Specify the time-to-live (TTL) for cache entries to ensure data freshness.

Example:

from apache_beam.transforms.enrichment import Enrichment

# Enrichment pipeline with Redis cache
enriched_data = (input_data
                 | 'Enrich with Cache' >> Enrichment(my_enrichment_transform).with_redis_cache(host, port))


## Related transforms

Not applicable.



Pydoc Pydoc