Mistral工作后台运营AI 评分 · 待评分AI 辅助编辑·未发现明显提示词注入风险n8n.io

使用 Qdrant 和 Mistral 的食谱推荐

抓取网页菜单 → Mistral 嵌入 → Qdrant 向量存储 + Recommend API → SQLite 备份 → AI Agent 聊天推荐

经验丰富步骤流程提示词
给谁
需要在 n8n 中构建推荐功能的运营者或开发者
你会得到
搭建一个能根据用户喜好和忌口推荐本周 HelloFresh 食谱的 AI 聊天机器人
你需要
n8n · mistral

硬约束

前置条件:可用的 n8n 实例;Mistral.ai 账号(API key);Qdrant 向量数据库实例及 API 凭证。需先在 Qdrant 中创建 collection:PUT collections/hello_fresh,vectors 配置为 distance=Cosine, size=1024。模板使用 HelloFresh 英国站(hellofresh.co.uk)周菜单页面作为数据源,网站结构变化可能导致抓取失效。

他们做了什么

作者 jimleuk 在 n8n 中构建了一个工作流:从 HelloFresh 英国站抓取本周菜单,将食谱详情通过 Mistral 嵌入模型转换为向量,存入 Qdrant 向量数据库;同时把完整食谱备份到本地 SQLite。然后搭建了一个 AI Agent,通过聊天界面接收用户的口味偏好和忌口,调用 Qdrant 的 Recommend API(支持正负向查询和分组去重)获取推荐食谱,再从 SQLite 取出完整内容回复用户。

效果如何

作者报告(author_report):AI Agent 能够根据用户的喜好和忌口推荐更合适的食谱,从而提升用户满意度。

值得知道

1. Qdrant 需预先创建 hello_fresh collection,vectors 配置为 distance=Cosine, size=1024。2. Recommend API 使用 average_vector 策略,通过 positive/negative 嵌入向量进行推荐,并利用 group_by=metadata.recipe_id 确保返回唯一食谱。3. 子工作流中包含 1.1 秒的 Wait 节点用于速率限制控制。4. HelloFresh 网站结构变化可能导致抓取失效,需人工维护 CSS 选择器。5. 模板可迁移到其他领域(服装、运动鞋、车辆、假期等)。6. 本站未实际运行该工作流,reproduction=not_tested。

n8n 工作流模板

结构已检查 · 未实际运行

下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。

配置与测试清单

需要绑定的凭证

  • Embeddings Mistral Cloud 节点:绑定mistralCloudApi 凭证。
  • Mistral Cloud Chat Model 节点:绑定mistralCloudApi 凭证。
  • Get Mistral Embeddings 节点:绑定mistralCloudApi 凭证。
  • Use Qdrant Recommend API 节点:绑定qdrantApi 凭证。
  • Qdrant Vector Store 节点:绑定qdrantApi 凭证。

需要替换的配置

  • 源模板来自 n8n 公开库 #2333(约 33 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
  • Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。

测试输入与预期结果

  • 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
  • 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。

模板处理说明

  • 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
  • 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。

模板获取日期: 2026-10-25

步骤

  1. 抓取本周菜单

    在 n8n 中点击「Test workflow」手动触发。工作流通过 HTTP Request 节点请求 https://www.hellofresh.co.uk/menus/{{ $now.year }}-W{{ $now.weekNumber }},获取本周菜单页面。随后用 HTML 节点提取 script#__NEXT_DATA__ 中的服务端数据,再通过 Code 节点(JavaScript)解析出前 10 个可用课程(courses)。页面较大,可能需要等待。

  2. 创建食谱文档

    对上一步获取的每个课程,并行执行:Set 节点提取元数据(name, cuisines, category, tags, nutrition, url, id);HTTP Request 节点请求食谱详情页;HTML 节点提取 description、ingredients、utensils、instructions。然后用 Merge 节点按位置合并元数据和详情,再用 Set 节点(Prepare Documents)将内容格式化为 Markdown 文档,包含标题、网站链接、食材、厨具、营养信息、步骤说明,并附加 week、cuisine、category、tag、id、name 字段。

  3. 向量化并存入 Qdrant

    将格式化后的文档送入 Default Data Loader 节点,配置 metadata(week, cuisine, category, tag, recipe_id),并启用 Recursive Character Text Splitter 进行文本切分。Embeddings Mistral Cloud 节点将文本转换为向量(需配置 mistralCloudApi 凭证)。最后通过 Qdrant Vector Store 节点以 insert 模式写入 hello_fresh collection(需预先创建,Cosine 距离,1024 维)。

    搭建指导 · 来源原文。Qdrant 服务端或控制台,创建向量集合

    PUT collections/hello_fresh
    {
      "vectors": {
        "distance": "Cosine",
        "size": 1024
      }
    }
  4. 保存原始文档到 SQLite

    使用 Code 节点(Python)连接本地 SQLite 数据库 hello_fresh_1.db,创建 recipes 表(id TEXT PRIMARY KEY, name TEXT, data TEXT, cuisine TEXT, category TEXT, tag TEXT, week TEXT),并将上一步的完整文档批量写入。此步骤为 AI Agent 后续检索完整食谱内容提供数据源。

    运行提示词 · 来源原文。n8n Code 节点,Python 模式

    import sqlite3
    con = sqlite3.connect("hello_fresh_1.db")
    
    cur = con.cursor()
    cur.execute("CREATE TABLE IF NOT EXISTS recipes (id TEXT PRIMARY KEY, name TEXT, data TEXT, cuisine TEXT, category TEXT, tag TEXT, week TEXT);")
    
    for item in _input.all():
      cur.execute('INSERT OR REPLACE INTO recipes VALUES(?,?,?,?,?,?,?)', (
        item.json.id,
        item.json.name,
        item.json.data,
        ','.join(item.json.cuisine),
        item.json.category,
        ','.join(item.json.tag),
        item.json.week
      ))
    
    con.commit()
    con.close()
    
    return [{ "affected_rows": len(_input.all()) }]
  5. 配置 AI Agent 聊天推荐

    搭建 Chat Trigger 节点作为聊天入口,连接 AI Agent 节点。AI Agent 使用 Mistral Cloud Chat Model(模型 mistral-large-2402,需 mistralCloudApi 凭证),并挂载 Qdrant Recommend API 工具。该工具通过子工作流实现:先调用 Mistral 嵌入 API 将用户的 positive/negative 描述转为向量,再调用 Qdrant 的 /collections/hello_fresh/points/recommend/groups 接口(average_vector 策略,按 metadata.week 过滤,按 metadata.recipe_id 分组去重),最后从 SQLite 查询完整食谱返回给 Agent。

    运行提示词 · 来源原文。AI Agent 节点的 systemMessage 字段

    =You are a recipe bot for the company, "Hello fresh". You will help the user choose which Hello Fresh recipe to choose from this week's menu. The current week is {{ $now.year }}-W{{ $now.weekNumber }}.
    Do not recommend any recipes other from the current week's menu. If there are no recipes to recommend, please ask the user to visit the website instead https://hellofresh.com.

    运行提示词 · 来源原文。Qdrant Recommend API 工具(toolWorkflow 节点)的 description 字段

    Call this tool to get a recipe recommendation. Pass in the following params as a json object:
    * positives - a description of what the user wants to cook. This could be ingredients, flavours, utensils available, number of diners, type of meal etc.
    * negatives - a description of what the user wants to avoid in the recipe. This could be flavours to avoid, allergen considerations, conflicts with theme of meal etc.

    运行提示词 · 来源原文。Qdrant Recommend API 工具(toolWorkflow 节点)的 inputSchema 字段

    {
    "type": "object",
    "properties": {
    	"positive": {
    		"type": "string",
    		"description": "a description of what the user wants to cook. This could be ingredients, flavours, utensils available, number of diners, type of meal etc."
    	},
       "negative": {
        "type": "string",
        "description": "a description of what the user wants to avoid in the recipe. This could be flavours to avoid, allergen considerations, conflicts with theme of meal etc."
      }
    }
    }

可复制提示词

搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限,再按步骤导入 workflow.json 或手动重建节点

这一段是提示词,页面不会在这里插入广告。

你正在搭建一个基于 n8n 的食谱推荐工作流。请按以下顺序确认:1)n8n 实例可用且已配置 mistralCloudApi 和 qdrantApi 凭证;2)Qdrant 中已创建 hello_fresh collection(Cosine, 1024);3)理解工作流分为数据抓取、文档准备、向量存储、SQLite 备份、AI Agent 五个阶段;4)AI Agent 的 systemMessage 和 Recommend API 工具参数已按来源配置;5)HelloFresh 网站结构变化可能导致抓取失效,需人工验证。

先验证凭证和 Qdrant collection,再运行 Test workflow 检查抓取是否成功

来源

Recipe recommendations with Qdrant and Mistral · jimleuk · n8n.io · 2024-07-10

留言与反馈

试过这个方法吗?分享效果、遇到的问题或改进建议。留言审核后公开,请勿填写敏感信息。

正在加载…

    相关用例