APOC GenAI 过程

APOC Extended 过程库可与多种 AI/ML 平台集成,提供一组实用工具,帮助快速演示 GenAI 功能。该库包括用于生成文本、图像和向量嵌入的过程,并支持从自然语言生成并执行 Cypher 查询以及进行模式说明。

APOC Extended 与以下平台集成

安装

APOC extended 作为 Neo4j 的插件提供。要安装 APOC,请遵循 APOC 手册中的说明。大多数情况下,您可以下载 相应的发布版本,并将 JAR 文件放置在 Neo4j 安装目录的 plugins 文件夹中。

Neo4j Sandbox 中,APOC 已预装,您可以立即开始使用这些过程。

APOC Extended 在 Neo4j Aura 云服务中不可用。

使用

下面是一个快速示例

// generate embedding
CALL apoc.ml.openai.embedding(['Knowledge Graphs work well with LLMs'], $apiKey, {}) yield index, text, embedding;

// generate text
CALL apoc.ml.openai.completion('What color is the sky? Answer in one word: ', $apiKey, {config}) yield value;

/*
{ created=1684248202, model="text-davinci-003", id="cmpl-7GqBWwX49yMJljdmnLkWxYettZoOy",
  usage={completion_tokens=2, prompt_tokens=12, total_tokens=14},
  choices=[{finish_reason="stop", index=0, text="Blue", logprobs=null}], object="text_completion"}
*/

CALL apoc.ml.query("What movies did Tom Hanks play in?", {apiKey: $apiKey}) yield value, query
RETURN *;


CALL apoc.ml.schema({apiKey: $apiKey});
/*
The graph database schema represents a system where users can follow other users and review movies.
Users (:Person) can either follow other users (:Person) or review movies (:Movie).
The relationships allow users to express their preferences and opinions about movies.
This schema can be compared to social media platforms where users can follow each other and leave reviews or ratings for movies they have watched.
It can also be related to movie recommendation systems where user preferences and reviews play a crucial role in generating personalized recommendations.
*/

大多数过程除了接受您的输入外,还需要提供 API 密钥或令牌的配置以及模型名称。

API 密钥也可以在 apoc.conf 中进行配置,以便对所有用户开放该功能,请务必通过速率限制和预算限制来保护这些密钥。

功能包括

  • 生成向量嵌入

  • 文本补全

  • 带有系统、助理和用户角色的多消息聊天补全

  • 图像生成

  • 从自然语言生成 Cypher 查询

  • 模式解释

文档

© . This site is unofficial and not affiliated with Neo4j, Inc.