-
Notifications
You must be signed in to change notification settings - Fork 5
Create getting_started.md #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
33de40b
bf2d025
70d4ff5
f078cd1
19c75c2
bc1c267
57a1c4a
c249c99
74d6ae1
037c521
a16ce37
2effef5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
--- | ||
title: "Getting Started" | ||
nav_order: 2 | ||
description: > | ||
Getting Started with FalkorDB Graph Database. | ||
--- | ||
|
||
|
||
# Getting Started with FalkorDB | ||
|
||
This guide will walk you through setting up FalkorDB, modeling a social network as a graph, | ||
and accessing it using the [FalkorDB Python client](/clients) with [Cypher](/cypher). | ||
|
||
--- | ||
|
||
## Prerequisites | ||
|
||
1. **FalkorDB Instance**: Set up FalkorDB (on-prem or cloud). | ||
- [Run FalkorDB Docker](https://hub.docker.com/r/falkordb/falkordb/) | ||
- [Create a FalkorDB Cloud Instance](https://app.falkordb.cloud/signup) | ||
2. **Python Installed**: Ensure you have Python 3.8+ installed. | ||
3. **Install FalkorDB Python Client**: | ||
|
||
```bash | ||
pip install falkordb | ||
``` | ||
|
||
--- | ||
|
||
## Step 1: Model a Social Network as a Graph | ||
|
||
Let's create a simple graph for a social network where: | ||
- **Nodes** represent `User` and `Post`. | ||
- **Relationships** connect `User`s with a `FRIENDS_WITH` relationship, and `User`s are connected via a `CREATED` relationship to `Post`s | ||
|
||
### Graph Schema | ||
|
||
| Node Type | Properties | | ||
|-----------|--------------------------| | ||
| User | `id`, `name`, `email` | | ||
| Post | `id`, `content`, `date` | | ||
|
||
| Relationship Type | Start Node | End Node | Properties | | ||
|-------------------|------------|----------|--------------| | ||
| FRIENDS_WITH | User | User | `since` | | ||
| CREATED | User | Post | `time` | | ||
|
||
 | ||
|
||
--- | ||
|
||
## Step 2: Load Data into FalkorDB | ||
|
||
Here’s how you can model and load the data. | ||
|
||
### Cypher Query to Create the Data | ||
swilly22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```cypher | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the queries are repeated in this section and the following, which is a bit of a waste. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it looks like a repeated section but it's not, the first is giving a pure Cypher example for the data modeling while the second it taking it one step farther and show how to run it in python |
||
CREATE (alice:User {id: 1, name: "Alice", email: "[email protected]"}) | ||
CREATE (bob:User {id: 2, name: "Bob", email: "[email protected]"}) | ||
CREATE (charlie:User {id: 3, name: "Charlie", email: "[email protected]"}) | ||
|
||
CREATE (post1:Post {id: 101, content: "Hello World!", date: 1701388800}) | ||
CREATE (post2:Post {id: 102, content: "Graph Databases are awesome!", date: 1701475200}) | ||
|
||
CREATE (alice)-[:FRIENDS_WITH {since: 1640995200}]->(bob) | ||
CREATE (bob)-[:FRIENDS_WITH {since: 1684108800}]->(charlie) | ||
CREATE (alice)-[:CREATED {time: 1701388800}]->(post1) | ||
CREATE (bob)-[:CREATED {time: 1701475200}]->(post2) | ||
Comment on lines
+63
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. date and time as they are right now can be confusing, either use Python to create timestamps from actual dates or consider changing the attribute to something else which doesn't require time / date datatype There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how would you do it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look up Python date / time to unix timestamp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked it up, it will bloat the example too much |
||
``` | ||
|
||
You can execute these commands using the FalkorDB Python client. | ||
|
||
--- | ||
|
||
## Step 3: Access Your Data | ||
|
||
### Connect to FalkorDB | ||
|
||
```python | ||
from falkordb import FalkorDB | ||
|
||
# Connect to FalkorDB | ||
client = FalkorDB(host="localhost", port=6379, password="your-password") | ||
gkorland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
graph = client.select_graph('social') | ||
``` | ||
|
||
### Execute Cypher Queries | ||
|
||
#### Create the Graph | ||
|
||
```python | ||
create_query = """ | ||
CREATE (alice:User {id: 1, name: "Alice", email: "[email protected]"}) | ||
CREATE (bob:User {id: 2, name: "Bob", email: "[email protected]"}) | ||
CREATE (charlie:User {id: 3, name: "Charlie", email: "[email protected]"}) | ||
|
||
CREATE (post1:Post {id: 101, content: "Hello World!", date: 1701388800}) | ||
CREATE (post2:Post {id: 102, content: "Graph Databases are awesome!", date: 1701475200}) | ||
|
||
CREATE (alice)-[:FRIENDS_WITH {since: 1640995200}]->(bob) | ||
CREATE (bob)-[:FRIENDS_WITH {since: 1684108800}]->(charlie) | ||
CREATE (alice)-[:CREATED {time: 1701388800}]->(post1) | ||
CREATE (bob)-[:CREATED {time: 1701475200}]->(post2) | ||
""" | ||
|
||
graph.query(create_query) | ||
print("Graph created successfully!") | ||
``` | ||
|
||
 | ||
|
||
#### Query the Graph | ||
|
||
```python | ||
# Find all friends of Alice | ||
query = """ | ||
|
||
date and time as they are right now can be confusing, either use Python to create timestamps from actual dates or consider changing the attribute to something else which doesn't require time / date datatype | ||
|
||
MATCH (alice:User {name: "Alice"})-[:FRIENDS_WITH]->(friend) | ||
RETURN friend.name AS Friend | ||
""" | ||
result = graph.ro_query(query) | ||
|
||
print("Alice's friends:") | ||
for record in result: | ||
print(record["Friend"]) | ||
``` | ||
|
||
#### Query Relationships | ||
|
||
```python | ||
# Find posts created by Bob | ||
query = """ | ||
MATCH (bob:User {name: "Bob"})-[:CREATED]->(post:Post) | ||
RETURN post.content AS PostContent | ||
""" | ||
result = graph.ro_query(query) | ||
|
||
print("Posts created by Bob:") | ||
for record in result: | ||
print(record["PostContent"]) | ||
``` | ||
|
||
--- | ||
|
||
## Step 4: Explore Further | ||
|
||
Congratulations! 🎉 You have successfully modeled, loaded, and queried a social network graph with FalkorDB. | ||
|
||
Next, dive deeper into FalkorDB's powerful features: | ||
- [Advanced Cypher](/cypher) | ||
- [Database Operations](/operations) | ||
- [Integration with ML Workflows](/llm_support) | ||
|
||
For questions or support, visit our [community forums](https://www.falkordb.com/contact-us/) |
Uh oh!
There was an error while loading. Please reload this page.