SlideShare ist ein Scribd-Unternehmen logo
1 von 116
Neo4j -
      from 0 to Her0
     Thank you Trulia!
Peter Neubauer   Andreas Kollegger   Michael Hunger
@peterneubauer   @akollegger         @mesirii
#neo4j
                                                      1
Neo4j -
      from 0 to Her0
     Thank you Trulia!
Peter Neubauer   Andreas Kollegger   Michael Hunger
@peterneubauer   @akollegger         @mesirii
#neo4j
                                                      1
Neo4j



         Neo4j -
      from 0 to Her0
     Thank you Trulia!
Peter Neubauer   Andreas Kollegger   Michael Hunger
@peterneubauer   @akollegger         @mesirii
#neo4j
                                                      1
1
2
Um, Neo for what?




                    2
Um, Neo for what?


•Neo4j - the graph database
•Graph
•no: not for charts & diagrams, or vector artwork
•yes: for storing data that is connected
•remember linker lists, trees?
•graphs are the general-purpose data structure



                                               2
Neo4j is a Graph Database




                            3
Neo4j is a Graph Database
๏ A Graph Database:




                            3
Neo4j is a Graph Database
๏ A Graph Database:
   • a Property Graph with Nodes, Relationships
     and Properties on both




                                                  3
Neo4j is a Graph Database
๏ A Graph Database:
   • a Property Graph with Nodes, Relationships
     and Properties on both

   • perfect for complex, highly connected data




                                                  3
Neo4j is a Graph Database
๏ A Graph Database:
   • a Property Graph with Nodes, Relationships
     and Properties on both

   • perfect for complex, highly connected data
๏ A Graph Database:




                                                  3
Neo4j is a Graph Database
๏ A Graph Database:
   • a Property Graph with Nodes, Relationships
     and Properties on both

   • perfect for complex, highly connected data
๏ A Graph Database:
   • reliable with real ACID Transactions


                                                  3
Neo4j is a Graph Database
๏ A Graph Database:
   • a Property Graph with Nodes, Relationships
     and Properties on both

   • perfect for complex, highly connected data
๏ A Graph Database:
   • reliable with real ACID Transactions
   • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion
       Properties



                                                                  3
Neo4j is a Graph Database
๏ A Graph Database:
   • a Property Graph with Nodes, Relationships
     and Properties on both

   • perfect for complex, highly connected data
๏ A Graph Database:
   • reliable with real ACID Transactions
   • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion
       Properties

   • Server with REST API, or Embeddable on the JVM
                                                                  3
Neo4j is a Graph Database
๏ A Graph Database:
   • a Property Graph with Nodes, Relationships
     and Properties on both

   • perfect for complex, highly connected data
๏ A Graph Database:
   • reliable with real ACID Transactions
   • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion
       Properties

   • Server with REST API, or Embeddable on the JVM
   • high-performance with High-Availability (read scaling)       3
Graph DB 101


               4
5
You know relational




                      5
You know relational




                      5
You know relational




          foo

                      5
You know relational




          foo         bar

                            5
You know relational




          foo   foo_bar   bar

                                5
You know relational




          foo   foo_bar   bar

                                5
You know relational




          foo   foo_bar   bar

                                5
You know relational




          foo   foo_bar   bar

                                5
You know relational
now consider relationships...




                                5
You know relational
now consider relationships...




                                5
You know relational
now consider relationships...




                                5
You know relational
now consider relationships...




                                5
You know relational
now consider relationships...




                                5
You know relational
now consider relationships...




                                5
5
6
We're talking about a
Property Graph




                        6
We're talking about a
Property Graph


    Nodes




                        6
We're talking about a
Property Graph


    Nodes


     Relationships




                        6
We're talking about a
Property Graph
                                            Em                                       Joh
                                                 il                                      a   n
                                  knows                                     knows
                     Alli                                         Tob                                    Lar

    Nodes
                            son                                       ias           knows                   s
                                                          knows
                                          And                                       And                  knows
                     knows                      rea                                       rés
                                                      s
                                                          knows             knows                knows
                     Pet                                          Miic
                                                                  Mc                knows                 Ian
                        er                knows                        a
                                                                       a
                                  knows                   knows
                                           De                                       Mic
                                              lia                                      h   ael

     Relationships

            Properties (each a key+value)

       + Indexes (for easy look-ups)
                                                                                                                 6
6
7
And, but, so how do you
query this "graph" database?



                         7
Cypher Query Language
What is Cypher?


• Graph Query Language for Neo4j
• Aims to make querying simple
Design Decisions
 Pattern matching
Design Decisions

 Pattern matching

                       A


                   B       C
Design Decisions
 Pattern matching
Design Decisions
 Pattern matching
Design Decisions
 Pattern matching
Design Decisions
 Pattern matching
Design Decisions
 ASCII-art patterns
Design Decisions
 ASCII-art patterns




           () --> ()
Design Decisions
 Directed relationship


             A           B
Design Decisions
 Directed relationship


             A           B

        (A) --> (B)
Design Decisions
 Undirected relationship


             A             B
Design Decisions
 Undirected relationship


             A             B

         (A) -- (B)
Design Decisions
 specific relationships

                   LOVES
             A             B
Design Decisions
 specific relationships

                   LOVES
             A             B

          A -[:LOVES]-> B
Design Decisions
 Joined paths


      A            B   C
Design Decisions
 Joined paths


      A            B   C

     A --> B --> C
Design Decisions
 multiple paths

                       A


                   B       C
Design Decisions
 multiple paths

                       A


                   B       C

     A --> B --> C, A --> C
Design Decisions
 multiple paths

                       A


                   B       C

     A --> B --> C, A --> C
      A --> B --> C <-- A
Design Decisions
 Optional relationships


             A            B
Design Decisions
 Optional relationships


             A            B

         A -[?]-> B
SELECT skills.*, user_skill.*
FROM users
JOIN user_skill ON users.id = user_skill.user_id
JOIN skills ON user_skill.skill_id = skill.id WHERE
users.id = 1
START user = node(1)
MATCH user -[user_skill]-> skill
RETURN skill, user_skill
Indexes

Used as multiple starting points, not to speed
up any traversals


START a = node:nodes_index(type='User') MATCH
a-[r:knows]-b
RETURN ID(a), ID(b), r.weight
Variable length Path Match

Some UGLY recursive self join on the groups
table


START max=node:person(name=“Max")
MATCH group <-[:BELONGS_TO*]- max
RETURN group
27
Who uses this stuff?




                       27
[A] Mmm Pancakes
[A] Mmm Pancakes
Cute meta + data




This Material is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the
MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/
Cute meta + data




This Material is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the
MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/
Neo4J Co-Existence

        •         Node uuids as refs in external ElasticSearch
                  also in internal Lucene
        •         Custom search ranking for user history based on
                  node relationship data
        •         MySQL for user data, Redis for metrics


This Material is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the
MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/
[B] ACL from Hell




One of the top 10 telcos worldwide
Example Access Authorization
                                                                             User
Access may be given directly or by inheritance                               Customer
                                                                             Account
                                                U                            Subscription
                 U                                      Inherit = true
                          Inherit =
                                    false
                In


                                                C
                  he
                    rit
                     =




C                                                          C                                C
                      tru
                         e




        A                        A              A                    A           A


    S       S                S       S      S       S            S       S   S         S
[C] Master of your Domain
[C] MDM within Cisco
master data management, sales compensation management, online customer support


Description                                                          Benefits
Real-time conflict detection in sales compensation management.        Performance : “Minutes to Milliseconds”
Business-critical “P1” system. Neo4j allows Cisco to model complex   Outperforms Oracle RAC, serving complex queries in real time
algorithms, which still maintaining high performance over a large    Flexibility
dataset.                                                             Allows for Cisco to model interconnected data and complex queries with
                                                                     ease
Background
                                                                     Robustness
Neo4j replaces Oracle RAC, which was not performant enough for the
                                                                     With 9+ years of production experience, Neo4j brings a solid product.
use case.




Architecture
3-node Enterprise cluster with mirrored
disaster recovery cluster
Dedicated hardware in own datacenter
Embedded in custom webapp
Sizing
35 million nodes
50 million relationships
600 million properties
35
Webadmin




           35
36
Graph -[:Cypher]-> JDBC




                      36
37
Today’s app:
  Cineasts




               37
38
The domain model




                   38
39
Hands-on: Installation




                         39
Hands-on: Installation


•copy zip drive contents to your box
•cd cineasts
•./import.sh
•neo4j/bin/neo4j-shell
•http://localhost:7474



                                       39
Some Links
๏ GraphConnect
๏ Community: http://neo4j.org




                                40
41
Cypher - overview
๏ a pattern-matching query language
๏ declarative grammar with clauses (like SQL)
๏ aggregation, ordering, limits
๏ create, read, update, delete




                                                41
42
Cypher - read clauses
๏ Find a place to begin:
   •START <lookup>
๏ Describe what to find:
   •MATCH <paths>
๏ Filter the elements:
   •WHERE <filters>
๏ RETURN <values>



                           42
43
Cypher: START + RETURN
๏ START <lookup> RETURN <expressions>
๏ START binds terms using simple look-up
   •directly using known ids
   •or based on indexed Property
๏ RETURN expressions specify result set




                                           43
Cypher: START + RETURN
๏ START <lookup> RETURN <expressions>
๏ START binds terms using simple look-up
   •directly using known ids
   •or based on indexed Property
๏ RETURN expressions specify result set



  // lookup node id 1, return that node
  start n=node(1) return n

  // lookup all nodes
  start n=node(*) return n
                                           43
44
Cypher: MATCH
๏ START <lookup> MATCH <pattern> RETURN <expr>
๏ MATCH describes a pattern of nodes+relationships
   •node terms in optional parenthesis
   •lines with arrows for relationships




                                                 44
Cypher: MATCH
๏ START <lookup> MATCH <pattern> RETURN <expr>
๏ MATCH describes a pattern of nodes+relationships
   •node terms in optional parenthesis
   •lines with arrows for relationships
 // lookup 'n', traverse any relationship to some 'm'
 start n=node(0) match (n)--(m) return n,m;
 // any outgoing relationship from 'n' to 'm'
 start n=node(1) match n-->m return n,m;
 // only 'next' relationships from 'n' to 'm' up to 3 away
 start n=node(1) match p=n-[:next*..3]->m return p;
 // from 'n' to 'm' and capture the relationship as 'r'
 start n=node(1) match n-[r]->m return n,r,m


                                                       44
45
Cypher: WHERE
๏ START <lookup> [MATCH <pattern>]
 WHERE <condition> RETURN <expr>
๏ WHERE filters nodes or relationships
   •uses expressions to constrain elements




                                             45
Cypher: WHERE
๏ START <lookup> [MATCH <pattern>]
 WHERE <condition> RETURN <expr>
๏ WHERE filters nodes or relationships
   •uses expressions to constrain elements
  // lookup all nodes as 'n', constrained to name 'Andreas'
  start n=node(*) where n.name='Andreas' return n
  // filter nodes where age is less than 30
  start n=node(*) where n.age<30 return n
  // filter using a regular expression
  start n=node(*) where n.name =~ ‘Tob.*’ return n
  // filter for a property exists
  start n=node(*) where has(n.name) return n



                                                        45
46
Cypher: CREATE
๏ CREATE <node>[,node or relationship] RETURN <expr>
  •create nodes with optional properties
  •create relationship (must have a type)




                                               46
Cypher: CREATE
๏ CREATE <node>[,node or relationship] RETURN <expr>
  •create nodes with optional properties
  •create relationship (must have a type)

 // create an anonymous node
 create n
 // create node with a property, returning it
 create n={name:'Andreas'} return n
 // lookup 2 nodes, then create a relationship and return it
 start n=node(0),m=node(1) create n-[r:KNOWS]-m return r
 // lookup nodes, then create a relationship with properties
 start n=node(1),m=node(2) create n-[r:KNOWS {since:2008}]->m



                                                       46
47
Cypher: SET
๏ SET [<node property>] [<relationship property>]
   •update a property on a node or relationship
   •must follow a START




                                                    47
Cypher: SET
๏ SET [<node property>] [<relationship property>]
   •update a property on a node or relationship
   •must follow a START

  // update the name property
  start n=node(0) set n.name='Peter'
  // update many nodes, using a calculation
  start n=node(*) set n.size=n.size+1
  // match & capture a relationship, update a property
  start n=node(1) match n-[r]-m set r.times=10




                                                         47
48
Cypher: DELETE
๏ DELETE [<node>|<relationship>|<property>]
  •delete a node, relationship or property
  •must follow a START
  •tofirst a node, all relationships must be deleted
      delete




                                                48
Cypher: DELETE
๏ DELETE [<node>|<relationship>|<property>]
  •delete a node, relationship or property
  •must follow a START
  •tofirst a node, all relationships must be deleted
      delete

 // delete a node
 start n=node(5) delete n
 // remove a node and all relationships
 start n=node(3) match n-[r]-() delete n, r
 // remove a property
 start n=node(3) delete n.age




                                                48

Weitere ähnliche Inhalte

Mehr von Peter Neubauer

2012 09 GDG San Francisco Hackday at Parisoma
2012 09 GDG San Francisco Hackday at Parisoma2012 09 GDG San Francisco Hackday at Parisoma
2012 09 GDG San Francisco Hackday at ParisomaPeter Neubauer
 
Test driven documentation
Test driven documentationTest driven documentation
Test driven documentationPeter Neubauer
 
Neo4j at @PolyglotVancouver
Neo4j at @PolyglotVancouverNeo4j at @PolyglotVancouver
Neo4j at @PolyglotVancouverPeter Neubauer
 
From Zero to Hero - Neo4j and Cypher.
From Zero to Hero - Neo4j and Cypher.From Zero to Hero - Neo4j and Cypher.
From Zero to Hero - Neo4j and Cypher.Peter Neubauer
 
Tips for building communitites with limited resources
Tips for building communitites with limited resourcesTips for building communitites with limited resources
Tips for building communitites with limited resourcesPeter Neubauer
 
Intro to Neo4j or why insurances should love graphs
Intro to Neo4j or why insurances should love graphsIntro to Neo4j or why insurances should love graphs
Intro to Neo4j or why insurances should love graphsPeter Neubauer
 
Neo4j Spatial - GIS for the rest of us.
Neo4j Spatial - GIS for the rest of us.Neo4j Spatial - GIS for the rest of us.
Neo4j Spatial - GIS for the rest of us.Peter Neubauer
 
Geekout Tallinn - Neo4j for the rescue!
Geekout Tallinn - Neo4j for the rescue!Geekout Tallinn - Neo4j for the rescue!
Geekout Tallinn - Neo4j for the rescue!Peter Neubauer
 
GDM 2011 - Neo4j and real world apps.
GDM 2011 - Neo4j and real world apps.GDM 2011 - Neo4j and real world apps.
GDM 2011 - Neo4j and real world apps.Peter Neubauer
 
2010 09-neo4j-deutsche-telekom
2010 09-neo4j-deutsche-telekom2010 09-neo4j-deutsche-telekom
2010 09-neo4j-deutsche-telekomPeter Neubauer
 
Neo4j spatial-nosql-frankfurt
Neo4j spatial-nosql-frankfurtNeo4j spatial-nosql-frankfurt
Neo4j spatial-nosql-frankfurtPeter Neubauer
 
Neo4j - 5 cool graph examples
Neo4j - 5 cool graph examplesNeo4j - 5 cool graph examples
Neo4j - 5 cool graph examplesPeter Neubauer
 

Mehr von Peter Neubauer (15)

Intro to Neo4j 2.0
Intro to Neo4j 2.0Intro to Neo4j 2.0
Intro to Neo4j 2.0
 
2012 09 GDG San Francisco Hackday at Parisoma
2012 09 GDG San Francisco Hackday at Parisoma2012 09 GDG San Francisco Hackday at Parisoma
2012 09 GDG San Francisco Hackday at Parisoma
 
Test driven documentation
Test driven documentationTest driven documentation
Test driven documentation
 
Neo4j at @PolyglotVancouver
Neo4j at @PolyglotVancouverNeo4j at @PolyglotVancouver
Neo4j at @PolyglotVancouver
 
From Zero to Hero - Neo4j and Cypher.
From Zero to Hero - Neo4j and Cypher.From Zero to Hero - Neo4j and Cypher.
From Zero to Hero - Neo4j and Cypher.
 
Tips for building communitites with limited resources
Tips for building communitites with limited resourcesTips for building communitites with limited resources
Tips for building communitites with limited resources
 
Intro to Neo4j or why insurances should love graphs
Intro to Neo4j or why insurances should love graphsIntro to Neo4j or why insurances should love graphs
Intro to Neo4j or why insurances should love graphs
 
2011 11-öredev
2011 11-öredev2011 11-öredev
2011 11-öredev
 
Neo4j Spatial - GIS for the rest of us.
Neo4j Spatial - GIS for the rest of us.Neo4j Spatial - GIS for the rest of us.
Neo4j Spatial - GIS for the rest of us.
 
Geekout Tallinn - Neo4j for the rescue!
Geekout Tallinn - Neo4j for the rescue!Geekout Tallinn - Neo4j for the rescue!
Geekout Tallinn - Neo4j for the rescue!
 
GDM 2011 - Neo4j and real world apps.
GDM 2011 - Neo4j and real world apps.GDM 2011 - Neo4j and real world apps.
GDM 2011 - Neo4j and real world apps.
 
2010 09-neo4j-deutsche-telekom
2010 09-neo4j-deutsche-telekom2010 09-neo4j-deutsche-telekom
2010 09-neo4j-deutsche-telekom
 
Neo4j spatial-nosql-frankfurt
Neo4j spatial-nosql-frankfurtNeo4j spatial-nosql-frankfurt
Neo4j spatial-nosql-frankfurt
 
Neo4j - 5 cool graph examples
Neo4j - 5 cool graph examplesNeo4j - 5 cool graph examples
Neo4j - 5 cool graph examples
 
Neo4j Nosqllive
Neo4j NosqlliveNeo4j Nosqllive
Neo4j Nosqllive
 

Kürzlich hochgeladen

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Kürzlich hochgeladen (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

2012 09 SF Data Mining zero to hero

  • 1. Neo4j - from 0 to Her0 Thank you Trulia! Peter Neubauer Andreas Kollegger Michael Hunger @peterneubauer @akollegger @mesirii #neo4j 1
  • 2. Neo4j - from 0 to Her0 Thank you Trulia! Peter Neubauer Andreas Kollegger Michael Hunger @peterneubauer @akollegger @mesirii #neo4j 1
  • 3. Neo4j Neo4j - from 0 to Her0 Thank you Trulia! Peter Neubauer Andreas Kollegger Michael Hunger @peterneubauer @akollegger @mesirii #neo4j 1
  • 4. 1
  • 5. 2
  • 6. Um, Neo for what? 2
  • 7. Um, Neo for what? •Neo4j - the graph database •Graph •no: not for charts & diagrams, or vector artwork •yes: for storing data that is connected •remember linker lists, trees? •graphs are the general-purpose data structure 2
  • 8. Neo4j is a Graph Database 3
  • 9. Neo4j is a Graph Database ๏ A Graph Database: 3
  • 10. Neo4j is a Graph Database ๏ A Graph Database: • a Property Graph with Nodes, Relationships and Properties on both 3
  • 11. Neo4j is a Graph Database ๏ A Graph Database: • a Property Graph with Nodes, Relationships and Properties on both • perfect for complex, highly connected data 3
  • 12. Neo4j is a Graph Database ๏ A Graph Database: • a Property Graph with Nodes, Relationships and Properties on both • perfect for complex, highly connected data ๏ A Graph Database: 3
  • 13. Neo4j is a Graph Database ๏ A Graph Database: • a Property Graph with Nodes, Relationships and Properties on both • perfect for complex, highly connected data ๏ A Graph Database: • reliable with real ACID Transactions 3
  • 14. Neo4j is a Graph Database ๏ A Graph Database: • a Property Graph with Nodes, Relationships and Properties on both • perfect for complex, highly connected data ๏ A Graph Database: • reliable with real ACID Transactions • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion Properties 3
  • 15. Neo4j is a Graph Database ๏ A Graph Database: • a Property Graph with Nodes, Relationships and Properties on both • perfect for complex, highly connected data ๏ A Graph Database: • reliable with real ACID Transactions • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion Properties • Server with REST API, or Embeddable on the JVM 3
  • 16. Neo4j is a Graph Database ๏ A Graph Database: • a Property Graph with Nodes, Relationships and Properties on both • perfect for complex, highly connected data ๏ A Graph Database: • reliable with real ACID Transactions • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion Properties • Server with REST API, or Embeddable on the JVM • high-performance with High-Availability (read scaling) 3
  • 18. 5
  • 22. You know relational foo bar 5
  • 23. You know relational foo foo_bar bar 5
  • 24. You know relational foo foo_bar bar 5
  • 25. You know relational foo foo_bar bar 5
  • 26. You know relational foo foo_bar bar 5
  • 27. You know relational now consider relationships... 5
  • 28. You know relational now consider relationships... 5
  • 29. You know relational now consider relationships... 5
  • 30. You know relational now consider relationships... 5
  • 31. You know relational now consider relationships... 5
  • 32. You know relational now consider relationships... 5
  • 33. 5
  • 34. 6
  • 35. We're talking about a Property Graph 6
  • 36. We're talking about a Property Graph Nodes 6
  • 37. We're talking about a Property Graph Nodes Relationships 6
  • 38. We're talking about a Property Graph Em Joh il a n knows knows Alli Tob Lar Nodes son ias knows s knows And And knows knows rea rés s knows knows knows Pet Miic Mc knows Ian er knows a a knows knows De Mic lia h ael Relationships Properties (each a key+value) + Indexes (for easy look-ups) 6
  • 39. 6
  • 40. 7
  • 41. And, but, so how do you query this "graph" database? 7
  • 43. What is Cypher? • Graph Query Language for Neo4j • Aims to make querying simple
  • 45. Design Decisions Pattern matching A B C
  • 51. Design Decisions ASCII-art patterns () --> ()
  • 52. Design Decisions Directed relationship A B
  • 53. Design Decisions Directed relationship A B (A) --> (B)
  • 54. Design Decisions Undirected relationship A B
  • 55. Design Decisions Undirected relationship A B (A) -- (B)
  • 56. Design Decisions specific relationships LOVES A B
  • 57. Design Decisions specific relationships LOVES A B A -[:LOVES]-> B
  • 58. Design Decisions Joined paths A B C
  • 59. Design Decisions Joined paths A B C A --> B --> C
  • 61. Design Decisions multiple paths A B C A --> B --> C, A --> C
  • 62. Design Decisions multiple paths A B C A --> B --> C, A --> C A --> B --> C <-- A
  • 63. Design Decisions Optional relationships A B
  • 64. Design Decisions Optional relationships A B A -[?]-> B
  • 65. SELECT skills.*, user_skill.* FROM users JOIN user_skill ON users.id = user_skill.user_id JOIN skills ON user_skill.skill_id = skill.id WHERE users.id = 1
  • 66. START user = node(1) MATCH user -[user_skill]-> skill RETURN skill, user_skill
  • 67. Indexes Used as multiple starting points, not to speed up any traversals START a = node:nodes_index(type='User') MATCH a-[r:knows]-b RETURN ID(a), ID(b), r.weight
  • 68. Variable length Path Match Some UGLY recursive self join on the groups table START max=node:person(name=“Max") MATCH group <-[:BELONGS_TO*]- max RETURN group
  • 69. 27
  • 70. Who uses this stuff? 27
  • 71.
  • 74. Cute meta + data This Material is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/
  • 75. Cute meta + data This Material is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/
  • 76. Neo4J Co-Existence • Node uuids as refs in external ElasticSearch also in internal Lucene • Custom search ranking for user history based on node relationship data • MySQL for user data, Redis for metrics This Material is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/
  • 77.
  • 78. [B] ACL from Hell One of the top 10 telcos worldwide
  • 79. Example Access Authorization User Access may be given directly or by inheritance Customer Account U Subscription U Inherit = true Inherit = false In C he rit = C C C tru e A A A A A S S S S S S S S S S
  • 80.
  • 81. [C] Master of your Domain
  • 82. [C] MDM within Cisco master data management, sales compensation management, online customer support Description Benefits Real-time conflict detection in sales compensation management. Performance : “Minutes to Milliseconds” Business-critical “P1” system. Neo4j allows Cisco to model complex Outperforms Oracle RAC, serving complex queries in real time algorithms, which still maintaining high performance over a large Flexibility dataset. Allows for Cisco to model interconnected data and complex queries with ease Background Robustness Neo4j replaces Oracle RAC, which was not performant enough for the With 9+ years of production experience, Neo4j brings a solid product. use case. Architecture 3-node Enterprise cluster with mirrored disaster recovery cluster Dedicated hardware in own datacenter Embedded in custom webapp Sizing 35 million nodes 50 million relationships 600 million properties
  • 83. 35
  • 84. Webadmin 35
  • 85. 36
  • 87. 37
  • 88. Today’s app: Cineasts 37
  • 89. 38
  • 91. 39
  • 93. Hands-on: Installation •copy zip drive contents to your box •cd cineasts •./import.sh •neo4j/bin/neo4j-shell •http://localhost:7474 39
  • 94. Some Links ๏ GraphConnect ๏ Community: http://neo4j.org 40
  • 95. 41
  • 96. Cypher - overview ๏ a pattern-matching query language ๏ declarative grammar with clauses (like SQL) ๏ aggregation, ordering, limits ๏ create, read, update, delete 41
  • 97. 42
  • 98. Cypher - read clauses ๏ Find a place to begin: •START <lookup> ๏ Describe what to find: •MATCH <paths> ๏ Filter the elements: •WHERE <filters> ๏ RETURN <values> 42
  • 99. 43
  • 100. Cypher: START + RETURN ๏ START <lookup> RETURN <expressions> ๏ START binds terms using simple look-up •directly using known ids •or based on indexed Property ๏ RETURN expressions specify result set 43
  • 101. Cypher: START + RETURN ๏ START <lookup> RETURN <expressions> ๏ START binds terms using simple look-up •directly using known ids •or based on indexed Property ๏ RETURN expressions specify result set // lookup node id 1, return that node start n=node(1) return n // lookup all nodes start n=node(*) return n 43
  • 102. 44
  • 103. Cypher: MATCH ๏ START <lookup> MATCH <pattern> RETURN <expr> ๏ MATCH describes a pattern of nodes+relationships •node terms in optional parenthesis •lines with arrows for relationships 44
  • 104. Cypher: MATCH ๏ START <lookup> MATCH <pattern> RETURN <expr> ๏ MATCH describes a pattern of nodes+relationships •node terms in optional parenthesis •lines with arrows for relationships // lookup 'n', traverse any relationship to some 'm' start n=node(0) match (n)--(m) return n,m; // any outgoing relationship from 'n' to 'm' start n=node(1) match n-->m return n,m; // only 'next' relationships from 'n' to 'm' up to 3 away start n=node(1) match p=n-[:next*..3]->m return p; // from 'n' to 'm' and capture the relationship as 'r' start n=node(1) match n-[r]->m return n,r,m 44
  • 105. 45
  • 106. Cypher: WHERE ๏ START <lookup> [MATCH <pattern>] WHERE <condition> RETURN <expr> ๏ WHERE filters nodes or relationships •uses expressions to constrain elements 45
  • 107. Cypher: WHERE ๏ START <lookup> [MATCH <pattern>] WHERE <condition> RETURN <expr> ๏ WHERE filters nodes or relationships •uses expressions to constrain elements // lookup all nodes as 'n', constrained to name 'Andreas' start n=node(*) where n.name='Andreas' return n // filter nodes where age is less than 30 start n=node(*) where n.age<30 return n // filter using a regular expression start n=node(*) where n.name =~ ‘Tob.*’ return n // filter for a property exists start n=node(*) where has(n.name) return n 45
  • 108. 46
  • 109. Cypher: CREATE ๏ CREATE <node>[,node or relationship] RETURN <expr> •create nodes with optional properties •create relationship (must have a type) 46
  • 110. Cypher: CREATE ๏ CREATE <node>[,node or relationship] RETURN <expr> •create nodes with optional properties •create relationship (must have a type) // create an anonymous node create n // create node with a property, returning it create n={name:'Andreas'} return n // lookup 2 nodes, then create a relationship and return it start n=node(0),m=node(1) create n-[r:KNOWS]-m return r // lookup nodes, then create a relationship with properties start n=node(1),m=node(2) create n-[r:KNOWS {since:2008}]->m 46
  • 111. 47
  • 112. Cypher: SET ๏ SET [<node property>] [<relationship property>] •update a property on a node or relationship •must follow a START 47
  • 113. Cypher: SET ๏ SET [<node property>] [<relationship property>] •update a property on a node or relationship •must follow a START // update the name property start n=node(0) set n.name='Peter' // update many nodes, using a calculation start n=node(*) set n.size=n.size+1 // match & capture a relationship, update a property start n=node(1) match n-[r]-m set r.times=10 47
  • 114. 48
  • 115. Cypher: DELETE ๏ DELETE [<node>|<relationship>|<property>] •delete a node, relationship or property •must follow a START •tofirst a node, all relationships must be deleted delete 48
  • 116. Cypher: DELETE ๏ DELETE [<node>|<relationship>|<property>] •delete a node, relationship or property •must follow a START •tofirst a node, all relationships must be deleted delete // delete a node start n=node(5) delete n // remove a node and all relationships start n=node(3) match n-[r]-() delete n, r // remove a property start n=node(3) delete n.age 48

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. Visualization done with GraphViz\nA user will have many such &amp;#x201C;stacks&amp;#x201D;\n
  107. Search ranking weighs inbound and outbound node connections as part of search score calculation\n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. \n
  158. \n
  159. \n
  160. \n
  161. \n
  162. \n
  163. \n
  164. \n
  165. \n
  166. \n
  167. \n
  168. \n
  169. \n
  170. \n