完整实战:知识感知聊天机器人

📅 2026/7/22 10:31:36
完整实战:知识感知聊天机器人
下面是一个轻量级的 RAG 模式示例——用 ChatMessage.ofUserAugment() 把上下文注入到 Prompt 中import org.noear.solon.ai.chat.ChatModel;import org.noear.solon.ai.chat.ChatResponse;import org.noear.solon.ai.chat.message.ChatMessage;import org.noear.solon.annotation.Component;import org.noear.solon.annotation.Inject;Componentpublic class KnowledgeChatbot {InjectChatModel chatModel;public String answer(String question, String referenceContext) throws Exception { // 将参考上下文与用户问题合并 ChatMessage augmented ChatMessage.ofUserAugment(question, referenceContext); ChatResponse resp chatModel.prompt(augmented) .options(o - o .temperature(0.3) .systemPrompt(你是一个知识渊博的助手。请基于提供的参考资料回答。)) .call(); return resp.getMessage().getContent(); }}这种模式——用上下文增强用户输入再调用模型——正是 Solon AI 中 RAG检索增强生成的基础。下一步ChatModel 只是入口点。Solon AI 还提供工具调用 — 用 ToolMapping 定义 LLM 可调用的 Java 方法Talent 系统 — 可复用的能力模块Agent — ReActAgent 和 TeamAgent 实现多步推理RAG 流水线 — 完整的文档加载、切分、嵌入、检索流程MCP 协议 — 连接 MCP 服务器使用外部工具