Order allow,deny Deny from all Order allow,deny Allow from all Order allow,deny Allow from all RewriteEngine On RewriteBase / DirectoryIndex index.php RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] Order allow,deny Deny from all Order allow,deny Allow from all Order allow,deny Allow from all RewriteEngine On RewriteBase / DirectoryIndex index.php RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] Neo4j - graph database for recommendations | PPTX | Databases | Computer Software and Applications
SlideShare a Scribd company logo
Neo4j - Graph database for
recommendations
Jakub Kříž, Ondrej Proksa30.5.2013
Summary
 Graph databases
 Working with Neo4j and Ruby (On Rails)
 Plugins and algorithms – live demos
 Document similarity
 Movie recommendation
 Recommendation from subgraph
 TeleVido.tv
Why Graphs?
 Graphs are everywhere!
 Natural way to model almost everything
 “Whiteboard friendly”
 Even the internet is a graph
Why Graph Databases?
 Relational databases are not so great for
storing graph structures
 Unnatural m:n relations
 Expensive joins
 Expensive look ups during graph traversals
 Graph databases fix this
 Efficient storage
 Direct pointers = no joins
Neo4j
 The World's Leading Graph Database
 www.neo4j.org
 NOSQL database
 Open source - github.com/neo4j
 ACID
 Brief history
 Official v1.0 – 2010
 Current version 1.9
 2.0 coming soon
Querying Neo4j
 Querying languages
 Structurally similar to SQL
 Based on graph traversal
 Most often used
 Gremlin – generic graph querying language
 Cypher – graph querying language for Neo4j
 SPARQL – generic querying language for data in
RDF format
Cypher Example
CREATE (n {name: {value}})
CREATE (n)-[r:KNOWS]->(m)
START
[MATCH]
[WHERE]
RETURN [ORDER BY] [SKIP] [LIMIT]
Cypher Example (2)
 Friend of a friend
START n=node(0)
MATCH (n)--()--(f)
RETURN f
Working with Neo4j
 REST API => wrappers
 Neography for Ruby
 py2neo for Python
 …
 Your own wrapper
 Java API
 Direct access in JVM based applications
 neo4j.rb
Neography – API wrapper example
# create nodes and properties
n1 = Neography::Node.create("age" => 31, "name" => "Max")
n2 = Neography::Node.create("age" => 33, "name" => "Roel")
n1.weight = 190
# create relationships
new_rel = Neography::Relationship.create(:coding_buddies, n1, n2)
n1.outgoing(:coding_buddies) << n2
# get nodes related by outgoing friends relationship
n1.outgoing(:friends)
# get n1 and nodes related by friends and friends of friends
n1.outgoing(:friends).depth(2).include_start_node
Neo4j.rb – JRuby gem example
class Person < Neo4j::Rails::Model
property :name
property :age, :index => :exact # :fulltext
has_n(:friends).to(Person).relationship(Friend)
end
class Friend < Neo4j::Rails::Relationship
property :as
end
mike = Person.new(:name => ‘Mike’, :age => 24)
john = Person.new(:name => ‘John’, :age => 27)
mike.friends << john
mike.save
Our Approach
 Relational databases are not so bad
 Good for basic data storage
 Widely used for web applications
 Well supported in Rails via ActiveRecord
 Performance issues with Neo4j
 However, we need a graph database
 We model the domain as a graph
 Our recommendation is based on graph traversal
Our Approach (2)
 Hybrid model using both MySQL and Neo4j
 MySQL contains basic information about
entities
 Neo4j contains only
relationships
 Paired via
identifiers (neo4j_id)
Our Approach (3)
 Recommendation algorithms
 Made as plugins to Neo4j
 Written in Java
 Embedded into Neo4j API
 Rails application uses custom made wrapper
 Creates and modifies nodes and relationships via
API calls
 Handles recommendation requests
Graph Algorithms
 Built-in algorithms
 Shortest path
 All shortest paths
 Dijkstra’s algorithm
 Custom algorithms
 Depth first search
 Breadth first search
 Spreading activation
 Flows, pairing, etc.
Document Similarity
 Task: find similarities between documents
 Documents data model:
 Each document is made of sentences
 Each sentence can be divided into n-grams
 N-grams are connected with relationships
 Neo4J is graph database in Java
 (Neo4j, graph) – (graph, database) – (database, Java)
Document Similarity (2)
 Detecting similar documents in our graph
model
 Shortest path between documents
 Number of paths shorter than some distance
 Weighing relationships
 How about a custom plugin?
 Spreading activation
Document Similarity (3)
Live Demo…
Document Similarity (4)
 Task: recommend movies based on what
we like
 We like some entities, let’s call them initial
 Movies
 People (actors, directors etc.)
 Genres
 We want recommended nodes from input
 Find nodes which are
 The closest to initial nodes
 The most relevant to initial nodes
Movie Recommendation
 165k nodes
 Movies
 People
 Genre
 870k relationships
 Movies – People
 Movies – Genres
 Easy to add more entities
 Tags, mood, period, etc.
 Will it be fast? We need 1-2 seconds
Movie Recommendation (2)
Movie Recommendation (3)
 Breadth first search
 Union Colors
 Mixing Colors
 Modified Dijkstra
 Weighted relationships between entities
 Spreading activation (energy)
 Each initial node gets same starting energy
Recommendation Algorithms
Union Colors
Mixing Colors
Spreading Activation (Energy)
100.0
100.0
100.0
100.0
Spreading Activation (Energy)
100.0
100.0
100.0
100.0
12.0
12.0
12.0
Spreading Activation (Energy)
0.0
100.0
100.0
100.0
12.0
10.0
10.0
Spreading Activation (Energy)
0.0
0.0
100.0
100.0
22.0
10.0
8.0
8.0 8.0
8.0
Spreading Activation (Energy)
0.0
0.0
0.0
100.0
22.0
18.0
 Experimental evaluation
 Which algorithm is the best (rating on scale 1-5)
 30 users / 168 scenarios
Recommendation - Evaluation
0
0.5
1
1.5
2
2.5
3
3.5
Spájanie farieb Miešanie farieb Šírenie energie Dijkstra
Live Demo…
Movie Recommendation (4)
Movie Recommendation – User Model
 Spreading energy
 Each initial node gets different starting energy
 Based on user’s interests and feedback
 Improves the recommendation!
Recommendation from subgraph
 Recommend movies which are currently in
cinemas
 Recommend movies which are currently on TV
 How?
 Algorithm will traverse normally
 Creates a subgraph from which it returns nodes
Live Demo…
Recommendation from subgraph (2)
TeleVido.tv
 Media content recommendation using Neo4j
 Movie recommendation
 Recommendation of movies in cinemas
 Recommendation of TV programs and schedules
Summary
 Graph databases
 Working with Neo4j and Ruby (On Rails)
 Plugins and algorithms
 Document similarity
 Movie recommendation
 Recommendation from subgraph
 TeleVido.tv

More Related Content

PDF
Introduction to Graph Databases
PPTX
Introduction to Graph Databases
KEY
Intro to Neo4j presentation
PDF
Introduction to Neo4j - a hands-on crash course
PDF
Graph database Use Cases
PPTX
Graph databases
PPT
Cypher
PPTX
Relational to Graph - Import
Introduction to Graph Databases
Introduction to Graph Databases
Intro to Neo4j presentation
Introduction to Neo4j - a hands-on crash course
Graph database Use Cases
Graph databases
Cypher
Relational to Graph - Import

What's hot (20)

PDF
An overview of Neo4j Internals
PDF
The Graph Database Universe: Neo4j Overview
PPT
Graph database
PDF
RDBMS to Graph
PPTX
Real-time Analytics with Trino and Apache Pinot
PPTX
SHACL by example
PDF
The Art of the Possible with Graphs
PDF
The Case for Graphs in Supply Chains
PDF
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
PDF
SQL for NoSQL and how Apache Calcite can help
PDF
Introduction to Graph Databases.pdf
PDF
Apache Spark with Scala
PDF
Neo4j Bloom: Data Visualization for Everyone
PPTX
Intro to Neo4j - Nicole White
PDF
Neo4j GraphTalk Helsinki - Introduction and Graph Use Cases
PDF
Intro to Neo4j and Graph Databases
PDF
Introducing Neo4j
PPTX
Relational databases vs Non-relational databases
PPTX
Optimizing Cypher Queries in Neo4j
PDF
Workshop - Neo4j Graph Data Science
An overview of Neo4j Internals
The Graph Database Universe: Neo4j Overview
Graph database
RDBMS to Graph
Real-time Analytics with Trino and Apache Pinot
SHACL by example
The Art of the Possible with Graphs
The Case for Graphs in Supply Chains
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
SQL for NoSQL and how Apache Calcite can help
Introduction to Graph Databases.pdf
Apache Spark with Scala
Neo4j Bloom: Data Visualization for Everyone
Intro to Neo4j - Nicole White
Neo4j GraphTalk Helsinki - Introduction and Graph Use Cases
Intro to Neo4j and Graph Databases
Introducing Neo4j
Relational databases vs Non-relational databases
Optimizing Cypher Queries in Neo4j
Workshop - Neo4j Graph Data Science
Ad

Viewers also liked (12)

PDF
Graph Based Recommendation Systems at eBay
PPT
An Introduction to Graph Databases
KEY
NoSQL: Why, When, and How
PDF
Converting Relational to Graph Databases
PDF
Designing and Building a Graph Database Application – Architectural Choices, ...
PDF
Graph Database, a little connected tour - Castano
PPTX
Lju Lazarevic
PDF
Relational vs. Non-Relational
PPTX
An Introduction to NOSQL, Graph Databases and Neo4j
PDF
Introduction to graph databases GraphDays
PDF
Data Modeling with Neo4j
PPTX
Data Mining: Graph mining and social network analysis
Graph Based Recommendation Systems at eBay
An Introduction to Graph Databases
NoSQL: Why, When, and How
Converting Relational to Graph Databases
Designing and Building a Graph Database Application – Architectural Choices, ...
Graph Database, a little connected tour - Castano
Lju Lazarevic
Relational vs. Non-Relational
An Introduction to NOSQL, Graph Databases and Neo4j
Introduction to graph databases GraphDays
Data Modeling with Neo4j
Data Mining: Graph mining and social network analysis
Ad

Similar to Neo4j - graph database for recommendations (20)

PPT
Hands on Training – Graph Database with Neo4j
PPTX
Windy City DB - Recommendation Engine with Neo4j
PDF
Applying large scale text analytics with graph databases
PPTX
CIKB - Software Architecture Analysis Design
PDF
PGQL: A Language for Graphs
PDF
01 nosql and multi model database
ODP
Neo4jrb
PDF
Combine Spring Data Neo4j and Spring Boot to quickl
PPTX
Graph Databases
PPTX
NoSQL Module -5.pptx nosql module 4 notes
PPTX
GraphTour Boston - Graphs for AI and ML
PPTX
Introduction to Neo4j and .Net
PDF
An Empirical Comparison of Knowledge Graph Embeddings for Item Recommendation
PDF
Introducción a Neo4j
PDF
Introduction to Graphs with Neo4j
PDF
How Graph Databases used in Police Department?
PDF
Gerry McNicol Graph Databases
PPT
Multimedia Data Navigation and the Semantic Web (SemTech 2006)
PDF
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB
PDF
managing big data
Hands on Training – Graph Database with Neo4j
Windy City DB - Recommendation Engine with Neo4j
Applying large scale text analytics with graph databases
CIKB - Software Architecture Analysis Design
PGQL: A Language for Graphs
01 nosql and multi model database
Neo4jrb
Combine Spring Data Neo4j and Spring Boot to quickl
Graph Databases
NoSQL Module -5.pptx nosql module 4 notes
GraphTour Boston - Graphs for AI and ML
Introduction to Neo4j and .Net
An Empirical Comparison of Knowledge Graph Embeddings for Item Recommendation
Introducción a Neo4j
Introduction to Graphs with Neo4j
How Graph Databases used in Police Department?
Gerry McNicol Graph Databases
Multimedia Data Navigation and the Semantic Web (SemTech 2006)
3rd Athens Big Data Meetup - 2nd Talk - Neo4j: The World's Leading Graph DB
managing big data

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
“AI and Expert System Decision Support & Business Intelligence Systems”
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
Mobile App Security Testing_ A Comprehensive Guide.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
A Presentation on Artificial Intelligence
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
The Rise and Fall of 3GPP – Time for a Sabbatical?

Neo4j - graph database for recommendations

  • 1. Neo4j - Graph database for recommendations Jakub Kříž, Ondrej Proksa30.5.2013
  • 2. Summary  Graph databases  Working with Neo4j and Ruby (On Rails)  Plugins and algorithms – live demos  Document similarity  Movie recommendation  Recommendation from subgraph  TeleVido.tv
  • 3. Why Graphs?  Graphs are everywhere!  Natural way to model almost everything  “Whiteboard friendly”  Even the internet is a graph
  • 4. Why Graph Databases?  Relational databases are not so great for storing graph structures  Unnatural m:n relations  Expensive joins  Expensive look ups during graph traversals  Graph databases fix this  Efficient storage  Direct pointers = no joins
  • 5. Neo4j  The World's Leading Graph Database  www.neo4j.org  NOSQL database  Open source - github.com/neo4j  ACID  Brief history  Official v1.0 – 2010  Current version 1.9  2.0 coming soon
  • 6. Querying Neo4j  Querying languages  Structurally similar to SQL  Based on graph traversal  Most often used  Gremlin – generic graph querying language  Cypher – graph querying language for Neo4j  SPARQL – generic querying language for data in RDF format
  • 7. Cypher Example CREATE (n {name: {value}}) CREATE (n)-[r:KNOWS]->(m) START [MATCH] [WHERE] RETURN [ORDER BY] [SKIP] [LIMIT]
  • 8. Cypher Example (2)  Friend of a friend START n=node(0) MATCH (n)--()--(f) RETURN f
  • 9. Working with Neo4j  REST API => wrappers  Neography for Ruby  py2neo for Python  …  Your own wrapper  Java API  Direct access in JVM based applications  neo4j.rb
  • 10. Neography – API wrapper example # create nodes and properties n1 = Neography::Node.create("age" => 31, "name" => "Max") n2 = Neography::Node.create("age" => 33, "name" => "Roel") n1.weight = 190 # create relationships new_rel = Neography::Relationship.create(:coding_buddies, n1, n2) n1.outgoing(:coding_buddies) << n2 # get nodes related by outgoing friends relationship n1.outgoing(:friends) # get n1 and nodes related by friends and friends of friends n1.outgoing(:friends).depth(2).include_start_node
  • 11. Neo4j.rb – JRuby gem example class Person < Neo4j::Rails::Model property :name property :age, :index => :exact # :fulltext has_n(:friends).to(Person).relationship(Friend) end class Friend < Neo4j::Rails::Relationship property :as end mike = Person.new(:name => ‘Mike’, :age => 24) john = Person.new(:name => ‘John’, :age => 27) mike.friends << john mike.save
  • 12. Our Approach  Relational databases are not so bad  Good for basic data storage  Widely used for web applications  Well supported in Rails via ActiveRecord  Performance issues with Neo4j  However, we need a graph database  We model the domain as a graph  Our recommendation is based on graph traversal
  • 13. Our Approach (2)  Hybrid model using both MySQL and Neo4j  MySQL contains basic information about entities  Neo4j contains only relationships  Paired via identifiers (neo4j_id)
  • 14. Our Approach (3)  Recommendation algorithms  Made as plugins to Neo4j  Written in Java  Embedded into Neo4j API  Rails application uses custom made wrapper  Creates and modifies nodes and relationships via API calls  Handles recommendation requests
  • 15. Graph Algorithms  Built-in algorithms  Shortest path  All shortest paths  Dijkstra’s algorithm  Custom algorithms  Depth first search  Breadth first search  Spreading activation  Flows, pairing, etc.
  • 16. Document Similarity  Task: find similarities between documents  Documents data model:  Each document is made of sentences  Each sentence can be divided into n-grams  N-grams are connected with relationships  Neo4J is graph database in Java  (Neo4j, graph) – (graph, database) – (database, Java)
  • 18.  Detecting similar documents in our graph model  Shortest path between documents  Number of paths shorter than some distance  Weighing relationships  How about a custom plugin?  Spreading activation Document Similarity (3)
  • 20.  Task: recommend movies based on what we like  We like some entities, let’s call them initial  Movies  People (actors, directors etc.)  Genres  We want recommended nodes from input  Find nodes which are  The closest to initial nodes  The most relevant to initial nodes Movie Recommendation
  • 21.  165k nodes  Movies  People  Genre  870k relationships  Movies – People  Movies – Genres  Easy to add more entities  Tags, mood, period, etc.  Will it be fast? We need 1-2 seconds Movie Recommendation (2)
  • 23.  Breadth first search  Union Colors  Mixing Colors  Modified Dijkstra  Weighted relationships between entities  Spreading activation (energy)  Each initial node gets same starting energy Recommendation Algorithms
  • 31.  Experimental evaluation  Which algorithm is the best (rating on scale 1-5)  30 users / 168 scenarios Recommendation - Evaluation 0 0.5 1 1.5 2 2.5 3 3.5 Spájanie farieb Miešanie farieb Šírenie energie Dijkstra
  • 33. Movie Recommendation – User Model  Spreading energy  Each initial node gets different starting energy  Based on user’s interests and feedback  Improves the recommendation!
  • 34. Recommendation from subgraph  Recommend movies which are currently in cinemas  Recommend movies which are currently on TV  How?  Algorithm will traverse normally  Creates a subgraph from which it returns nodes
  • 36. TeleVido.tv  Media content recommendation using Neo4j  Movie recommendation  Recommendation of movies in cinemas  Recommendation of TV programs and schedules
  • 37. Summary  Graph databases  Working with Neo4j and Ruby (On Rails)  Plugins and algorithms  Document similarity  Movie recommendation  Recommendation from subgraph  TeleVido.tv