FlowiseAI - LlamaIndex / 工具 / API 集成详解
学习日期:2026-05-07
文档来源:https://docs.flowiseai.com/integrations
一、LlamaIndex 集成
LlamaIndex 是一个用于 LLM 应用的数据框架,专注于摄取、结构化和访问私有或特定领域数据。相比 LangChain,LlamaIndex 在高级检索技术方面更强大,特别适合设计 RAG 应用。
Flowise 为 LlamaIndex 提供可视化界面,将节点分组排列,使工作流构建更直观。
LlamaIndex 组件分类
| 组件 | 说明 |
|---|---|
| Agents | 自主执行任务的智能体 |
| Chat Models | 对话模型 |
| Embeddings | 文本向量化 |
| Engine | 查询引擎(核心) |
| Response Synthesizer | 响应合成器 |
| Tools | 工具函数 |
| Vector Stores | 向量数据库 |
二、Agents(智能体)
LlamaIndex Agent 类型
| Agent | 说明 |
|---|---|
| OpenAI Tool Agent | 使用 OpenAI Function Calling 选择工具 |
| Anthropic Tool Agent | 使用 Anthropic Claude 工具调用 |
Agent 核心概念
语言模型本身不能执行动作——它们只输出文本。
Agent 是使用 LLM 作为推理引擎来决定:
- 应该采取什么行动
- 这些行动的输入应该是什么
- 结果反馈给 Agent,决定是否需要更多行动或完成
三、Engine(引擎)
Engine 是 LlamaIndex 中处理信息处理和用户交互的核心组件。
Engine 类型
| Engine | 说明 | 适用场景 |
|---|---|---|
| Query Engine | 查询引擎 | 单一知识库问答 |
| Simple Chat Engine | 简单对话引擎 | 基础聊天 |
| Context Chat Engine | 上下文对话引擎 | 带记忆的聊天 |
| Sub-Question Query Engine | 子问题查询引擎 | 复杂问题分解查询 |
Query Engine
处理用户查询并返回响应的核心引擎,支持从向量存储中检索相关文档。
Context Chat Engine
在对话过程中保持上下文,支持多轮对话,适合需要记住之前对话内容的场景。
Sub-Question Query Engine
将复杂问题分解为多个子问题,分别查询后综合回答。适合处理需要多方面信息的问题。
四、Response Synthesizer(响应合成器)
将检索到的多个文档片段合成为最终答案的组件。支持不同的合成策略:
- 简单拼接
- 按相关性排序
- LLM 二次处理
五、Tools(工具)
LlamaIndex 的工具与 LangChain 类似,允许 Agent 与外部世界交互。
六、LiteLLM Proxy 集成
LiteLLM Proxy 允许 Flowise:
- 负载均衡 Azure OpenAI / LLM 端点
- 调用 100+ 种 LLM(统一 OpenAI 格式)
- 使用虚拟 Key 设置预算、速率限制和用量追踪
LiteLLM + Flowise 配置步骤
Step 1:在 LiteLLM config.yaml 中定义模型
model_list:
- model_name: gpt-4
litellm_params:
model: azure/chatgpt-v-2
api_base: https://openai-gpt-4-test-v-1.openai.azure.com/
api_version: "2023-05-15"
api_key:
- model_name: gpt-4
litellm_params:
model: azure/gpt-4
api_key:
api_base: https://openai-gpt-4-test-v-2.openai.azure.com/Step 2:启动 LiteLLM Proxy
docker run \
-v $(pwd)/litellm_config.yaml:/app/config.yaml \
-p 4000:4000 \
ghcr.io/berriai/litellm:main-latest \
--config /app/config.yaml --detailed_debugStep 3:在 Flowise 中使用
- 使用标准 OpenAI 节点(不是 Azure OpenAI 节点)
BasePath设置为http://localhost:4000- 添加 Header:
Authorization: Bearer <your-litellm-master-key>
七、Utilities(实用工具)
开发工具,用于在 Flowise 中实现自定义逻辑。
工具列表
| 工具 | 说明 |
|---|---|
| Custom JS Function | 执行自定义 JavaScript 代码 |
| Set/Get Variable | 设置和获取变量 |
| If Else | 条件分支逻辑 |
| Sticky Note | 添加注释和文档 |
Custom JS Function
允许编写自定义 JavaScript 逻辑,扩展 Flowise 的功能边界。
Set/Get Variable
在 Flowise 流程中存储和读取变量,用于:
- 跨节点传递数据
- 缓存中间结果
- 实现条件逻辑
If Else
条件分支节点,根据条件执行不同路径。
Variable 语法
在任意节点的文本输入中使用:
{{$vars.<variable-name>}}在 Function 节点中使用:
const value = $vars.character;八、API 参考
Flowise 提供完整的 REST API,支持编程方式管理 Chatflow。
核心端点
| 方法 | 端点 | 说明 |
|---|---|---|
POST | /api/v1/prediction/{chatflowId} | 执行预测 |
GET | /api/v1/chatmessage/{chatflowId} | 获取聊天历史 |
DELETE | /api/v1/chatmessage/{chatflowId} | 删除会话 |
GET | /api/v1/chatflows | 列出所有 Chatflow |
POST | /api/v1/chatflows | 创建 Chatflow |
GET | /api/v1/chatflows/{id} | 获取 Chatflow 详情 |
PUT | /api/v1/chatflows/{id} | 更新 Chatflow |
DELETE | /api/v1/chatflows/{id} | 删除 Chatflow |
POST | /api/v1/vector/upsert | 上传文档到向量库 |
POST | /api/v1/attachments/upload | 上传附件 |
GET | /api/v1/variables | 获取变量列表 |
POST | /api/v1/variables | 创建变量 |
PUT | /api/v1/variables/{id} | 更新变量 |
DELETE | /api/v1/variables/{id} | 删除变量 |
POST | /api/v1/tools | 创建工具 |
GET | /api/v1/tools | 获取工具列表 |
GET | /api/v1/assistants | 获取助手列表 |
POST | /api/v1/assistants | 创建助手 |
POST | /api/v1/feedback | 提交反馈 |
GET | /api/v1/ping | 健康检查 |
认证方式
API Key 认证:
Authorization: Bearer <your-api-key>Python / TypeScript SDK
Python:
pip install flowise
from flowise import Flowise, PredictionData
client = Flowise()
completion = client.create_prediction(
PredictionData(
chatflowId="<flow-id>",
question="Hello world!",
streaming=True
)
)
for chunk in completion:
print(chunk)TypeScript:
npm install flowise-sdk
import { FlowiseClient } from 'flowise-sdk'
const client = new FlowiseClient({ baseUrl: 'http://localhost:3000' });
const prediction = await client.createPrediction({
chatflowId: '<flow-id>',
question: 'What is the capital of France?',
streaming: true,
});
for await (const chunk of prediction) {
console.log(chunk);
}九、Streaming(流式响应)
Token 以 Server-Sent Events (SSE) 格式逐个发送。
事件类型
| 事件 | 说明 |
|---|---|
start | 流开始 |
token | 新 Token 输出 |
error | 错误发生 |
end | 流结束 |
metadata | 元数据(chatId、messageId 等) |
sourceDocuments | 返回来源文档 |
usedTools | 使用了的工具 |
cURL 示例
curl https://localhost:3000/api/v1/predictions/{flow-id} \
-H "Content-Type: application/json" \
-d '{
"question": "Hello world!",
"streaming": true
}'SSE 格式
event: token
data: Once upon a time...十、Web Embed(嵌入聊天组件)
将聊天窗口嵌入到任意网站。
基础嵌入
<script type="module">
import Chatbot from 'https://cdn.jsdelivr.net/npm/flowise-embed/dist/web.js';
Chatbot.init({
chatflowid: 'your-chatflowid-here',
apiHost: 'your-apihost-here',
})
</script>指定版本
<script type="module">
import Chatbot from 'https://cdn.jsdelivr.net/npm/flowise-embed@<version>/dist/web.js';
Chatbot.init({ chatflowid: '...', apiHost: '...' })
</script>Chatflow Config(覆盖配置)
Chatbot.init({
chatflowid: '...',
apiHost: '...',
chatflowConfig: {
"sessionId": "123",
"returnSourceDocuments": true
}
})Observer(观察者模式)
Chatbot.init({
chatflowid: '...',
apiHost: '...',
observersConfig: {
observeUserInput: (userInput) => { console.log({ userInput }); },
observeMessages: (messages) => { console.log({ messages }); },
observeLoading: (loading) => { console.log({ loading }); },
}
})Theme(主题配置)
完整的 UI 定制选项:
Chatbot.init({
chatflowid: '...',
apiHost: '...',
theme: {
button: {
backgroundColor: '#3B81F6',
right: 20,
bottom: 20,
size: 48,
dragAndDrop: true,
autoWindowOpen: { autoOpen: true, openDelay: 2 }
},
tooltip: {
showTooltip: true,
tooltipMessage: 'Hi There 👋!'
},
chatWindow: {
title: 'Flowise Bot',
titleAvatarSrc: 'https://...',
welcomeMessage: 'Hello!',
height: 700,
width: 400,
backgroundColor: '#ffffff',
botMessage: { backgroundColor: '#f7f8ff', textColor: '#303235' },
userMessage: { backgroundColor: '#3B81F6', textColor: '#ffffff' },
textInput: { placeholder: 'Type your question', maxChars: 50 }
}
}
})Custom CSS
Chatbot.init({
chatflowid: '...',
apiHost: '...',
theme: {
customCSS: `
/* Your custom CSS */
.bot-message { border-radius: 20px !important; }
`
}
})修复 CORS 问题
部署时如果遇到 CORS 错误:
CORS_ORIGINS=*
IFRAME_ORIGINS=*十一、MCP(Model Context Protocol)
MCP 是一种让 AI 模型与外部工具和数据源连接的协议标准。
Flowise MCP 支持
- 连接外部 MCP 服务器
- 安全验证(默认启用)
- 支持
stdio和SSE两种协议 - 命令白名单保护
- 参数验证和注入防护
MCP 环境变量
| 变量 | 说明 |
|---|---|
MCP_SERVER_URL | MCP 服务器地址 |
MCP_SECRET_KEY | 认证密钥 |
CUSTOM_MCP_SECURITY_CHECK | 安全验证开关 |
CUSTOM_MCP_PROTOCOL | 通信协议 |
十二、Record Managers(记录管理器)
用于追踪已索引文档,防止向量库中重复插入 embedding。
工作原理
- 文档分块时,每个块通过 SHA-1 算法生成哈希
- 哈希存储在 Record Manager 中
- 如果哈希已存在,跳过 embedding 和插入
三种清理模式
| 模式 | 说明 |
|---|---|
| Incremental | 仅删除当前批次中明确要删除的文档,保留其他文档 |
| Full | 自动删除所有不在当前批次中的向量 embedding |
| None | 不执行任何清理 |
支持的数据库
- SQLite
- MySQL
- PostgreSQL
十三、Moderation(内容审核)
对输入/输出内容进行安全检查。
| 审核类型 | 说明 |
|---|---|
| OpenAI Moderation | 使用 OpenAI 官方审核 API |
| Simple Prompt Moderation | 自定义提示词规则审核 |
十四、Output Parsers(输出解析器)
将 LLM 输出转换为结构化格式。
| Parser | 说明 |
|---|---|
| CSV Output Parser | CSV 格式 |
| Custom List Output Parser | 自定义列表 |
| Structured Output Parser | 结构化 JSON |
| Advanced Structured Output Parser | 高级结构化(支持嵌套) |
十五、Quick Reference 快速查询表
场景 → 使用的引擎/组件
| 场景 | 使用组件 |
|---|---|
| 简单知识问答 | Query Engine + Vector Store |
| 多轮对话 | Context Chat Engine |
| 复杂问题分解 | Sub-Question Query Engine |
| Agent 自主任务 | OpenAI Tool Agent / Anthropic Tool Agent |
| 统一调用多模型 | LiteLLM Proxy |
| 网站嵌入聊天 | Web Embed + Theme 配置 |
| 结构化数据输出 | Structured Output Parser |
| 内容安全审核 | OpenAI Moderation |
| 文档去重索引 | Record Manager + Vector Store |