Challenge: Multipartite projections

Challenge: Create a user-genre projection

You’ve learned how to create projections with multiple node types. Now it’s your turn to create one independently.

Your task: Create a bipartite projection of Users and Genres that preserves their labels and connects them through the movies they rated.

This projection would be useful for:

  • Understanding user genre preferences

  • Finding users with similar genre tastes

  • Genre-based recommendation systems

Requirements

Your projection should:

  1. Include User and Genre nodes with labels preserved

  2. Connect users to genres through the movies they rated

  3. Preserve relationship types

  4. Name the projection 'users-genres'

Hints

You’ll need a two-hop pattern:

  • User rates a Movie

  • That Movie is in a Genre

  • Therefore, User connects to Genre

Remember the configuration parameters:

  • sourceNodeLabels for source node labels

  • targetNodeLabels for target node labels

  • relationshipType for relationship types

Solution approach

Details
cypher
Solution: Project users and genres through movies
MATCH (source:User)-[:RATED]->(:Movie)-[r:IN_GENRE]->(target:Genre) // (1)
WITH gds.graph.project( // (2)
  'users-genres', // (3)
  source, // (4)
  target, // (5)
  {
    sourceNodeLabels: labels(source), // (6)
    targetNodeLabels: labels(target), // (7)
    relationshipType: type(r) // (8)
  },
  {}
) AS g
RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels // (9)
  1. Match User nodes connected to Genre nodes through Movie nodes

  2. Call the GDS projection function

  3. Name the projection 'users-genres'

  4. Include source (User) nodes

  5. Include target (Genre) nodes

  6. Preserve source node labels

  7. Preserve target node labels

  8. Preserve relationship types

  9. Return projection statistics

Key components: - MATCH pattern connects users to genres through movies - Configuration preserves User and Genre labels - Relationship type is preserved as IN_GENRE - The result is a bipartite graph of user genre preferences

Once you have completed the previous steps, run the following query to group users by their favorite genres:

cypher
Find users with similar genre preferences
MATCH (u:User)-[:SIMILAR]-(u2:User) // (1)
WITH u.name AS name, collect(DISTINCT u2.name) AS similar_users_by_genre // (2)
RETURN name, similar_users_by_genre // (3)
  1. Match pairs of User nodes connected by SIMILAR relationships

  2. Collect distinct similar user names for each user

  3. Return user name and their list of similar users

This simple query now returns each user along with all the users who have similar tastes in genre.

Check your understanding

Understanding The Projection Pattern

In the user-genre projection, what does a connection between a User and a Genre represent?

  • ❏ The user created that genre

  • ✓ The user rated at least one movie in that genre

  • ❏ The user is an expert in that genre

  • ❏ The user and genre share the same name

Hint

Remember the projection pattern traces through movies to connect users to genres.

Solution

The user rated at least one movie in that genre is correct.

The projection pattern User → RATED → Movie → IN_GENRE → Genre creates connections between users and genres when users have rated movies that belong to those genres. This bipartite structure reveals user genre preferences based on their rating behavior.

Benefits Of Label Preservation

You’ve created a user-genre projection with preserved labels. What advantage does this give you over a default projection?

  • ❏ It uses less memory

  • ❏ It runs algorithms faster

  • ✓ You can run algorithms on only Users or only Genres by filtering node labels

  • ❏ It automatically creates recommendations

Hint

Think about what the nodeLabels parameter allows you to do when calling algorithms.

Solution

You can run algorithms on only Users or only Genres by filtering node labels is correct.

When you preserve labels in your projection, you can use the nodeLabels configuration parameter:

cypher
CALL gds.degree.stream('users-genres', {
  nodeLabels: ['Genre']
})

This runs the algorithm only on Genre nodes, showing which genres have the most user connections. Without label preservation, you can’t make this distinction—all nodes are treated identically.

Summary

Creating multi-type projections with label preservation enables type-specific analysis and filtering. By preserving User and Genre labels, you can:

  • Run algorithms on specific node types

  • Filter results by label

  • Understand user preferences at the genre level

  • Build recommendation systems based on genre affinity

You’ve now completed the graph structure types series! You understand monopartite, bipartite, and multipartite graphs, and you can create GDS projections for each. Next, you’ll learn about the different categories of algorithms available in GDS.

Chatbot

How can I help you today?