search

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BM25

type BM25 struct {
	// contains filtered or unexported fields
}

BM25 实现 BM25 搜索算法 BM25 (Best Matching 25) 是一种经典的文本相关性排序算法

func NewBM25

func NewBM25(k1, b float64) *BM25

NewBM25 创建 BM25 搜索引擎 k1: 词频饱和参数 (默认 1.5) b: 文档长度归一化参数 (默认 0.75)

func NewBM25WithDefaults

func NewBM25WithDefaults() *BM25

NewBM25WithDefaults 使用默认参数创建 BM25 搜索引擎

func (*BM25) AddDocument

func (bm *BM25) AddDocument(doc Document)

AddDocument 添加单个文档到索引

func (*BM25) AddDocuments

func (bm *BM25) AddDocuments(docs []Document)

AddDocuments 批量添加文档

func (*BM25) Clear

func (bm *BM25) Clear()

Clear 清空索引

func (*BM25) DocumentCount

func (bm *BM25) DocumentCount() int

DocumentCount 返回索引中的文档数量

func (*BM25) GetDocument

func (bm *BM25) GetDocument(id string) *Document

GetDocument 根据 ID 获取文档

func (*BM25) RemoveDocument

func (bm *BM25) RemoveDocument(id string) bool

RemoveDocument 从索引中移除文档 注意:这个操作需要重建索引,性能较低

func (*BM25) Search

func (bm *BM25) Search(query string, topK int) []SearchResult

Search 搜索文档 返回按相关性排序的结果

func (*BM25) UpdateDocument

func (bm *BM25) UpdateDocument(doc Document) bool

UpdateDocument 更新文档

type Document

type Document struct {
	ID       string         // 文档唯一标识
	Content  string         // 文档内容
	Metadata map[string]any // 附加元数据
}

Document 可搜索的文档

type SearchResult

type SearchResult struct {
	Document Document
	Score    float64
	Rank     int
}

SearchResult 搜索结果

type ToolIndex

type ToolIndex struct {
	// contains filtered or unexported fields
}

ToolIndex 工具索引系统 使用 BM25 算法对工具进行索引和搜索

func NewToolIndex

func NewToolIndex() *ToolIndex

NewToolIndex 创建工具索引

func (*ToolIndex) Clear

func (ti *ToolIndex) Clear()

Clear 清空索引

func (*ToolIndex) Count

func (ti *ToolIndex) Count() int

Count 返回索引中的工具数量

func (*ToolIndex) Export

func (ti *ToolIndex) Export() ([]byte, error)

Export 导出索引为 JSON

func (*ToolIndex) GetActiveTools

func (ti *ToolIndex) GetActiveTools() []ToolIndexEntry

GetActiveTools 获取所有活跃的工具(非延迟加载)

func (*ToolIndex) GetAllTools

func (ti *ToolIndex) GetAllTools() []ToolIndexEntry

GetAllTools 获取所有工具条目

func (*ToolIndex) GetDeferredTools

func (ti *ToolIndex) GetDeferredTools() []ToolIndexEntry

GetDeferredTools 获取所有延迟加载的工具

func (*ToolIndex) GetTool

func (ti *ToolIndex) GetTool(name string) *ToolIndexEntry

GetTool 获取工具条目

func (*ToolIndex) Import

func (ti *ToolIndex) Import(data []byte) error

Import 从 JSON 导入索引

func (*ToolIndex) IndexTool

func (ti *ToolIndex) IndexTool(tool tools.Tool, source string, deferred bool) error

IndexTool 索引单个工具

func (*ToolIndex) IndexToolEntry

func (ti *ToolIndex) IndexToolEntry(entry ToolIndexEntry) error

IndexToolEntry 直接索引条目(用于 MCP 延迟加载的工具)

func (*ToolIndex) RemoveTool

func (ti *ToolIndex) RemoveTool(name string) bool

RemoveTool 从索引中移除工具

func (*ToolIndex) Search

func (ti *ToolIndex) Search(query string, topK int) []ToolSearchResult

Search 搜索工具

func (*ToolIndex) SearchByCategory

func (ti *ToolIndex) SearchByCategory(category string) []ToolIndexEntry

SearchByCategory 按分类搜索

type ToolIndexEntry

type ToolIndexEntry struct {
	Name        string              `json:"name"`
	Description string              `json:"description"`
	InputSchema map[string]any      `json:"input_schema"`
	Category    string              `json:"category,omitempty"`
	Keywords    []string            `json:"keywords,omitempty"`
	Examples    []tools.ToolExample `json:"examples,omitempty"`
	Deferred    bool                `json:"deferred"`
	Source      string              `json:"source"` // "builtin", "mcp", "custom"
	Metadata    map[string]any      `json:"metadata,omitempty"`
}

ToolIndexEntry 工具索引条目

type ToolSearchResult

type ToolSearchResult struct {
	Entry    ToolIndexEntry `json:"entry"`
	Score    float64        `json:"score"`
	Rank     int            `json:"rank"`
	Snippets []string       `json:"snippets,omitempty"` // 匹配的文本片段
}

ToolSearchResult 工具搜索结果

Jump to

Keyboard shortcuts

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