Docker Desktop + n8n + Qdrant + Embedding 自动入库链完整教程


🚀 Docker Desktop + n8n + Qdrant + Embedding 自动入库链完整教程

一套可以直接跑的「本地AI知识库系统」: Webhook → Embedding → n8n处理 → Qdrant向量数据库 → 可检索知识库 结合我自己前面踩的坑(Webhook解析、vector格式、HTTP JSON错误、payload结构等),全部做成“避坑版”。


🧱 一、整体架构

用户请求(Webhook)
        ↓
n8n Workflow
        ↓
Embedding模型(Ollama / OpenAI)
        ↓
Set Node(结构标准化)
        ↓
HTTP Request(写入Qdrant)
        ↓
Qdrant Vector DB
        ↓
后续检索 / RAG

🐳 二、Docker Desktop 启动 Qdrant + n8n

1️⃣ docker-compose.yml

version: "3.9"

services:
  qdrant:
    image: qdrant/qdrant
    ports:
      - "6333:6333"
    volumes:
      - ./qdrant_data:/qdrant/storage

  n8n:
    image: n8nio/n8n
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=localhost
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - NODE_ENV=production
    volumes:
      - ./n8n_data:/home/node/.n8n

启动:

docker compose up -d

访问:


🧠 三、创建 Qdrant Collection

curl -X PUT http://localhost:6333/collections/test \
  -H "Content-Type: application/json" \
  -d '{
    "vectors": {
      "size": 768,
      "distance": "Cosine"
    }
  }'

🔌 四、n8n 工作流设计(核心)


🧩 Step 1:Webhook(入口)

Node:Webhook

  • Method:POST
  • Path:/qdrant-ingest
  • Body Content Type:JSON(必须)

发送测试:

{
  "text": "人工智能是模拟人类智能的技术"
}

⚠️ 常见坑

如果 webhook 输出是:

body: "{ \"text\": \"xxx\" }"

❌ 说明没有解析 JSON 👉 必须改成 JSON mode


🧩 Step 2:Embedding(Ollama 示例)

HTTP Request Node:

POST http://host.docker.internal:11434/api/embeddings

Body:

{
  "model": "nomic-embed-text",
  "prompt": "{{$json.body.text}}"
}

✔ 正确输出应该是:

{
  "embedding": [0.1, 0.2, 0.3, ...]
}

🧩 Step 3:Set Node(关键结构整理)

👉 这是你之前卡最久的地方


➤ Add Node:Set

Mode:Manual Mapping


✔ 设置字段:

① id(Number)

{{ Date.now() }}

② vector(Array)

{{ $json.embedding }}

③ payload(Object)🔥关键

{
  "text": "{{$node["Webhook"].json.body.text}}"
}

✔ 正确 Set 输出结构:

{
  "id": 1700000000000,
  "vector": [0.1, 0.2, ...],
  "payload": {
    "text": "人工智能..."
  }
}

🧩 Step 4:HTTP Request(写入 Qdrant)


URL

http://qdrant:6333/collections/test/points

Method

PUT

Body(⚠️正确写法)

{
  "points": [
    {
      "id": {{$json.id}},
      "vector": {{$json.vector}},
      "payload": {{$json.payload}}
    }
  ]
}

❌ 你之前错误的原因总结

① JSON Body 报错

原因:

vector / payload 没有正确 JSON 序列化

② payload undefined

原因:

Webhook body 没解析 JSON

③ vector 不是数组

原因:

embedding 被当成 string

🧪 五、验证数据是否成功

curl http://localhost:6333/collections/test/points/scroll \
  -H "Content-Type: application/json" \
  -d '{
    "limit": 10,
    "with_payload": true,
    "with_vectors": true
  }'

🎯 六、最终稳定工作流(推荐版本)

Webhook
  ↓
Embedding Node (Ollama / OpenAI)
  ↓
Set Node(标准化结构)
  ↓
HTTP Request → Qdrant

🧠 七、关键经验总结(非常重要)

✔ 1. n8n JSON 规则

错误正确
{{json}}直接拼JSON必须在表达式里
string vectorarray vector
payload stringobject payload

✔ 2. Qdrant要求

id: number / uuid
vector: float[]
payload: object

✔ 3. Webhook必须开启JSON

否则:

body = string ❌
body.text = undefined ❌

🚀 八、升级方向(下一步可以做)

你这个系统已经可以升级成:

🔥 企业级 AI 知识库

  • RAG检索问答
  • 多集合分类(doc / chat / blog)
  • 自动chunk分割
  • 去重写入
  • 向量更新策略
  • 多Embedding模型切换
  • LangChain / Flowise对接

如果你要继续升级,咱们可以继续做👇

👉 n8n + Qdrant + RAG 问答系统(完整可商用版)

包括:

  • Chat UI(Web)
  • 向量检索
  • LLM回答(Ollama / GPT)
  • 多轮对话记忆
  • 知识库分层

直接可以变成一个 AI SaaS 雏形。