neo4j

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Neo4j

Neo4j

Neo4j is a native graph database. It stores data as nodes and relationships, not tables or documents. It is essential for "connected data" problems where relationships are as important as the data itself.
Neo4j是一款原生图数据库,它以节点和关系的形式存储数据,而非表格或文档。对于那些关系与数据本身同等重要的“关联数据”问题而言,它是不可或缺的工具。

When to Use

适用场景

  • Knowledge Graphs: Connecting silos of data (Users, Docs, Concepts).
  • Fraud Detection: Finding "Rings" of users sharing IDs/Devices.
  • Recommendation Engines: "People who bought X also bought Y" (Collaborative Filtering).
  • GraphRAG (2025): Enhancing LLM context by traversing a knowledge graph instead of just vector similarity.
  • 知识图谱:打通孤立的数据孤岛(如用户、文档、概念等)。
  • 欺诈检测:识别共享ID/设备的用户“圈子”。
  • 推荐引擎:实现“购买了X的用户也购买了Y”这类协同过滤功能。
  • GraphRAG(2025年):通过遍历知识图谱而非仅依赖向量相似度,增强大语言模型(LLM)的上下文信息。

Quick Start (Cypher)

快速入门(Cypher)

cypher
-- Create nodes and relationships
CREATE (alice:Person {name: 'Alice'})
CREATE (bob:Person {name: 'Bob'})
CREATE (alice)-[:KNOWS {since: 2024}]->(bob);

-- Query friends of friends
MATCH (p:Person {name: 'Alice'})-[:KNOWS]->(friend)-[:KNOWS]->(fof)
RETURN fof.name;
cypher
-- Create nodes and relationships
CREATE (alice:Person {name: 'Alice'})
CREATE (bob:Person {name: 'Bob'})
CREATE (alice)-[:KNOWS {since: 2024}]->(bob);

-- Query friends of friends
MATCH (p:Person {name: 'Alice'})-[:KNOWS]->(friend)-[:KNOWS]->(fof)
RETURN fof.name;

Core Concepts

核心概念

Cypher

Cypher

The SQL of Graphs. It uses ASCII-art patterns
(node)-[RELATIONSHIP]->(node)
.
图数据库领域的SQL语言,它使用ASCII艺术风格的模式
(node)-[RELATIONSHIP]->(node)
来表达查询。

Index-Free Adjacency

无索引邻接(Index-Free Adjacency)

In Neo4j, every node physically points to the next node. "Joins" are pre-computed pointers. Traversing 1 million relationships is O(1) per step, not O(Log N) like B-Trees.
在Neo4j中,每个节点都直接指向关联的节点。“关联查询”是预先计算好的指针。遍历100万条关系时,每一步的时间复杂度为O(1),而非像B树那样的O(Log N)。

Graph Data Science (GDS)

图数据科学(Graph Data Science,GDS)

Library for algorithms like PageRank, Louvain (Community Detection), and Path Finding.
包含PageRank、Louvain(社区检测)和路径查找等算法的库。

Best Practices (2025)

最佳实践(2025年)

Do:
  • Use GraphRAG: Combine Vector Search (Semantic) with Graph Traversal (Structural) for better AI answers.
  • Model Relationships Richly: Put properties on relationships (e.g.,
    [:REVIEWED {rating: 5, date: ...}]
    ).
  • Use Labels: Always label nodes (
    :Person
    ) to optimize scans.
Don't:
  • Don't create Supernodes: A node with 1 Million edges (e.g.,
    (Justin Bieber)-[:FOLLOWED_BY]->(...)
    ) hurts traversal performance.
  • Don't use it for simple lookups: If you just need
    ByKey
    or
    Range
    , use a K-V store.
建议
  • 使用GraphRAG:结合向量搜索(语义层面)与图遍历(结构层面),提升AI回答的质量。
  • 丰富关系建模:为关系添加属性(例如
    [:REVIEWED {rating: 5, date: ...}]
    )。
  • 使用标签:始终为节点添加标签(如
    :Person
    ),以优化扫描性能。
避免
  • 不要创建超级节点:拥有100万条边的节点(例如
    (Justin Bieber)-[:FOLLOWED_BY]->(...)
    )会影响遍历性能。
  • 不要用于简单查询:如果仅需要按键查询或范围查询,使用键值存储数据库即可。

References

参考资料