你好,我正在構建一個工作流來抓取 WordPress 網站內容,並將其存儲在向量數據庫中,以便稍後可以使用該數據來餵送 AI 代理。
描述問題/錯誤/問題
我已經將數據分塊,並且可以在 Hugging Face 的幫助下準備用於嵌入。一旦數據被嵌入,它會以數組形式返回數據,但我需要將響應追加到現有的元數據對象中。
錯誤信息是什麼(如果有的話)?
請分享你的工作流
Data Chunk Node:
{
"nodes": [
{
"parameters": {
"jsCode": "function chunkText(text, size = 1200, overlap = 150) {\n const chunks = [];\n let start = 0;\n\n while (start < text.length) {\n const end = Math.min(start + size, text.length);\n const chunk = text.slice(start, end).trim();\n\n if (chunk.length > 0) {\n chunks.push(chunk);\n }\n\n start += size - overlap;\n }\n\n return chunks;\n}\n\n\nconst items = $input.all();\n\nlet output = [];\n\nfor (const item of items) {\n\n const input = item.json;\n\n const text = input.clean_text || '';\n\n if (!text) {\n continue;\n }\n\n const chunks = chunkText(text);\n\n chunks.forEach((chunk, index) => {\n\n output.push({\n json: {\n id: input.id,\n title: input.title,\n slug: input.slug,\n link: input.link,\n modified: input.modified || '',\n source_type: input.source_type || 'page',\n\n chunk_index: index,\n\n chunk_text: chunk,\n\n // 稍後我們將使用此項進行 upsert/update\n chunk_hash: `${input.id}-${index}-${chunk.length}`\n }\n });\n\n });\n}\n\nreturn output;"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
832,
0
],
"id": "2984be2c-5f97-4833-8d5e-a0912be70559",
"name": "ChunkText"
}
],
"connections": {
"ChunkText": {
"main": [
[]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "a12d2939883b6ee4645287d26116bd7830ea910b3e2205baee32d9bb5d782014"
}
}
Hugging Face Node:
{
"nodes": [
{
"parameters": {
"method": "POST",
"url": "https://router.huggingface.co/hf-inference/models/BAAI/bge-small-en-v1.5",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer <<API TOKEN>>"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{\n{\n inputs: $json.chunk_text\n}\n}}",
"options": {
"response": {
"response": {
"responseFormat": "json"
}
}
}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.4,
"position": [
992,
-144
],
"id": "2f3d7b70-454c-4e1d-8345-33ef8e3b047c",
"name": "Hugging Face API"
}
],
"connections": {
"Hugging Face API": {
"main": [
[]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "a12d2939883b6ee4645287d26116bd7830ea910b3e2205baee32d9bb5d782014"
}
}
分享最後一個節點返回的輸出
Hugging Face 模型的響應:
[
-0.03779905289411545,
-0.027235977351665497,
0.04070237651467323,
0.02413654699921608,
-0.04879286512732506,
-0.016459722071886063,
-0.0015258010243996978,
0.07087898999452591,
-0.03721754252910614,
0.019904209300875664,
0.022374162450432777,
-0.05740947648882866,
-0.017154762521386147,
0.04529924318194389,
0.0001327882637269795,
-0.023566097021102905,
0.008483237586915493,
0.013999130576848984,
-0.057878654450178146,
0.0066631208173930645,
0.034953076392412186,
-0.02018037624657154,
-0.013172738254070282,
-0.030672265216708183,
0.007248119916766882
]
向量數據庫架構:
create table public.site_chunks (
id bigserial not null,
url text not null,
title text null,
chunk_text text not null,
chunk_hash text not null,
source_type text not null,
modified_at timestamp with time zone null,
created_at timestamp with time zone not null default now(),
updated_at timestamp with time zone not null default now(),
embedding public.vector null,
constraint site_chunks_pkey primary key (id)
) TABLESPACE pg_default;
create unique INDEX IF not exists site_chunks_url_hash_idx on public.site_chunks using btree (url, chunk_hash) TABLESPACE pg_default;
create index IF not exists site_chunks_source_type_idx on public.site_chunks using btree (source_type) TABLESPACE pg_default;
create index IF not exists site_chunks_modified_at_idx on public.site_chunks using btree (modified_at) TABLESPACE pg_default;
注意:我提供了單個數組輸出,但我有 53 個文本塊,我將進行嵌入,API 返回總共 20352 個項目,所以我不確定如何將所有這些數據與我現有的記錄進行映射。
樣本輸入:
[
{
“id”: 1383,
“title”: “blog”,
“url”: “TEST”,
“content”: “”,
“modified”: “2026-07-29T23:06:08”,
“source_type”: “page”,
“clean_text”: “”
},
{
“id”: 1222,
“title”: “Laser Dentistry”,
“slug”: “”,
“link”: “”,
“date”: “”,
“clean_text”: “Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum”
} ]
注意:我在主體參數中發送 clean_text 以進行嵌入。
預期輸出:
{ "url": "", "title": "Laser Dentistry", "chunk_text": "LASER DENTISTRY...", "chunk_hash": "1222-0-1200", "source_type": "page", "modified_at": null, "embedding": "[-0.037799,-0.027235,0.040702,...]" }
有關你的 n8n 設置的信息
- n8n 版本:
- 數據庫(預設:SQLite):
- n8n EXECUTIONS_PROCESS 設置(預設:own、main):
- 通過以下方式運行 n8n(Docker、npm、n8n cloud、桌面應用):Azure App Service
- 操作系統:Linux