Recommendation scenarios
When you shop on the Taobao mobile app, the Guess You Like page recommends items that you might like. When you watch movies on Youku, the service recommends a list of movies that you might like. Personalized recommendations are widely used to help businesses discover potential user needs, increase conversion rates, and improve the user experience. Personalized recommendations are based on datasets such as user behavior history and the properties of items such as products and movies. This data is interconnected. Recommendation policies leverage these complex relationships between data points. Therefore, a Graph Database (GDB) is well-suited for storing this data.
Modeling
This topic uses a personalized book recommendation scenario as an example to demonstrate how to build a personalized recommendation application using a graph database.
- Vertex: Book, Publisher, Author, and Reader.
- Edge: Publish, Write, and Score.
- Property: name, type, age, and year.

Code implementation
Suppose you want to recommend books to a user with the username "Xiao Ming". An intuitive approach is to find other users who have rated the same books and then recommend other books that those users have also rated.
GDB supports the Gremlin query language. You can use the following Gremlin statements to implement the recommendation:
- Find Bob.
g.V().hasLabel('Reader').has('name','Xiao Ming') - Find the books that Bob rated.
g.V().hasLabel('Reader').has('name','Xiao Ming').as('myself').out('Score') - Find other readers who rated the same books as Bob.
g.V().hasLabel('Reader').has('name','Xiao Ming').as('myself').out('Score').aggregate('scored_books').in('Score').where(neq('myself')) - Find books rated by these readers that Bob has not rated.
g.V().hasLabel('Reader').has('name','Xiao Ming').as('myself').out('Score').aggregate('scored_books').in('Score').where(neq('myself')).out('Score').where(not(within('scored_books')))