# A Quest for Fast Personalized Recommendation

Personalized recommender systems attempt to generate a limited number of item options (e.g., products on Amazon, movies on Netflix, or videos on Youtube, etc.) that are curated for each individual customer. The necessity of such systems is driven by the explosion of online choices, which makes it difficult for each customer to investigate every option. Therefore, more and more product and service providers are now relying on these systems to improve customer experience and conversion on their websites.

An established and prevalent technique for personalized recommendation is collaborative filtering based on matrix factorization (MF), which attempts to learn customers’ preferences from their historical activities. Let’s assume that there are * m* users, denoted as

*and*

**U***items, denoted as*

**n***. Typically, a classic matrix factorization model consists of two phases:*

**I**: this phase analyses customers’ historical activities, represented by a sparse matrix**Learning**of size**R**, to learn their preferences. Each customer*m*x*n**u*is represented by a-dimensional vector**d**and each item*x*_{u}*i*is represented by a-dimensional vector**d**, where**y**_{i}is the hypothetical number of factors that explain the behaviour of each customer. The degree of preference of a customer**d***u*for an item*i*is modelled as the inner product score. A higher inner product score implies a higher chance of the customer**(***x*)_{u}^{T}y_{i}*u*to prefer the item*i*.

: given the output vectors from the learning phase, to arrive at a personalized recommendation list for customer**Retrieval**, we need to identify the top-**u***K*items inthat have the highest inner product scores to**I**. Figure 1 illustrates the pipeline of top-**x**_{u}*K*MF recommendation retrieval, in whichdenotes the item matrix where each row represents an item vector.**Y**

The challenge of the *learning* phase is how to design effective algorithms that can learn from the data at the scale of millions of customers and items. This problem has been studied extensively in the research literature. On the other hand, the challenge of the *retrieval* phase is *speed,* due to the real-time nature of the task: *upon the arrival of a targeted customer* *u*, the system needs to quickly generate top-*K* items with highest inner product scores to ** x_{u} **be recommended for

*u*.

Formally, the above problem of finding the top-*K* MF recommendations can be stated as follows:

**(Maximum Inner Product Search-MIPS)** Given a customer vector *x _{u}*, determine the item

*i*such that:

i=\mathrm{argmax}_{j \in I} x_u^T y_j

A straightforward solution for MIPS is to compute the inner product between ** x_{u}** and all item vectors

**{**and rank these scores. However, such solution scales linearly with the number of items, which incurs the prohibitive cost given current number of items in today large-scale systems (see References [1], [2], [3] for more detailed analysis). To achieve real-time personalized recommendation, we shall look for faster alternatives to solve the MIPS problem efficiently, specifically those who can avoid examining all items in

*y*,_{1}*y*, …,_{2}*y*}_{m}*I*. In this post, we will explore such a solution, namely

*indexing.*

**Indexing for Matrix Factorization Recommendation Retrieval**

As top-*K* MF recommendation retrieval can be considered as top-*K* similarity search task with inner product as the similarity function, one can apply various approximate similarity search techniques such as indexing, quantization, or graph similarity to improve the speed of the search process. In this post, we primarily focus on indexing as it offers several appealing advantages: one-time pre-processing of item vectors, parallelizable search, and scale linearly with the number of items, etc.

Figure 2 depicts two steps of a top-*K* recommender system with the aid of indexing structures:

**Index construction**: process and store the item vectors*Y*in a data structure (e.g., hash tables, binary search trees, etc.) so that similar item vectors are stored closely in the data structure (e.g., on the same buckets of the hash tables or the same leaf nodes of the binary search tree. etc.).**Retrieval**: Given the built data structure, a search for the top-*K*most similar items to a customer vector, i.e., top-**x**_{u}*K*recommendations can be performed in order of magnitude faster than naïve exhaustive search. This is primarily due to the property of indexing structures, which can automatically remove potential irrelevant items with high confidence and reduce the number of item candidates for inner product computation and ranking.

The benefit of indexing comes at the cost of constructing the data structures to store the item vectors in new formats that support efficient similarity search, which is a one-time cost to be amortized over the many query instances.

Though having several advantages, a factor for consideration when using indexing structures for top-*K* recommendation is the growth rate of the systems. As customer preferences may change over time, new items appear, or old items are removed, maintaining a retrieval-efficient structure would require constant updates (e.g., insertion, deletion, or even re-build).

In the next part, we will investigate further some issues with using indexing for top-*K* MIPS as well as discuss some promising solutions.

**References**

**[1] **Koenigstein, Noam, Parikshit Ram, and Yuval Shavitt. “Efficient retrieval of recommendations in a matrix factorization framework.” *Proceedings of the 21st ACM international conference on Information and knowledge management*. 2012.

**[2]** Le, D. D., & Lauw, H. W. (2017, November). Indexable Bayesian Personalized Ranking for Efficient Top-k Recommendation. In *Proceedings of the 2017 ACM on Conference on Information and Knowledge Management* (pp. 1389-1398). ACM.

**[3]** Le, D. D., & Lauw, H. W (2020, Feb). Stochastically Robust Personalized Ranking for LSH Recommendation Retrieval, In *Proceeding of the 34thAAAI Conference on Artificial Intelligence *(AAAI’20), Feb 2020.