A Product Affinity Graph is a relational data structure that models products as interconnected nodes, with weighted edges quantifying the strength of their relationship based on observed customer behavior such as co-purchases, co-views, or sequential cart additions. Unlike simple collaborative filtering, this graph explicitly encodes directional and typed relationships—such as complement or substitute—enabling a merchandising engine to traverse the network and retrieve contextually relevant items for dynamic assortment optimization.
Glossary
Product Affinity Graph

What is Product Affinity Graph?
A Product Affinity Graph is a network structure where nodes represent products and edges represent co-purchase or co-view relationships, used to generate substitutable or complementary recommendations.
In a real-time retail environment, the graph powers inventory-aware substitution logic by identifying the strongest available alternative when a primary item stocks out, preventing broken customer journeys. By analyzing local purchasing patterns, a localized affinity scoring mechanism can re-weight graph edges for specific geographic clusters, ensuring that a substitute recommendation in one region does not cannibalize a complement in another.
Key Characteristics of Product Affinity Graphs
Product Affinity Graphs are network structures where nodes represent products and edges represent co-purchase or co-view relationships, used to generate substitutable or complementary recommendations.
Graph Topology & Edge Weighting
The graph is a weighted, directed network where edge strength quantifies the affinity between two products. Weights are typically derived from conditional probability—the likelihood of purchasing product B given product A is in the cart—or from cosine similarity between product embedding vectors. This structure enables the system to distinguish between strong complements (e.g., a phone and its specific case) and weak associations (e.g., a phone and a generic screen cleaner).
Complement vs. Substitute Logic
Edges are categorized by relationship type to power distinct merchandising strategies. A complementary edge connects items bought together (e.g., a camera and a memory card), driving cross-sell recommendations. A substitutable edge connects items viewed or bought instead of each other (e.g., two brands of the same cereal), enabling intelligent backfill when a product is out of stock. This classification is often determined by analyzing post-purchase return rates or session co-browsing patterns.
Real-Time Inventory Awareness
Modern affinity graphs integrate with inventory telemetry to prevent recommending unavailable items. Each node carries a dynamic stock_status attribute. During graph traversal for recommendation generation, nodes with a stockout_probability above a threshold are pruned from the candidate set. This ensures the system only surfaces availability-weighted relevance, directly linking the graph's mathematical structure to operational reality.
Localized Affinity Scoring
Global affinity graphs often fail to capture regional taste variations. Localized Affinity Scoring creates geo-specific graph layers by filtering co-purchase data through a geospatial demand cluster. An edge between craft beer A and craft beer B might be strong in one city but nonexistent in another. This allows the same recommendation engine to serve a micro-merchandising zone with culturally relevant suggestions without manual curation.
Cold Start Mitigation via Content-Based Edges
New products with no transactional history lack collaborative edges. To solve this cold start problem, the graph is initialized with content-based edges derived from product attribute similarity (e.g., same brand, category, color, or material). These edges are initially weak but provide a starting point for exploration. As interaction data accumulates, a contextual assortment bandit can shift traffic from content-based to behavior-based edges, dynamically re-weighting the graph.
Demand Transference for Substitution
When a primary product is out of stock, the affinity graph drives demand transference modeling. The system traverses the outbound substitutable edges of the unavailable node, selecting the connected product with the highest edge weight that is currently in stock. This predicts which alternative the customer is most likely to accept, minimizing lost revenue. The success of the substitution is fed back into the graph to reinforce or decay the edge weight.
Frequently Asked Questions
Clear, technical answers to the most common questions about product affinity graphs, their mechanisms, and their role in dynamic retail hyper-personalization.
A product affinity graph is a network data structure where nodes represent individual products and edges represent the strength and type of relationship between them—such as co-purchase frequency, co-view similarity, or substitutability. It works by ingesting historical transaction and behavioral data, then applying algorithms like collaborative filtering, market basket analysis, or graph neural networks to calculate edge weights. These weights quantify the probability that a customer who interacts with product A will also engage with product B. The resulting graph enables real-time retrieval of related items for recommendation carousels, search ranking boosts, and dynamic assortment logic. Unlike simple item-to-item similarity matrices, a graph structure allows for multi-hop reasoning—traversing from a seed product through intermediate nodes to discover non-obvious, high-affinity recommendations that a direct pairwise comparison would miss.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Core concepts that underpin the construction, analysis, and operational use of product affinity graphs in retail personalization.
Substitution vs. Complement Classification
A critical distinction in affinity graphs that determines whether a product edge represents a substitutable or complementary relationship. Misclassifying these leads to poor recommendations—suggesting a competing product when cross-selling is intended.
- Substitutes: Products that fulfill the same need (e.g., two brands of AA batteries). Identified by co-view but not co-purchase patterns, or by temporal separation in repeat purchases
- Complements: Products used together (e.g., a camera and a memory card). Identified by co-purchase within the same session or basket
- Advanced models use session-level temporal analysis and product category taxonomies to disambiguate these edge types automatically
Session-Based Affinity Mining
The process of extracting product relationship signals from real-time user session data rather than historical purchase records alone. This captures emerging trends and short-lived affinities that batch processing misses.
- Session windows (typically 30 minutes to 2 hours) define the boundary within which interactions are considered related
- Sequential patterns (e.g., viewing A then B then adding C to cart) provide richer affinity signals than simple co-occurrence
- Streaming architectures using Apache Kafka and Apache Flink enable continuous graph edge updates as new session data arrives, keeping the affinity graph fresh
Edge Weighting & Decay Functions
The mathematical formulation that assigns strength scores to connections in the affinity graph. Raw co-occurrence counts are rarely sufficient; sophisticated weighting accounts for popularity bias, recency, and confidence.
- Pointwise Mutual Information (PMI) normalizes co-occurrence by individual item popularity, preventing best-sellers from dominating all edges
- Temporal decay (e.g., exponential or half-life functions) reduces the weight of older interactions, allowing the graph to adapt to seasonal trends and shifting preferences
- Confidence weighting uses interaction type (purchase > add-to-cart > view) and engagement depth (dwell time, scroll depth) to differentiate weak signals from strong intent

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us