22 个版本 (8 个重大变更)
新 0.11.0 | 2024 年 8 月 23 日 |
---|---|
0.10.0 | 2024 年 7 月 15 日 |
0.9.3 | 2024 年 6 月 20 日 |
0.7.0 | 2023 年 12 月 21 日 |
0.4.3 | 2023 年 7 月 6 日 |
328 在 HTTP 服务器
2.5MB
58K SLoC
🌍 网站 📒 文档 Pometry 🧙教程 🐛 报告错误
加入 Slack
Raphtory 是一个用 Rust 编写的内存向量图数据库,顶部有友好的 Python API。它速度极快,可以在您的笔记本电脑上扩展到数亿条边,并且可以简单地通过 pip install raphtory
将其添加到现有的管道中。
它支持时间旅行、全文搜索、多层建模以及超越简单查询的高级分析,如自动风险检测、动态评分和时间模式。
如果您想贡献,请查看开放的 问题列表、赏金板 或直接在 Slack 上联系我们。成功的贡献将获得 Swag 奖励!
安装 Raphtory
Raphtory 可用于 Python 和 Rust。
对于 Python,您必须使用 3.8 或更高版本,并通过 pip 进行安装
pip install raphtory
对于Rust,Raphtory托管在crates上,支持Rust版本1.77及以上,可以通过以下命令将其添加到您的项目中:cargo add
cargo add raphtory
运行基本示例
以下是一个使用Python API的Raphtory示例,展示了它的外观和感觉。如果您喜欢看到的内容,可以在此处深入了解。
from raphtory import Graph
from raphtory import algorithms as algo
import pandas as pd
# Create a new graph
graph = Graph()
# Add some data to your graph
graph.add_node(timestamp=1, id="Alice")
graph.add_node(timestamp=1, id="Bob")
graph.add_node(timestamp=1, id="Charlie")
graph.add_edge(timestamp=2, src="Bob", dst="Charlie", properties={"weight": 5.0})
graph.add_edge(timestamp=3, src="Alice", dst="Bob", properties={"weight": 10.0})
graph.add_edge(timestamp=3, src="Bob", dst="Charlie", properties={"weight": -15.0})
# Check the number of unique nodes/edges in the graph and earliest/latest time seen.
print(graph)
results = [["earliest_time", "name", "out_degree", "in_degree"]]
# Collect some simple node metrics Ran across the history of your graph with a rolling window
for graph_view in graph.rolling(window=1):
for v in graph_view.nodes:
results.append(
[graph_view.earliest_time, v.name, v.out_degree(), v.in_degree()]
)
# Print the results
print(pd.DataFrame(results[1:], columns=results[0]))
# Grab an edge, explore the history of its 'weight'
cb_edge = graph.edge("Bob", "Charlie")
weight_history = cb_edge.properties.temporal.get("weight").items()
print(
"The edge between Bob and Charlie has the following weight history:", weight_history
)
# Compare this weight between time 2 and time 3
weight_change = cb_edge.at(2)["weight"] - cb_edge.at(3)["weight"]
print(
"The weight of the edge between Bob and Charlie has changed by",
weight_change,
"pts",
)
# Run pagerank and ask for the top ranked node
top_node = algo.pagerank(graph).top_k(1)
print(
"The most important node in the graph is",
top_node[0][0],
"with a score of",
top_node[0][1],
)
输出
Graph(number_of_edges=2, number_of_nodes=3, earliest_time=1, latest_time=3)
| | earliest_time | name | out_degree | in_degree |
|---|---------------|---------|------------|-----------|
| 0 | 1 | Alice | 0 | 0 |
| 1 | 1 | Bob | 0 | 0 |
| 2 | 1 | Charlie | 0 | 0 |
| 3 | 2 | Bob | 1 | 0 |
| 4 | 2 | Charlie | 0 | 1 |
| 5 | 3 | Alice | 1 | 0 |
| 6 | 3 | Bob | 1 | 1 |
| 7 | 3 | Charlie | 0 | 1 |
The edge between Bob and Charlie has the following weight history: [(2, 5.0), (3, -15.0)]
The weight of the edge between Bob and Charlie has changed by 20.0 pts
The top node in the graph is Charlie with a score of 0.4744116163405977
GraphQL
作为Python API的一部分,您可以在Raphtory的GraphQL服务器中托管您的数据。这使得将图分析集成到Web应用程序中变得非常容易。
以下是一个创建图、运行托管这些数据的服务器以及直接使用我们的GraphQL客户端查询它的示例。
from raphtory import Graph
from raphtory.graphql import GraphServer
import pandas as pd
import os
# URL for lord of the rings data from our main tutorial
url = "https://raw.githubusercontent.com/Raphtory/Data/main/lotr-with-header.csv"
df = pd.read_csv(url)
# Load the lord of the rings graph from the dataframe
graph = Graph()
graph.load_edges_from_pandas(df,"time","src_id","dst_id")
#Create a working_dir for your server and save your graph into it
#You can save any number of graphs here or create them via the server ones its running
os.makedirs("graphs/", exist_ok=True)
graph.save_to_file("graphs/lotr_graph")
# Launch the server and get a client to it.
server = GraphServer(work_dir="graphs/").start()
client = server.get_client()
#Run a basic query to get the names of the characters + their degree
results = client.query("""{
graph(path: "lotr_graph") {
nodes {
list{
name
degree
}
}
}
}""")
print(results)
输出
Loading edges: 100%|██████████████| 2.65K/2.65K [00:00<00:00, 984Kit/s]
Playground: https://127.0.0.1:1736
{'graph':
{'nodes':
[{'name': 'Gandalf', 'degree': 49},
{'name': 'Elrond', 'degree': 32},
{'name': 'Frodo', 'degree': 51},
{'name': 'Bilbo', 'degree': 21},
...
]
}
}
GraphQL Playground
当您托管Raphtory GraphQL服务器时,您将获得一个捆绑的Web playground,可以在浏览器中的同一端口上访问(默认为1736)。在这里,您可以实验对图的查询并探索模式。以下是一个playground的示例,运行与上面Python示例相同的查询。
入门指南
为了帮助您使用Raphtory,我们在Raphtory网站上提供了一套完整的教程。
如果您更喜欢API文档,可以直接在此处深入了解!
在线笔记本沙盒
想试试看,但无法安装?查看我们的交互式Jupyter Notebooks中的Raphtory操作!只需点击下面的徽章即可在线启动Raphtory沙盒,无需安装。
社区
加入越来越多的开源爱好者,他们使用Raphtory来推动他们的图分析!
贡献者
赏金板
Raphtory目前提供奖励以鼓励贡献,如新增功能或算法。贡献者将获得周边产品和奖品!
要开始,请查看我们期望的算法列表,其中包含一些易于实现的简单目标(🍇)。
基准测试
我们托管了一个页面,每当向master分支推送时,都会触发并保存两个基准测试的结果。在此查看
许可证
Raphtory根据GNU通用公共许可证v3.0(请参阅我们的LICENSE文件)进行许可。
依赖项
~84MB
~1.5M SLoC