← 返回博客
跳至主要内容

使用 n8n 和 Weaviate 实现 AI Agent 工作流自动化

·阅读需 16 分钟
Mary Newhauser

AI Agent Workflow Automation with n8n and Weaviate

无需代码的 Weaviate 就在这里。但即使你已经会编码,你也需要看看它。

新的 Weaviate 社区节点 允许你将 Weaviate 向量存储与 n8n 的无代码自动化平台一起使用。

有了 n8n,你可以创建工作流,连接不同的应用程序、服务和数据源。n8n 的 AI 和 AI agent 节点以及与 OpenAI、Google、Anthropic 和 Cohere 等 LLM 提供商的集成,使你无需编写任何代码即可构建复杂的 AI 和 agent 工作流。

那么在使用 n8n 时,为什么需要向量数据库?在 n8n 中使用向量存储允许你在执行 AI 相关任务时引用整个知识库,而不是依赖于少样本提示或上下文窗口,后者对于特定主题可能不可靠。向量存储为 LLM 和 AI agent 提供上下文,以保证其答案的准确性和可靠性。这意味着改进 n8n 中检索管道的最简单方法可能是将向量存储添加到你的工作流中。

n8n 的 Weaviate 社区节点

Weaviate 向量存储社区节点意味着无需代码的 Weaviate 就在这里。我们的节点具有四个核心功能,可以让你与 AI 和 AI agent 节点无缝协作

  1. 获取多个: 查询 Weaviate 向量存储以获取多个排序文档。
  2. 插入文档: 将文档插入到 Weaviate 向量存储中。
  3. 检索文档(作为链/工具的向量存储): 从 Weaviate 向量存储检索文档,用作 AI 节点的工具。
  4. 检索文档(作为 AI Agent 的工具): 从 Weaviate 向量存储检索文档,用作 AI agent 节点的工具。

Weaviate 对开源的承诺意味着你可以使用我们的 n8n 社区节点与 本地版本的 WeaviateWeaviate Cloud 配合使用。

为了帮助你掌握在 n8n 中使用 Weaviate 的技巧,我们创建了一个 示例模板,我们将在本文中引导你完成。

在这个 模板 中,我们创建了一个工作流,该工作流从 arXiv 抓取 AI 和机器学习文章摘要,使用 LLM 丰富它们,将它们嵌入到 Weaviate 中,并将其馈送到 AI agent,以每周自动执行趋势分析。结果是一封简短的电子邮件,总结了本周的关键研究趋势,并链接到最有趣和最具影响力的 arXiv 论文。

overall-workflow.jpg

此工作流分为两部分

  1. 获取、清理、丰富并将 arXiv 摘要插入到 Weaviate 中。
  2. 使用 agentic RAG 识别研究趋势并在每周电子邮件中发送它们。

先决条件

  1. 现有的 Weaviate 集群。 你可以在 这里 查看使用 Docker 设置 本地集群 的说明,或在 这里 查看设置 Weaviate Cloud 集群的说明。
  2. 用于生成嵌入和运行 Google Gemini 的 API 密钥。 随时可以根据你的喜好切换模型!
  3. 具有 STMP 权限的电子邮件地址。 这是电子邮件将发出的地址。
  4. 自托管的 n8n 实例。 请参阅此 视频,了解如何在三分钟内完成设置。

在 n8n 中设置 Weaviate 凭据

设置你的 Weaviate 凭据 在 n8n 中非常快速和简单。

  1. 导航到你的 n8n 主页,单击“创建工作流”按钮旁边的向下箭头,然后单击“创建凭据”。

Create new n8n credential

  1. 对于添加 Weaviate Cloud 凭据,在 Connection Type 下选择 Weaviate Cloud。在创建 新的云集群 后,请按照以下 说明 从你的 Weaviate Cloud 集群获取以下参数
    • Weaviate Cloud Endpoint(在 Weaviate Cloud 控制台中,这称为 REST Endpoint
    • Weaviate Api Key

Create Weaviate n8n local credential

  1. 对于添加使用本地 Weaviate 的凭据,在 Connection Type 下选择 Custom Connection。所有字段都应预先填充,除了 Weaviate Api Key。如果你正在使用 Docker 运行 Weaviate,你可以启用 API 密钥身份验证并在你的 docker-compose.yml 文件中设置你自己的 API 密钥,如下所示
services:
weaviate:
...
environment:
...
AUTHENTICATION_APIKEY_ENABLED: 'true'
AUTHENTICATION_APIKEY_ALLOWED_KEYS: 'your-api-key-here'
AUTHENTICATION_APIKEY_USERS: 'your-username'

n8n-create-credential-4.jpg

第一部分:获取、清理、丰富并将 arXiv 摘要插入到 Weaviate 中

在这个工作流的第一部分,我们激活一个 Schedule Trigger 节点,以每周获取 AI 和 ML 摘要(以及文章标题、作者、发布日期等元数据)。我们清理数据,然后使用 LLM 丰富数据,LLM 将用主题类别标记数据,并预测每篇文章在该领域的潜在影响。最后,我们将丰富后的清理数据上传到 Weaviate 集合,并验证数据是否已上传。

第一部分步骤如下

  1. 指定每周自动化的日期范围。 此日期范围设置为包括过去七天,因为这是一个每周自动化。但是,你可以通过编辑 Date & Time 节点中的 Duration 参数来设置任何日期范围。
  2. 从 arXiv 获取每周文章。 我们使用我们的搜索查询向 arXiv API 发送 GET 请求,以获取摘要及其元数据。我们根据 arXiv API 制定搜索查询,其中包含发布在 cs.LGstat.ML 类别中的文章,并选择前 200 篇文章。你可以通过调整查询字段中的 max_results=200 来增加获取的文章数量。
https://export.arxiv.org/api/query?search_query=cat:cs.LG+OR+cat:stat.ML&sortBy=submittedDate&sortOrder=descending&start=0&max_results=200&last_update_date_from={{ $('Date & Time').item.json.startDate.toDateTime().toFormat("yyyyMMdd") }}
  1. 预处理获取的数据。 arXiv API 以 XML 形式返回我们的结果,因此我们需要将 XML 转换为 JSON。然后,我们解析 JSON 文件并提取所需字段,为 Weaviate 格式化数据,并删除重复项(如果存在)。具体来说,我们需要将具有多个条目的字段(如作者或类别)合并到一个字符串数组中,以便将其作为元数据传递到 Weaviate。以下是一个示例
# ❌ Before preparing data for Weaviate
{
"category": [
{
"term": "cs.CR"
},
{
"term": "cs.LG"
}
]
}

# ✅ After preparing data for Weaviate
{
"category": "["cs,CV", "cs.LG"]"
}
  1. 使用主题分类和潜在影响预测丰富 arXiv 文章。 在工作流的这一部分,我们将标题和摘要馈送到 LLM,并提示它通过从预定义的类别列表中分配每个文章的主要主题类别来丰富我们的文章。每篇文章还将分配最多两个不同的次要类别,并获得一个 1-5 分的评分,以预测其在该领域中的潜在影响。你可以在下面看到我们使用的系统提示
You are an expert AI agent designed to classify academic research papers. Your task is to analyze the provided arXiv paper data and categorize it based on its content.

Input Data Schema:
The input data will be a JSON object with the following structure:

{
"title": "string",
"summary": "string"
}

You MUST respond with a JSON object containing the following fields:

"primary_category": (string) The single most relevant primary category for the paper. You MUST choose one category from the following predefined list. Do NOT use any category not on this list.

"secondary_categories": (array of strings) Up to two additional relevant secondary categories. These are optional; if no secondary categories apply, provide an empty array []. If chosen, they MUST also be from the predefined list.

"potential_impact": (integer) An integer score from 1 to 5, judging the paper's potential impact based on these criteria:

1: Papers with no new existing information or limited results.

2: Papers with minor incremental contributions or limited novelty.

3: Papers with solid contributions, good results, and clear utility, but not groundbreaking.

4: Papers with significant advancements, novel approaches, or strong potential to influence the field.

5: Papers that are potential game-changers, representing paradigm shifts, or opening entirely new research directions.

Predefined Categories and Definitions:

Foundation Models: Models trained on broad data at scale, designed to be adaptable to a wide range of downstream tasks (e.g., large language models, large vision models, multi-modal models).

LLM Fine-tuning: Techniques and methodologies for adapting pre-trained Large Language Models (LLMs) to specific tasks or datasets.

Parameter-Efficient Fine-tuning (PEFT): Methods that enable efficient adaptation of large pre-trained models to new tasks with minimal computational cost, by updating only a small subset of parameters (e.g., LoRA, Prompt Tuning).

Retrieval-Augmented Generation (RAG): Architectures or systems that combine generative models (like LLMs) with information retrieval mechanisms to enhance the factual accuracy and relevance of generated outputs by referencing external knowledge bases.

Model Quantization: Techniques for reducing the precision of model parameters (e.g., from float32 to int8) to decrease model size, memory footprint, and computational requirements, often for efficient deployment on edge devices.

Agentic AI / AI Agents: Systems designed for autonomous decision-making, planning, and action in dynamic environments, often involving reasoning, memory, and tool use.

Multimodality: Models capable of processing, understanding, and generating content across multiple data types or modalities (e.g., text and images, audio and video).

Reinforcement Learning: A paradigm where an agent learns to make decisions by performing actions in an environment to maximize a cumulative reward, often through trial and error.

Computer Vision (Specific Techniques): Papers focusing on particular computer vision tasks or methodologies that are not primarily about foundation models (e.g., 3D reconstruction, object detection, image segmentation, pose estimation).

Natural Language Processing (Specific Techniques): Papers focusing on particular NLP tasks or methodologies that are not primarily about foundation models or LLM fine-tuning (e.g., text summarization, machine translation, sentiment analysis, named entity recognition).

Ethical AI / AI Safety: Research addressing the societal implications of AI, including fairness, bias detection and mitigation, interpretability, transparency, privacy, and alignment with human values.

Efficient AI / AI Optimization: Techniques aimed at improving the computational efficiency, speed, or resource usage of AI models beyond just quantization, including architecture search, inference optimization, and hardware-aware design.

Data-centric AI: Approaches that prioritize improving the quality, quantity, and organization of data used to train AI models, rather than solely focusing on model architecture improvements.

Other: A catch-all category for articles that don't fall into one of the classes mentioned above.

Focus solely on the content of the paper's title, summary, and categories to make your classification. Do NOT include any conversational text or explanations in your response, only the JSON object.
注意

此步骤的目的是最终为我们的 agent 提供更多关于文章的结构化数据,以帮助其分析并减少同时执行分类和趋势分析的计算负载。

  1. 后处理丰富的数据。 在此步骤中,我们只是将 LLM 的输出与现有的文章元数据合并,以便将所有这些上传到 Weaviate。
  2. 创建新的 Weaviate 集合(在现有的集群中)。 双击 Weaviate Vector Store 节点以配置这些设置。
    • 连接到你的 Weaviate Cloud 或本地凭据。
    • Operation Mode 设置为 Insert Documents
    • 要将新数据插入到 新的 Weaviate Collection 中,请选择 By ID 并以 SnakeCase 格式为你的集合命名。
    • 要将数据插入到 现有的 Weaviate Collection 中,请选择 From List 并从下拉菜单中选择你现有的集合。
    • Options 下,单击 Add Option 并选择 Text Key。这是将生成嵌入的字段。在此示例中,我们嵌入数据中的 summary 字段,因为这是文章的摘要文本。

Create new Weaviate collection in n8n

  1. 配置嵌入组件。 双击 Embeddings OpenAI 节点。
    • 选择你的嵌入提供商和模型,并将其连接到你的凭据。
  2. 配置数据加载器组件。 双击 Default Data Loader 节点。
    • 我们正在加载的 Type of DataJSON
    • 如果你正在包含元数据(我们正在包含),请将 Mode 设置为 Load Specific Data
    • Data 字段表示我们要生成嵌入的数据。
    • Options 下,我们定义我们的元数据模式。

Configure n8n data loader

  1. 配置文本拆分器。
    • 我们正在使用 Recursive Character Text Splitter 并将我们的 Chunk Size 设置为 2000 以获取每个摘要一个块(但请随时尝试!)。
  2. 确认文章和嵌入已上传。 这些步骤用于验证新的每周文章是否已成功嵌入并上传到 Weaviate,然后再运行 AI Agent 节点。 文章列表将生成一个静态 session_id,作为该验证。
# ID's of successfully uploaded article abstracts
[
{
"arxiv_id": [
"http://arxiv.org/abs/2506.20668v1",
"http://arxiv.org/abs/2506.20651v1",
"http://arxiv.org/abs/2506.20650v1",
...
]
}
]
  • 首先,我们获取刚刚上传到 Weaviate 的所有 arXiv ID 的列表。
  • 如果列表中有 ID,我们将生成一个静态 session_id,它将作为 AI Agent 节点的触发器。

最后,数据收集和嵌入生成完成,我们准备好配置我们的 AI agent。

在工作流程的这一部分中,我们配置一个 AI Agent 节点,将其用作 Weaviate 的工具。 整个嵌入式文章摘要集合及其元数据都可供 agent 使用。 我们指示 agent 将 Weaviate 用作工具,描述可用的输入数据,并给出识别趋势和构建摘要电子邮件的指示。 最后,我们清理数据并通过电子邮件发送。

以下是第二部分的步骤

  1. 配置 AI Agent 节点(将 Weaviate 作为工具 首先,我们使用简短的用户提示和更长、更具描述性的系统提示设置 agent。

    • Prompt 的来源(用户消息) 设置为 定义如下
    • Prompt(用户消息) 中,给出对检索和分析任务的简短说明。
    • 选项 下,单击 添加选项 以添加 系统消息,也称为系统提示。 提供有关 agent 的具体说明,包括
      • 有关如何查询 Weaviate 向量存储的说明
      • 我们数据在 Weaviate 中的模式说明
      • 有关如何确定趋势的说明
      • 指定的输出格式
      • 真实输出示例
  2. 配置 Weaviate 向量存储。

    • 选择与之前相同的凭据(云端或本地)进行连接。
    • 操作模式 设置为 将文档作为 AI Agent 的工具检索
    • 为工具添加 描述,告诉 LLM 如何使用 Weaviate 向量存储。
    This tool allows you to query the Weaviate Vector Store1 to retrieve arXiv article titles, summary and other metadata to be used as the sole data source performing a trend analysis. You must query the database to get information for the trend analysis.
    • 通过选择 按 ID 并输入与上述相同的集合名称:ArxivArticles 来连接到现有的向量存储。
    • 启用 包含元数据,因为发布日期、标题和 arXiv URL 对于 agent 的响应至关重要。
    • 选择 OpenAI 作为查询的嵌入提供程序。
注意

n8n agent 的工具描述非常重要! 糟糕的工具描述可能导致 agent 不使用该工具。 好的描述包括有关 agent 应该如何使用该工具以及该工具的功能的说明。 你可以在这里语气强硬。

  1. 添加模型、内存和输出解析器。
    • 我们使用 OpenRouter Chat Model 节点,以便可以使用 Google Gemini 作为 agent。
    • 为 agent 添加简单的(短期)内存,将 会话 ID 设置为 定义如下,将 Key 设置为 sessionId(因为我们只使用短期内存,不存储 agent 的输出以供将来使用)。
    • 添加 结构化输出解析器 节点并将 模式类型 设置为 从 JSON 示例生成
    • JSON 示例 中,我们定义 agent 的输出格式,这将是结果摘要电子邮件所需的标题和正文文本。
{
"subject": "...",
"body": "..."
}
  1. 后处理 agent 响应。 在这里,我们清理 agent 的响应,并将电子邮件的正文文本从 markdown 格式转换为 HTML。
  2. 将输出作为电子邮件发送。 最后,我们选择我们的 STMP 帐户 凭据(电子邮件将发送到的帐户),输入要发送电子邮件的地址,并使用来自上一个节点的数据格式化 主题HTML 字段。

工作流程输出

此工作流程的最终输出是一封简短的电子邮件,突出显示了 AI 和机器学习领域中的关键研究趋势并预测了未来的研究方向。 每个趋势都以一句话简洁地总结,并包含指向 arXiv 上原始论文的链接。

n8n workflow output

此模板可以以无数种方式进行自定义、扩展和优化。 所有这些都不需要一行代码。

结论

在这篇文章中,我们向您展示了如何在 agentic n8n 工作流程中使用 Weaviate 向量存储社区节点。 我们专门演示了如何创建新的 Weaviate 集合,生成并存储其中的嵌入,并将其用作 agentic 工具来执行 agentic RAG。

这只是在 n8n 中使用 Weaviate 社区节点的众多可能方法之一,我们鼓励您尝试使用不同的嵌入模型、分块策略、提示工程,甚至将多个 agent 纳入您的工作流程中。

如果您使用 Weaviate 创建了很酷的模板,请告诉我们,也许我们会与我们的社区分享。 💚

资源指南

🔗  创建 n8n 帐户

📺. 3 分钟内设置 N8N 自托管(6 种方法) (YouTube)

🧑‍💻  arXiv 趋势分析模板 (n8n 模板)

📋  使用 Docker 设置本地 Weaviate 集群 (文档)

📋  设置 Weaviate Cloud 集群 (文档)

📝  什么是 Agentic 工作流程?模式、用例、示例等 (博客)

📝  什么是 Agentic RAG (博客)