返回资讯中心
外部精选
软件工程
#开发者实时流

Neo4j 发布实验性嵌入式图数据库 Relate,单二进制即可运行

来源标题:Relate by Neo4j – embedded, agent-native graph database

Neo4j Labs 推出实验性项目 Relate,一款用 Rust 编写的嵌入式内存属性图引擎,整个图数据库可打包为单个二进制文件,无需部署服务器。它支持用 Cypher 查询,可作为 Python 包、Node.js 与浏览器 WASM 包、Rust crate 使用,也可选启动支持 Bolt、HTTP 和 MCP 的单进程服务。该项目不属于 Neo4j 官方支持产品线。

Hacker News 最新jexp2026/11/12 · 5 天前30 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

A graph database in a single binary — query it in Cypher, embed it anywhere, deploy nothing.

Relate is an embedded, in-memory property-graph engine written in Rust, with a command-line shell for interactive and scripted queries. A graph is a single .rl file, a directory, or pure in-memory — durable through a fsync'd write-ahead log and Parquet checkpoints. The same engine powers the relate CLI, a Python package, Node.js and browser (WASM) npm packages, a Rust crate, and an optional one-process server speaking Bolt, HTTP, and MCP. No server to babysit, no infrastructure to operate.

📖 Documentation: relatedb.ai — tutorials, guides, and the CLI / Cypher / Rust / C API references. The deep references live in docs/ in this repository, and the honest list of what Relate does not do yet is docs/limitations.md.

This is an experimental Neo4j Labs project and not part of Neo4j's supported product lineup. See the Neo4j Labs disclaimer.

curl -sSfL https://relatedb.ai/install.sh | bash

Downloads the release binary for your platform (macOS and Linux, amd64 and arm64) to $HOME/.local/bin, resolving the latest release from releases.json — the same release metadata relate upgrade reads (ADR-0571 — and the assets themselves come straight from the GitHub release download route, so the installer makes no GitHub API requests and no token is ever needed, even behind shared-IP networks (ADR-0585)). Each release's SHA256SUMS manifest is authenticated against its SSHSIG signature with the stock ssh-keygen — the public key is pinned in the script, and the installer fails closed on a missing or invalid signature (ADR-0115). macOS binaries are additionally signed and notarized, so Gatekeeper raises no warning (ADR-0123). Prebuilt binaries for Linux, macOS, and Windows are on the releases page, and an installed binary self-updates:

relate upgrade # download, verify, and replace (alias: update) relate upgrade --check # report current vs latest; changes nothing

Python:

pip install relate-db # the import is import relate

npm — Node.js and the browser:

npm install @relate/relate # Node.js 18+ (native bindings) npm install @relate/relate-wasm # browser (WebAssembly)

Rust:

cargo add --git https://github.com/relatedb/relate relate

Until the PyPI and npm publishes land, Python wheels are on the releases page and every package builds from source — see Development.

Hand the wheel to your AI agents, or drive it yourself:

Once: install the relate skill bundle — CLI + Cypher + vector + spatial

references — into every detected AI agent (Claude Code, Cursor, Codex,

Gemini CLI, Copilot, Windsurf, OpenCode, ...)

relate skill install

One-shot query on an in-memory database

relate "RETURN 1 + 2 AS sum"

Open (or create) a store and drop into the interactive shell

relate query --database ./friends

Script-friendly output

relate --json ./friends "MATCH (p:Person) RETURN p.name"

Run a file of statements

relate -d ./friends < setup.cypher

relate skill install is optional — it teaches supported agents the CLI flags, the Cypher dialect, and the gotchas, so they can drive relate for you. relate upgrade keeps the bundle current automatically. More in Agent skill.

$ relate query --database ./friends

Relate v1.0.2 Type .help for help, .exit to quit.

cypher> CREATE (alice:Person {name: 'Alice', age: 30}); Nodes created: 1, Properties set: 2, Labels added: 1

cypher> CREATE (bob:Person {name: 'Bob', age: 28}); Nodes created: 1, Properties set: 2, Labels added: 1

cypher> MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) ...> CREATE (a)-[:FRIENDS_WITH {since: 2020}]->(b); Relationships created: 1, Properties set: 1

cypher> MATCH (p:Person)-[r:FRIENDS_WITH]->(friend) ...> RETURN p.name, friend.name, r.since; +--------+-------------+---------+ | p.name | friend.name | r.since | +--------+-------------+---------+ | Alice | Bob | 2020 | +--------+-------------+---------+

Surfaces

One engine, many front doors: the CLI (Quick start above), the libraries below, the server surfaces (Bolt, HTTP, MCP), and the extension mount (Extensions below).

Queries execute in-process — a native extension module (PyO3), no server, no subprocess:

import relate

db = relate.connect(":memory:") # or "./friends" — a directory or .rl file

db.execute("CREATE (p:Person {name: $name, age: $age})", {"name": "Alice", "age": 30}) db.execute("CREATE (p:Person {name: $name, age: $age})", {"name": "Bob", "age": 28}) db.execute( "MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) " "CREATE (a)-[:FRIENDS_WITH {since: 2020}]->(b)" )

for row in db.execute("MATCH (p:Person)-[:FRIENDS_WITH]->(f) RETURN p.name, f.name"): print(f"{row['p.name']} -> {row['f.name']}") # Alice -> Bob

A native Database class adds execute_arrow() — zero-copy Arrow IPC into pandas or Polars. Spec: docs/api/python/; runnable example: examples/python/python_demo.py.

const { Database } = require("@relate/relate");

const db = Database.open("./friends"); // or ":memory:" const result = db.connect().query("MATCH (p:Person) RETURN p.name");

result.rows; // [{ "p.name": "Alice" }, ...] result.stats; // mutation counters, zeros included result.consume().elapsedMs; // engine-reported milliseconds

Node 18+; the native library arrives via platform optional-dependencies — no install scripts. Spec: docs/api/javascript/.

The engine compiled to WebAssembly — run Cypher in a page, no server:

import init, { RelateDb } from "@relate/relate-wasm";

await init();

const db = new RelateDb(); // in-memory const result = JSON.parse(db.execute("RETURN 1 AS n", null));

Durable browser storage via OPFS: await RelateDb.open("opfs://graph") — runs in a dedicated worker only. Spec: docs/api/wasm/.

relate::Database is the engine's public API — the surface every other binding wraps:

use relate::Database;

fn main() -> relate::Result<()> { let db = Database::open("./friends")?; let mut conn = db.connect()?;

conn.query("CREATE (n:Person {name: 'Ada'})")?; let result = conn.query("MATCH (n:Person) RETURN n.name AS name")?; println!("{}", result.rows[0][0]); // Ada Ok(()) }

Explicit transactions, cancellation tokens, and read-only, follow, and ephemeral opens. Spec: docs/api/rust/.

Every language client wraps one typed C ABI — version 2, additive-only after the first public release:

#include "relate.h"

relate_database db = NULL; relate_connection conn = NULL; relate_query_result r = NULL; char err = NULL; / out-param errors: start NULL */

relate_database_open(":memory:", &db, &err); relate_connect_namespace(db, NULL, &conn, &err); relate_query_params(conn, "RETURN 1 AS n", NULL, &r, &err);

The header and library (librelate_ffi, static or shared) ship as relate-ffi-<target>.tar.gz on the releases page; every fallible call reports through one typed error channel. Contract: docs/api/c/.

com.relate:relate — Java 17+, JNA over the C ABI, with the native library bundled in the jar (one fat jar, or one of five platform classifiers):

try (Database db = Database.open("./friends"); Database.Connection conn = db.connect()) { Result result = conn.query("RETURN $n AS n", java.util.Map.of("n", 1)); result.columns(); // List<String> result.rows(); // List<List<Object>> — typed values }

Jars are on the releases page until Maven Central goes live. Spec: docs/api/java/.

Module github.com/relatedb/relate/clients/go, cgo against librelate_ffi (from the release tarballs, or built with cargo build --release -p relate-ffi):

db, err := relate.Open("./friends") conn, err := db.Connect() result, err := conn.Query("MATCH (p:Person) RETURN p.name") // result.Columns []string, result.Rows [][]any

Spec: docs/api/go/.

A SwiftPM package (iOS 16+ / macOS 13+, Swift 6) wrapping the C ABI, with the checksummed binary framework attached to every release:

// Package.swift of a consumer .package(url: "https://github.com/relatedb/relate", from: "<release>") // target dependency .product(name: "Relate", package: "relate")

let db = try Database(path: "./friends") let conn = try db.connect() let result = try conn.query("MATCH (p:Person) RETURN p.name")

Spec: docs/api/swift/.

When you want a socket instead of a library:

relate serve --database ./friends --bolt 7687 --http 7474 --mcp 7475

One process, one store, one generated token (printed at startup): Neo4j drivers connect over Bolt — neo4j-browser works out of the box — the HTTP Query API v2 serves JSON, and MCP (streamable HTTP) serves AI hosts. Binds loopback by default; runs until SIGINT/SIGTERM. Specs: bolt, http, mcp.

Docker — make docker builds the server image (multi-stage, a FROM scratch runtime with static binaries); make docker-run runs Bolt (7687), HTTP (7474), and MCP (7475) on localhost with a data volume. Auth is on by default; the token is in the startup banner:

TOKEN=$(docker logs <container> 2>&1 | sed -n 's/.*generated token for user relate: //p' | head -1) python -c "from neo4j import GraphDatabase; print(GraphDatabase.driver('bolt://localhost:7687', auth=('relate', '$TOKEN')).execute_query('RETURN 1 AS n')[0][0]['n'])"

Or preset it with -e RELATE_AUTH=relate:secret (...=none disables it — publish ports on trusted networks only). Configuration is env-based and echoed at startup (docker logs is the debugging surface); a fresh store can be seeded before the server starts:

docker run -p 7687:7687 -p 7474:7474 -p 7475:7475 -v "$PWD/data:/data"
-e RELATE_QUERY="UNWIND range(1,100) AS i CREATE (:Person {id: i})"
relate-bolt:latest

fetch-and-seed from a JSON API, or mirror a Neo4j/Aura subgraph:

-e RELATE_LOAD='value=https://…' + -e RELATE_LOAD_QUERY='UNWIND $value.items AS q MERGE (:Question {id: q.question_id})'

-e RELATE_PULL_FROM=/run/secrets/neo4j.env + -e RELATE_PULL_QUERY='MATCH (o:Organization)-[r]-() RETURN o, r LIMIT 500'

For large seeds, two knobs matter (details: Bulk import): batch the writes into few statements — one UNWIND per few thousand rows — because each autocommit statement pays one WAL fsync under the default full durability; and relax that barrier for the seed run with -e RELATE_DURABILITY_MODE=everysecond (a crash can lose ~1s of acknowledged writes — drop the variable when serving).

INSTANCES=N runs a test fleet of N serve processes with stepped port ranges. The image is a dev/test image: serve is plaintext-only and warns loudly about it — for encrypted Bolt, front it with a TLS-terminating proxy.

Area What it covers

Cypher Reading and writing (MATCH, OPTIONAL MATCH, CREATE, MERGE, SET, REMOVE, DELETE, FOREACH, INSERT), composing (WITH, UNWIND, UNION, CALL {} subqueries, subquery expressions), schema DDL (indexes, constraints, graph types), 80+ built-in functions, and modern pattern matching — label expressions, quantified path patterns, path selectors. One dialect: current Cypher.

Language floor The openCypher TCK is the dialect floor, measured by the project's spec harness: Neo4j's Cypher suites — the upstream TCK among them — run against the engine's Python wheel on every ready PR, as reported coverage, never a merge gate. History: docs/tck/compliance.md.

Vector search vector() properties, vector.similarity.* scoring functions, CREATE VECTOR INDEX plus the SEARCH clause for index-backed top-K with pre-filtering, and hybrid vector + full-text queries.

Geospatial WGS-84 and Cartesian points (2D/3D), point.distance(), radius and bounding-box predicates (point.withinBBox), and R-tree point indexes (CREATE POINT INDEX). The dialect covers points only — richer geometry is host-language work.

Profiling EXPLAIN renders the plan tree; PROFILE adds per-operator rows and time. Profiling costs nothing on non-PROFILE runs.

CLI shell Interactive REPL with readline-style editing, dot-commands, output modes table, csv, json, jsonl, markdown, cypher.

Import / sync LOAD CSV directly in Cypher; --fetch-params binds a fetched URL/file JSON document as a parameter; pull/push mirror subgraphs between Relate and a Neo4j/Aura instance; clone copies a whole store across lay

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →