GithubHelp home page GithubHelp logo

qingz11 / nebulagraph-ai Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wey-gu/nebulagraph-ai

0.0 0.0 0.0 2.58 MB

NebulaGraph AI High-Level API, do Graph Algo, Analytics in 4 lines of code.

Home Page: https://siwei.io/en/nebulagraph-ai-suite/

License: Apache License 2.0

C++ 22.82% Python 72.58% Makefile 0.79% Jupyter Notebook 3.81%

nebulagraph-ai's Introduction

NebulaGraph AI Suite(ng_ai)

NebulaGraph AI Suite with 4 line code to run Graph Algo on NebulaGraph

License PyPI version pdm-managed Tests Python 3.9


Documentation: https://github.com/wey-gu/nebulagraph-ai#documentation

Source Code: https://github.com/wey-gu/nebulagraph-ai


NebulaGraph AI Suite for Python (ng_ai) is a powerful Python library that offers APIs for data scientists to effectively read, write, analyze, and compute data in NebulaGraph.

With the support of a single-machine engine(NetworkX), or distributed computing environment using Spark, we could perform Graph Analysis and Algorithms on top of NebulaGraph in less than 10 lines of code, in unified and intuitive API.

Quick Start in 5 Minutes

Option 1: Try on your Desktop. Go with NebulaGraph Docker Extension!

Option 2: On Linux Server? Go with Nebula-Up πŸ‘‡πŸ»

Installation

pip install ng_ai

Usage

Call from nGQL

See more details in the docs

RETURN ng_ai("pagerank", ["follow"], ["degree"], "spark",
    {space: "basketballplayer", max_iter: 10}, {write_mode: "insert"})

Spark Engine Examples

See also: examples/spark_engine.ipynb

Run Algorithm on top of NebulaGraph:

Note, there is also a query mode, refer to examples or docs for more details.

from ng_ai import NebulaReader

# read data with spark engine, scan mode
reader = NebulaReader(engine="spark")
reader.scan(edge="follow", props="degree")
df = reader.read()

# run pagerank algorithm
pr_result = df.algo.pagerank(reset_prob=0.15, max_iter=10)

Write back to NebulaGraph:

from ng_ai import NebulaWriter
from ng_ai.config import NebulaGraphConfig

config = NebulaGraphConfig()

properties = {"louvain": "cluster_id"}

writer = NebulaWriter(
    data=df_result, sink="nebulagraph_vertex", config=config, engine="spark")
writer.set_options(
    tag="louvain", vid_field="_id", properties=properties,
    batch_size=256, write_mode="insert",)
writer.write()

Then we could query the result in NebulaGraph:

MATCH (v:louvain)
RETURN id(v), v.louvain.cluster_id LIMIT 10;

NebulaGraph Engine Examples

Basically the same as Spark Engine, but with engine="nebula", refer to examples or docs for more details.

- reader = NebulaReader(engine="spark")
+ reader = NebulaReader(engine="nebula")

Documentation

Environment Setup

API Reference

How it works

ng_ai is a unified abstraction layer for different engines, the current implementation is based on Spark, NetworkX, DGL, and NebulaGraph, but it's easy to extend to other engines like Flink, GraphScope, PyG, etc.

          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚   Spark Cluster                                   β”‚
          β”‚    .─────.    .─────.    .─────.    .─────.       β”‚
          β”‚   ;       :  ;       :  ;       :  ;       :      β”‚
       β”Œβ”€β–Άβ”‚   :       ;  :       ;  :       ;  :       ;      β”‚
       β”‚  β”‚    β•²     β•±    β•²     β•±    β•²     β•±    β•²     β•±       β”‚
       β”‚  β”‚     `───'      `───'      `───'      `───'        β”‚
  Algo Spark                                                  β”‚
    Engineβ””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       └───                                                    β”‚          β”‚
          β”‚   NebulaGraph AI Suite(ngai)                       β”‚ ngai-api │◀─┐
          β”‚                                                    β”‚          β”‚  β”‚
          β”‚                                                    └───────────  β”‚
          β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”            β”‚  β”‚
          β”‚     β”‚ Reader β”‚    β”‚ Algo β”‚    β”‚ Writer β”‚   β”‚ GNN β”‚            β”‚  β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”€β–Άβ”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”˜            β”‚  β”‚
 β”‚        β”‚          β”‚            β”‚            β”‚          β”‚               β”‚  β”‚
 β”‚        β”‚          β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”    └──────┐        β”‚  β”‚
 β”‚        β”‚          β–Ό                β–Ό              β–Ό           β–Ό        β”‚  β”‚
 β”‚        β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚  β”‚
 β”‚     β”Œβ”€β”€β”€   β”‚ SparkEngine β”‚ β”‚ NebulaEngine β”‚ β”‚ NetworkX β”‚β”‚ DGLEngineβ”‚   β”‚  β”‚
 β”‚     β”‚  β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚  β”‚
 β”‚     β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
 β”‚     β”‚             β”‚        Spark                                          β”‚
 β”‚     β”‚             └────────Reader ────────────┐                           β”‚
 β”‚  Spark                   Query Mode           β”‚                           β”‚
 β”‚  Reader                                       β”‚                           β”‚
 β”‚Scan Mode                                      β–Ό                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚     β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ ngai-udf│◀─────────────┐
 β”‚     β”‚  β”‚                                                   β”‚         └──────────              β”‚
 β”‚     β”‚  β”‚  NebulaGraph Graph Engine         Nebula-GraphD   β”‚   ngai-GraphD     β”‚              β”‚
 β”‚     β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚
 β”‚     β”‚  β”‚                              β”‚                    β”‚                                  β”‚
 β”‚     β”‚  β”‚  NebulaGraph Storage Engine  β”‚                    β”‚                                  β”‚
 β”‚     β”‚  β”‚                              β”‚                    β”‚                                  β”‚
 β”‚     └─▢│  Nebula-StorageD             β”‚    Nebula-Metad    β”‚                                  β”‚
 β”‚        β”‚                              β”‚                    β”‚                                  β”‚
 β”‚        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                  β”‚
 β”‚                                                                                               β”‚
 β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
 β”‚    β”‚ RETURN ng_ai("pagerank", ["follow"], ["degree"], "spark", {space:"basketballplayer"}) β”‚β”€β”€β”˜
 β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚  β”‚ from ng_ai import NebulaReader                              β”‚
 β”‚  β”‚                                                             β”‚
 β”‚  β”‚ # read data with spark engine, scan mode                    β”‚
 β”‚  β”‚ reader = NebulaReader(engine="spark")                       β”‚
 β”‚  β”‚ reader.scan(edge="follow", props="degree")                  β”‚
 └──│ df = reader.read()                                          β”‚
    β”‚                                                             β”‚
    β”‚ # run pagerank algorithm                                    β”‚
    β”‚ pr_result = df.algo.pagerank(reset_prob=0.15, max_iter=10)  β”‚
    β”‚                                                             β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  

Spark Engine Prerequisites

NebulaGraph Engine Prerequisites

Contributing

See HACKING.md for details.

License

This project is licensed under the terms of the Apache License 2.0.

nebulagraph-ai's People

Contributors

wey-gu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.