websearch

package
v0.14.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Package websearch 公开资料检索抽象:接口可插拔,缺省实现 SearXNG 自建实例 (免 API key、零调用成本)。与 knowledge/rag 互补——本包面向外网公开资料。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Title   string `json:"title"`
	URL     string `json:"url"`
	Snippet string `json:"snippet"`
}

Result 单条检索结果。

type Searxng

type Searxng struct {
	BaseURL     string
	Language    string // 缺省 "zh-CN";空串=不传 language 参数
	DefaultTopK int    // AsTool 用;≤0 兜底 5
	HTTP        *http.Client
}

Searxng SearXNG 自建实例客户端(GET /search?format=json——实例 settings.yml 须启用 formats: [html, json])。零 API key、零调用成本;商业后端后续按同 Service 接口接入。

func NewSearxng

func NewSearxng(baseURL string, timeout time.Duration) *Searxng

NewSearxng 构造(timeout 为单次检索上限;≤0 用 10s 兜底)。

func (*Searxng) AsTool

func (s *Searxng) AsTool() tool.BaseTool

AsTool 把检索包成 web_search 内置工具(与 rag.AsTool 同形态)。 AsTool 把检索包成 web_search 工具。

结果拼接前所有攻击者可影响字段过结构化消毒(tools#49、tools#63):检索 结果是半可信外网内容(敌意等级高于仓库内内容),未经消毒拼进编号列表, 字段内嵌换行即可伪造条目与指令。Title 折叠单行、URL 单行化(控制字符转 %XX 可见转义)后再过 fence.EscapeUntrusted——「承重保留原样」由消毒的 内容保持性兑现(中和结构不删内容),不构成豁免消毒的理由。

⚠️ panic 契约(oagentkit/rag#31 同族对齐):schema 反射构造失败时 panic (接口签名无 error 通道,「静态 schema 即编程错误」在此升级为显式 API 契约声明)。

func (*Searxng) Search

func (s *Searxng) Search(ctx context.Context, query string, topK int) ([]Result, error)

Search 实现 Service。HTTP 非 2xx / 响应非 JSON 一律报错——实例未开 formats: [json] 时 /search 返回 HTML,报错形态即「响应解析失败」。

type Service

type Service interface {
	Search(ctx context.Context, query string, topK int) ([]Result, error)
}

Service 检索服务抽象。失败返回 error(调用方按降级收口);无命中返回空切片 + nil error。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL