新增基于 You.com Search API 的联网检索(/v1/websearch + web_search MCP 工具)#44
Open
Emos21 wants to merge 4 commits into
Open
新增基于 You.com Search API 的联网检索(/v1/websearch + web_search MCP 工具)#44Emos21 wants to merge 4 commits into
Emos21 wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue: #43
动机
go-rag 目前的检索能力均基于知识库向量存储,无法获取实时网络信息。本 PR 新增基于 You.com Search API 的联网检索能力,作为 eino
retriever.Retriever的一种实现,与知识库检索互补。纯增量改动,现有向量检索链路完全不受影响。变更内容
server/core/websearch/youcom.go— 实现 einoretriever.Retriever接口(GEThttps://ydc-index.io/v1/search,X-API-Key认证),结果映射为schema.Document(ID=url,Content=标题+描述+摘录片段,MetaData 含 url/title/source),按排名生成递减分数,结果总数按 TopK 截断(与/v1/retriever语义一致)POST /v1/websearch接口 —api/rag/v1/websearch.go+internal/controller/rag/rag_v1_websearch.go,参数风格与/v1/retriever一致(question 必填 / top_k 默认 5)web_search—internal/mcp/websearch.go,与现有retriever工具相同的注册方式(cmd.go一行注册);检索失败时返回友好文本而非协议错误internal/logic/websearch/websearch.go— 惰性初始化(websearch 为可选功能,未配置时不影响进程启动)config_demo.yaml新增websearch.youcom段(apiKey / count / timeout);apiKey 留空时读取环境变量YDC_API_KEY(获取地址 https://you.com/platform/api-keys)YDC_API_KEY时自动跳过)测试方式
接口实测(服务启动后):
实测返回 3 条真实结果(分数递减、附来源 url)。MCP 侧
tools/list可见web_search工具,tools/call实测返回真实网页结果。未配置 Key 时:接口返回明确提示「未配置 You.com API Key,请设置环境变量 YDC_API_KEY 或在配置文件 websearch.youcom.apiKey 中填写」;MCP 工具返回友好文本;现有
/v1/retriever与其他功能不受任何影响(已与干净 main 分支对比验证)。gofmt、go vet、go build ./...均通过;go test ./...与 main 分支基线对比,唯一差异是新增的 websearch 包测试全部通过(main 上 core/rerank 等包的既有失败与本 PR 无关,未改动)。前端npm run build通过(本 PR 未改动前端代码)。备注
Rag.Retrieve的向量检索与 rerank 流程,保持改动最小;如有需要,可作为后续迭代(例如将 websearch 作为可选召回路挂入多路召回)。