我们可以将 apoc.ml.openai.embediing 与 Neo$j 桌面一起使用吗?

问题描述 投票:0回答:1

我想查询neo4j数据库并使用LLM将结果转换为自然语言? 可以在neo4j桌面上完成吗?我已经安装了 APOC 插件,但我没有看到任何 apoc.ml 程序。

提示示例:

#Are there any news regarding return to office policies? CALL apoc.ml.openai.embedding(["Are there any news regarding return to office policies?"],  "{openai_api_key}") 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

当我尝试在 neo4j 桌面中使用上述查询时,出现此错误: Neo.ClientError.Procedure.ProcedureNotFound 没有为此数据库实例注册名称为

apoc.ml.openai.embedding
的过程。请确保您正确拼写了过程名称并且该过程已正确部署。

neo4j cypher azure-openai openaiembeddings
1个回答
0
投票

APOC 有两个版本:APOC Core 和 APOC Extended。 APOC Core 受到 Neo4j 官方支持,并且在 Aura(Neo4j 的云托管版本)中可用,而 Extended 则不然。但是,嵌入方法仅在 APOC Extended 中可用,因此原因之一可能是您安装了 APOC Core。

但是在 Neo4j 5.15.0 版本中,您不再需要 APOC 来进行嵌入,该版本有官方支持的嵌入过程/函数版本,这些版本也可以在 Aura 中使用(或很快就会提供)。

如果您托管自己的数据库,则需要安装一个名为 neo4j-genai-plugin-5.XX.0.jar 的包(将其从产品文件夹复制到插件并重新启动 Neo4j)。在 Aura 中,它们默认可用。

嵌入方法现在称为:

genai.vector.encode
genai.vector.encodeBatch

您可以像这样使用它们(假设您使用 OpenAI。它还支持 VertexAI 和 AWS Bedrock):

WITH genai.vector.encode($phrase, "OpenAI", {token: $apiKey}) AS embedding

其中 $phrase 是要嵌入的单个字符串

CALL genai.vector.encodeBatch([$phrase1, $phrase2], "OpenAI", {token: $apiKey}) yield index, resource, vector

如果您想批量嵌入多个短语

所以用你的例子来说就是

WITH genai.vector.encode("Are there any news regarding return to office policies?", "OpenAI", {token: "{openai_api_key}"}) AS embedding
MATCH (c:Chunk) WITH c, gds.similarity.cosine(c.embedding, embedding) AS score ORDER BY score DESC LIMIT 3 RETURN c.text, score
© www.soinside.com 2019 - 2024. All rights reserved.