Create your first graph
Brahmand implements a structured property graph model and requires a pre-defined schema.
ClickHouse provides built-in JSON data type today, and upcoming enhancements will enable full semi-structured schemas—letting you store, index, and query JSON documents directly in your graph.
- Schema definition involves declaring node and relationship tables and their associated properties.
- Each property key is strongly typed (types must be explicitly declared)
- For node tables, a
primary key
and anode id
must be defined - For relationship tables,
primary key
is optional
Example database
Section titled “Example database”The dataset used in the tutorials is a social network dataset of users and posts that has the following schema.
This dataset originates from KuzuDB, and brahmand draws significant inspiration from Kuzu.
The User node represents users within the social network. Each user has their information attached, such as:
- user_id (UInt64): This is an id which is used to sort and find users.
- username (String): This is the username which each user will have.
- account_creation_date (DateTime): This represents the date which the account was created.
userId,username,account_creation_date1,Frodo,2025-09-092,Sam,2025-01-273,Aragon,2025-02-254,Gandolf,2025-05-115,Sauron,2025-06-116,Saruman,2025-03-11
The Post node represents the posts which has been made on the social network. Each post has its information attached, such as:
- post_id (UInt64): This is an unique id which is used to sort and find posts.
- creation_date (DateTime): This represents the date which the account was created.
- like_count (UInt64): This represents the amount of likes the post has received.
- retweet_count (UInt64): This represents the amount of retweets the post has received.
postId,creation_date,like_count,retweet_count1,2021-12-08,427,292,2022-06-02,9,163,2023-01-14,238,514,2023-01-06,67,1475,2022-10-26,103,73
Relationships
Section titled “Relationships”FOLLOWS
Section titled “FOLLOWS”The relationship FOLLOWS
goes from User
node to User
node. This relation represents a user following another user on the social network.
from_User,to_User1,31,42,12,32,46,5
The relationship POSTS
goes from User
node to Post
node. This relation represents a user posting the post on the social network.
from_User,to_Post1,14,25,33,42,5
The relationship Likes
goes from User
node to Post
node. This relation represents a user liking the post on the social network.
from_User,to_Post1,12,13,13,24,2
Define the schema in Brahmand
Section titled “Define the schema in Brahmand”We will use brahmand-client CLI in this tutorial.
In the brahmand-client CLI, let’s create a node table for the User
s in our dataset.
For
NODE ID
brahmand only supportsUInt64
andInt64
.
CREATE NODE TABLE User( userId UInt64, username String, account_creation_date DateTime, NODE ID(userId), PRIMARY KEY(username,userId));
DDL applied successfully
We can do a similar thing for the Post
s in our dataset.
CREATE NODE TABLE Post( postId UInt64, creation_date DateTime, like_count UInt64, retweet_count UInt64, NODE ID(postId), PRIMARY KEY(postId));
DDL applied successfully
Now that we have our node tables, we can create a relationship table for the FOLLOWS
, POSTS
and LIKES
relationships in our dataset.
CREATE REL TABLE FOLLOWS(From User To User);
DDL applied successfully
CREATE REL TABLE POSTS(From User To Post);
DDL applied successfully
CREATE REL TABLE LIKES(From User To Post);
DDL applied successfully
Check ClickHouse Tables
Section titled “Check ClickHouse Tables”Considering you are running brahmand with the docker compose configuration, to launch ClickHouse client, use this following command -
docker compose exec clickhouse-service clickhouse-client \ --host clickhouse-service \ --port 9000 \ --user test_user \ --password test_pass \ --database brahmand
To check tables and materialized views created by Brahmand, run:
SHOW TABLES;
┌─name────────────────┐ 1. │ FOLLOWS │ 2. │ FOLLOWS_incoming │ 3. │ FOLLOWS_outgoing │ 4. │ LIKES │ 5. │ LIKES_incoming │ 6. │ LIKES_outgoing │ 7. │ POSTS │ 8. │ POSTS_incoming │ 9. │ POSTS_outgoing │10. │ Post │11. │ User │12. │ graph_meta │13. │ mv_FOLLOWS_incoming │14. │ mv_FOLLOWS_outgoing │15. │ mv_LIKES_incoming │16. │ mv_LIKES_outgoing │17. │ mv_POSTS_incoming │18. │ mv_POSTS_outgoing │ └─────────────────────┘