> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Neo4j 集成

> 使用 LangChain Python 与 Neo4j 集成。

> * Neo4j 是一个专注于图数据库技术的 `开源数据库管理系统`。
> * Neo4j 允许您以节点和边的形式表示和存储数据，使其非常适合处理关联数据和关系。
> * Neo4j 提供了 `Cypher 查询语言`，使得与图数据交互和查询变得简单。
> * 使用 Neo4j，您可以实现高性能的 `图遍历和查询`，适用于生产级系统。

> 通过访问[其网站](https://neo4j.com/)开始使用 Neo4j。

## 安装与设置

* 使用 `pip install neo4j langchain-neo4j` 安装 Python SDK

## 向量存储

Neo4j 向量索引被用作向量存储，
无论是用于语义搜索还是示例选择。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_neo4j import Neo4jVector
```

查看[使用示例](/oss/python/integrations/vectorstores/neo4jvector)

## GraphCypherQAChain

存在一个围绕 Neo4j 图数据库的包装器，它允许您根据用户输入生成 Cypher 语句，
并使用它们从数据库中检索相关信息。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_neo4j import GraphCypherQAChain, Neo4jGraph
```

查看[使用示例](/oss/python/integrations/graphs/neo4j_cypher)

## 从文本构建知识图谱

文本数据通常包含丰富的关系和见解，这些对于各种分析、推荐引擎或知识管理应用非常有用。
Diffbot 的 NLP API 允许从非结构化文本数据中提取实体、关系和语义含义。
通过将 Diffbot 的 NLP API 与图数据库 Neo4j 结合，您可以基于从文本中提取的信息创建强大、动态的图结构。
这些图结构是完全可查询的，并且可以集成到各种应用中。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_neo4j import Neo4jGraph
from langchain_experimental.graph_transformers.diffbot import DiffbotGraphTransformer
```

查看[使用示例](/oss/python/integrations/graphs/diffbot)

## 检查点保存器

LangGraph 检查点保存器的 Neo4j 实现，用于支持分支时间旅行的持久化 GitHub 代理记忆。检查点保存器在每个超级步骤持久化图状态，从而实现会话记忆、人在回路工作流、时间旅行和容错。
适用于 LangGraph 图和 LangChain 代理：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_neo4j import Neo4jSaver

with Neo4jSaver.from_conn_string(
    uri="bolt://localhost:7687",
    user="neo4j",
    password="password"
) as checkpointer:
    checkpointer.setup()  # 创建索引（仅运行一次）
    # 使用检查点保存器创建代理
    agent = create_agent(
        model="google_genai:gemini-3.1-pro-preview",
        tools=[get_weather],
        system_prompt="You are a helpful assistant",
        checkpointer=checkpointer
    )
```

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs)通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/providers/neo4j.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
