AI Glossary · Letter Q

Q-Function.

A function in reinforcement learning that estimates the expected cumulative reward of taking a specific action in a specific state and then following the best possible policy thereafter. The Q-function is the core learned component of Q-learning and related algorithms, encoding what the agent has learned about which actions are valuable in each situation.

Also known as action-value function, Q-value function, state-action value function

What it is

A working definition of the Q-function.

In reinforcement learning, the Q-function Q(s, a) maps a state-action pair to an estimated value: the expected total future reward the agent will accumulate if it takes action a in state s and then acts optimally from that point forward. Higher Q-values indicate more valuable state-action pairs. The optimal policy derived from a converged Q-function is simple: in each state, take the action with the highest Q-value. This makes the Q-function a compact representation of optimal behavior: once the Q-function is learned, the policy is determined.

The Q-function is learned through temporal difference updates. After taking action a in state s and observing reward r and next state s’, the Q-value is updated toward the observed reward plus the discounted maximum Q-value in the next state: Q(s, a) gets closer to r + gamma * max_a’ Q(s’, a’). The discount factor gamma, between 0 and 1, controls how much the agent values immediate rewards versus future rewards. A gamma near 0 makes the agent myopic, caring mainly about immediate reward. A gamma near 1 makes the agent far-sighted, valuing long-term cumulative reward highly. For marketing applications with long customer relationship horizons, a higher gamma better captures the value of actions that build long-term customer relationships at some cost to immediate conversion.

The Q-function is stored either as a table mapping each state-action pair to a Q-value (the Q-table approach, practical only for small, discrete state spaces) or as a neural network that takes the state as input and outputs Q-values for all actions simultaneously (the deep Q-network approach, necessary for continuous or high-dimensional state spaces). Most real marketing applications require the neural network approach because customer states described by behavioral feature vectors are high-dimensional and continuous.

Why ad agencies care

Why understanding the Q-function illuminates how AI bidding and recommendation systems estimate value.

A working ad agency managing AI-driven bidding systems, recommendation engines, or customer engagement automation is working with systems that implicitly or explicitly estimate Q-function-like value functions. A bid optimization system that sets a bid price for an impression is estimating the expected cumulative value of winning that impression given the advertiser’s current budget and campaign state. A recommendation system that selects content is estimating the expected engagement value of each candidate item given the user’s current session context. Understanding the Q-function concept enables clearer thinking about what these systems are learning and what inputs they need to learn it well.

The discount factor in Q-learning determines whether the system optimizes for immediate or long-term value. A customer engagement system that uses a low discount factor will concentrate on actions that produce immediate responses, such as promotional emails that drive immediate purchases, potentially at the cost of actions that build longer-term engagement, such as educational content that increases product adoption and reduces churn. An agency configuring a reinforcement learning-based engagement system should consider whether the client’s business goals are better served by a higher discount factor that values long-term customer relationships or a lower one that prioritizes near-term conversion. This is a configuration decision with material consequences for the behavior the system learns.

Q-function learning requires the system to observe the consequences of its actions to update its value estimates. A Q-learning system improves its Q-function estimates by experiencing transitions: taking an action, observing the reward, and updating the Q-value for that state-action pair. Systems that act in sparse-reward environments, where conversions or other reward signals are rare, learn slowly because they rarely observe the reward signal needed to update Q-values. Marketing applications with very low conversion rates, such as B2B lead generation, may require reward shaping that defines intermediate rewards for early-funnel engagement signals to provide more frequent learning signal. Without intermediate rewards, the Q-function for early-stage actions receives too few direct reward updates to converge to accurate value estimates.

Exploration strategies for Q-learning must balance discovering new high-value actions against exploiting known good ones. During Q-function learning, the system must occasionally try actions it does not yet believe are optimal in order to discover whether they might be more valuable than current estimates suggest. The epsilon-greedy strategy takes the currently estimated optimal action most of the time and a random action with probability epsilon, allowing the system to discover whether untried state-action pairs have high value. For marketing systems, exploration means occasionally testing non-default bidding or messaging decisions, incurring some cost in the current period to gain information that improves future decisions. Agencies should understand that RL-based marketing systems will occasionally make non-greedy decisions as part of their learning process.

In practice

What q-function looks like inside a working ad agency.

An agency is implementing a reinforcement learning-based content recommendation system for a financial services client’s online learning platform. The platform offers 80 courses across 6 content categories, and the client wants a recommendation system that maximizes long-term learner engagement and course completion, not just immediate click-through. The Q-function in this system represents Q(learner state, recommended course): the expected cumulative engagement value of recommending a specific course to a learner in a given state. The learner state is an 18-dimensional vector capturing completed courses, current active course progress, days since last platform visit, category completion rates, and self-reported skill goals. The action space is the set of 80 courses. The Q-function is approximated by a neural network with the learner state as input and 80 Q-value outputs (one per course). The reward is defined as a composite: 0.3 for a course click, 1.0 for a course start, 3.0 for a course completion, and a 0.15 decay per day of inactivity (a negative reward that penalizes recommendations that did not sustain engagement). The discount factor gamma is set to 0.95, reflecting the client’s goal of optimizing 180-day engagement rather than immediate clicks. After 90 days of deployment with epsilon=0.1 exploration, the Q-network has processed 28,000 learner-course-outcome triplets. Analysis of the learned Q-values reveals that the system has discovered that recommending complementary courses in the same category shortly after a learner completes a course produces significantly higher 90-day engagement than cross-category recommendations, even when the cross-category recommendations produce slightly higher immediate click rates. This behavioral insight, discovered by the Q-function learning process, is incorporated into the recommendation logic and the client’s content strategy for sequencing new course releases.

Build the reinforcement learning foundations that clarify how AI systems estimate value and learn optimal decisions through The Creative Cadence Workshop.

The generative AI foundations module covers Q-learning, value functions, and the reinforcement learning framework underlying AI bidding, recommendation, and customer engagement systems that agencies deploy for clients.