Flink SQL on Confluent Cloud Invokes ML Model & AI Inference
Jul 29, 2024Diptiman Raichaudhuri

Summary
This post details the integration of AI model inference into Flink SQL on Confluent Cloud, specifically demonstrating how to invoke an OpenAI GPT-4o model for sentiment classification of product reviews. It outlines the steps involved: creating a Kafka topic, producing Avro-serialized review data, defining a Flink SQL remote model resource pointing to the OpenAI API with a specific system prompt and task ('classification'), and then using the `ML_PREDICT` function within a Flink SQL `INSERT INTO` statement to populate a downstream `product_ratings` table with sentiment ratings. The post provides code excerpts for the Python producer and Flink SQL statements, and discusses the benefits of real-time ML enrichment for streaming data.
More from the Flink AI Model Inference trail
- Flink: Programmatic Capabilities for Developers and dbt/SQL-Native for Data Practitioners
- Add Your First Flink Streaming Transformation
- Focal Systems: Boosting Store Performance with an AI Retail Operating System and Real-Time Data
- Detecting the Unexpected: Built-in Real-Time Anomaly Detection in Confluent Cloud for Apache Flink®
- Why Flink Agents Are the Future of Enterprise AI