Help us shape the future of Go! Take the 2026 Go Developer Survey

websearch

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 11 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 同形态)。

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