You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

咨询:Neo4j Desktop中能否使用APOC.ml.openai.embedding及LLM转换结果

在Neo4j Desktop中实现LLM转换查询结果为自然语言的方案

能在Neo4j Desktop中实现该功能,你遇到的apoc.ml.openai.embedding过程找不到的问题,核心原因是当前安装的APOC插件是Core版本,而apoc.ml系列过程仅包含在APOC Full版本中。以下是具体解决步骤:

1. 替换为APOC Full版本插件

  • 打开Neo4j Desktop,找到目标数据库实例,点击「Plugins」选项卡。
  • 若当前APOC为「APOC Core」,点击「Remove」卸载,再搜索「APOC Full」完成安装。
  • 注意:APOC版本必须与你的Neo4j版本严格匹配(比如Neo4j 5.12对应APOC 5.12.0 Full)。

2. 重启数据库实例

安装完成后必须重启数据库,才能加载新的apoc.ml系列过程。

3. 验证过程加载状态

重启后执行以下查询,确认apoc.ml.openai.embedding已注册:

SHOW PROCEDURES YIELD name WHERE name STARTS WITH 'apoc.ml.openai' RETURN name;

返回结果中包含apoc.ml.openai.embedding即表示加载成功。

4. 修正查询语句

将原查询中的{openai_api_key}替换为实际OpenAI API密钥,或通过neo4j.conf配置密钥以避免明文暴露:

apoc.ml.openai.api.key=你的OpenAI API密钥

配置后查询可简化为:

# 查询关于返回办公室政策的相关新闻
CALL apoc.ml.openai.embedding(["Are there any news regarding return to office policies?"]) YIELD embedding
MATCH (c:Chunk)
WITH c, gds.similarity.cosine(c.embedding, embedding) AS score
ORDER BY score DESC LIMIT 3
RETURN c.text, score;

5. 将查询结果转换为自然语言

获取相似片段后,可通过apoc.ml.openai.chatCompletion将结果传入LLM生成自然语言回答,示例查询:

# 查询并转换为自然语言回答
CALL apoc.ml.openai.embedding(["Are there any news regarding return to office policies?"]) YIELD embedding
MATCH (c:Chunk)
WITH c, gds.similarity.cosine(c.embedding, embedding) AS score
ORDER BY score DESC LIMIT 3
WITH collect({text: c.text, score: score}) AS results
CALL apoc.ml.openai.chatCompletion(
  [
    {role: "system", content: "你是专业信息整理员,根据给定的文本片段和相似度分数,用自然语言总结关于返回办公室政策的新闻内容,分数越高相关性越强。"},
    {role: "user", content: "相关内容:" + apoc.text.join([r.text + "(相似度:" + r.score + ")" | r IN results], "\n")}
  ]
) YIELD content
RETURN content AS natural_language_answer;

注意事项

  • 若网络无法直接访问OpenAI,需在neo4j.conf中配置代理:
    apoc.ml.openai.proxy.http=http://你的代理地址:端口
    apoc.ml.openai.proxy.https=http://你的代理地址:端口
    
  • 确保OpenAI API密钥有足够额度,且权限包含Embeddings和Chat Completion功能。

内容的提问来源于stack exchange,提问作者Amit Pawar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 04:43:36