https://memgraph.com/blog/build-graph-analytics-without-worrying-about-memory * * * * [615e] Platform Core Memgraph Arrow icon In-memory graph database for streaming data. The Memgraph Ecosystem Lab Arrow icon A user interface for graph data visualization. MAGE Arrow icon A growing open-source graph algorithm repository. GQLAlchemy Arrow icon An object graph mapper (OGM) for Python. Download Platform How it works Arrow icon Check under the hood and get a glimpse at the inner workings of Memgraph. Cloud Use cases Fraud detection Arrow icon Analyse the behavior of multiple users over time to detect anomalies and fraud. Recommendation Engine Arrow icon Combine multiple data sources to recommend products and services to the right people at the right time. Resource and Process Optimisation Arrow icon Analyse data from various data sources in real-time to improve productivity and reduce costs. Unique Case Arrow icon Not sure Memgraph is the right fit for your use case? Set up a call and explore let's explore the possibilities together. Resources Playground Arrow icon Master graph algorithms in minutes through guided lessons and sandboxes on real-world problems in the browser. Community Arrow icon Join a growing community of graph developers and data scientists building graph based apps. Blog Arrow icon As blogs do. Dive into Memgraph topics. Code with Buda Arrow icon Watch Memgraph's CTO demonstrate the power of graphs. Email courses Arrow icon Upgrade your Cypher or Graph Modelling skills in weekly bite-sized lessons. DocsPricing Discord logoGitHub logo Free Download Discord logoGitHub logo [61fa30e301] Check out the new Python Object Graph Mapper (OGM) libraryGQLAlchemy Right arrow icon[61fa30e301]Close icon Categories Product Memgraph MAGE Build C++ Graph Analytics Without Worrying About Memory Build C++ Graph Analytics Without Worrying About Memory Analyze Infrastructure Networks with Dynamic Betweenness Centrality MAGE 1.2 - Meet Temporal Graph Networks and Dynamic Graph Analytics Link prediction with Node2Vec in Physics Collaboration Network How to Identify Essential Proteins using Betweenness Centrality Recommendation System Using Online Node2Vec with Memgraph MAGE Diving into the Vehicle Routing Problem Announcements Product Use Cases Product Tutorials Graph Streaming Python Company Product / Memgraph MAGE Build C++ Graph Analytics Without Worrying About Memory by Ante Pusic October 3, 2022 Build C++ Graph Analytics Without Worrying About Memory Extracting value from graph data seems like so much more hassle than it needs to be. Datasets are often useful only when big enough, and at that point you need to scale up your analytics pipeline. More often than not, graph analytics products need changes to make them compatible with what you've got. Sometimes, even these changes don't do the trick, and you need to develop new graph algorithms or ML. All this is possible with minimal overhead using Memgraph and its MAGE graph analytics library, even if you haven't used graph databases before. Grab a coffee, and keep reading to find out how the new MAGE C++ API gives you the speed of C++ and the smoothness of higher-level languages for handling graph data. Extend queries with custom graph methods With MAGE, you can build user-defined methods as query procedures and functions, and run them with Cypher queries. Procedures are full-featured operations that can modify the graph and pass the changes for further processing. They return a stream of results which can be complex multi-field values. For simpler use cases, use functions: they take the graph as immutable and return a single value. Graph users often avoid storing data within graph DBs due to performance constraints: accessing the stored graph can cause bottlenecks, especially in dynamic analytics. We have worked around this issue in two ways: * Memgraph is an in-memory database, eliminating the need for expensive read/write operations. * The new C++ API directly interfaces with the stored graph and does not create its own graph representation. In short, if the data is in the DB, it's ready to use. However, high-performance code is worth nothing if you don't know how to write it. Thus, our team has made coding graph methods easier. The following code snippet implements a procedure that adds a user-defined number of nodes to the graph: // Universal procedure signature | void AddXNodes(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory) { mgp::memory = memory; // Grant memory access (for single-thread code) const auto arguments = mgp::List(args); // Get the arguments const auto n_new_nodes = arguments[0].ValueInt(); auto graph = mgp::Graph(memgraph_graph); // Get the graph for (int i = 0; i < n_new_nodes; i++) { graph.CreateNode(); } } // Initialization function | extern "C" int mgp_init_module(struct mgp_module *module, struct mgp_memory *memory) { try { mgp::memory = memory; // Grant memory access (for single-thread code) mgp::AddProcedure(AddXNodes, "add_x_nodes", mgp::ProcedureType::Write, {mgp::Parameter("number", mgp::Type::Int)}, {}, module, memory); // Add a procedure with the `void add_x_nodes(int number)` signature // that writes data to the graph } catch (const std::exception &e) { return 1; } return 0; } To familiarize yourself with the new API, learn from example with the reference guide and consult the documentation. Intuitive interface The new C++ API is designed for humans, not robots. We followed best practices toreduce unnecessary cognitive load: the components have simple and consistent interfaces, common use cases require fewer user actions, and the API comes with developer guides and extensive documentation. Memory management is probably the main pain point in C++ development, its usefulness notwithstanding. The new C++ API automatically manages the memory used by graph data, saving you time that would otherwise go to debugging and writing repetitive code. Under the hood, this API builds upon the existing C API. The ability to use C++ features ties in directly with our goal of creating a simple, consistent interface. During design, we had our minds set on avoiding the cognitive friction that comes with context-switching between C++ standard library classes and ours. Compare the code snippets below. They both do the same thing - iterate over graph nodes - but the latter is consistent with standard C++ iterables and manages memory on its own. // C API auto *vertices_it = mgp::graph_iter_vertices(memgraph_graph, memory); for (auto *vertex = mgp::vertices_iterator_get(vertices_it); vertex; vertex = mgp::vertices_iterator_next(vertices_it)) { // (...) } mgp::vertices_iterator_destroy(vertices_it); // C++ API for (const auto node : graph.Nodes()) { // (...) } Going further In its initial release, the new C++ API has made it easier to develop query modules with user-defined procedures and functions. To this end, we have cut down boilerplate code and made data accessible through a simple, consistent and high-performance graph API. Besides query modules, Memgraph supports transformation modules, which enable the database to ingest data from streams. For the next release, we plan to add support for transformation modules, as well as restricting graph operations to subgraphs or extending them to work with multiple graph iterations simultaneously. We will maintain the focus on simplicity and consistency when adding new features and incrementally improve what we've already got. What's next? Thanks for keeping with us! We've worked hard to make graph analytics fast, scalable, and easy to develop and use, come try MAGE out. You can build graph analytics tailored to your needs in C++ or Python, or even contribute to MAGE and see your work now available to everybody. Tell us what you're doing on our Discord server, we'll be happy to talk about it with you! Share Blog Sign up for our Newsletter Get the latest articles on all things graph databases, algorithms, and Memgraph updates delivered straight to your inbox Table of Contents Share Blog Sign up for our Newsletter Get the latest articles on all things graph databases, algorithms, and Memgraph updates delivered straight to your inbox Continue Reading Tutorials / Python Optimizing Telco Networks With Graph Coloring & Memgraph MAGE In this tutorial, you will learn about the code assignment problem in telecommunication networks and how to solve it in a simple yet effective way using graph algorithms and Memgraph. by Suzana Pratljacic May 3, 2021 Tutorials / Python How to Implement Custom JSON Utility Procedures With Memgraph MAGE and Python. Learn how to extend the Cypher query language by implementing a few simple custom procedures to load and export data in a JSON format using Memgraph MAGE and Python. by Ivan Despot March 9, 2021 Python / GQLAlchemy Link prediction with Node2Vec in Physics Collaboration Network A guide to understanding how link prediction works with node2vec algorithm by Antonio Filipovic December 13, 2021 Subscribe to our newsletter Stay up to date with product updates, tips, tricks and industry related news. [ ] [Sign up] Thank you! Your submission has been received! Oops! Something went wrong while submitting the form. [62cf5584ff] Platform Memgraph DBCloudLabMAGEGQLAlchemy How it worksUse CasesPricing Resources DocsPlaygroundCommunityBlogCode with BudaEmail Courses Company About UsCareersLegalPress RoomNewsletterContact Join us on Discord Our growing community of graph enthusiast awaits you! Join our community [62cf5a7422][62cf5a7434][62cf5a7488][62cf5a7422]Linkedin icon (c) 2022 Memgraph Ltd. All rights reserved. Terms & Privacy