search

package
v0.0.0-...-89ea4b1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package search provides an inverted index for fast keyword-based search across AgentOps session and knowledge files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveIndex

func SaveIndex(idx *Index, path string) error

SaveIndex writes the index to a JSONL file (one line per term).

func UpdateIndex

func UpdateIndex(idx *Index, path string) error

UpdateIndex adds or re-indexes a single file in the index. It first removes any existing entries for the path, then re-scans.

Types

type Index

type Index struct {
	// Terms maps each lowercase term to a set of document paths.
	Terms map[string]map[string]bool `json:"-"`
}

Index is an in-memory inverted index mapping lowercase terms to the set of document paths that contain them.

func BuildIndex

func BuildIndex(dir string) (*Index, error)

BuildIndex scans all .md and .jsonl files under dir (recursively) and builds an inverted index from their content.

func LoadIndex

func LoadIndex(path string) (*Index, error)

LoadIndex reads an index from a JSONL file.

func NewIndex

func NewIndex() *Index

NewIndex creates an empty index.

type IndexEntry

type IndexEntry struct {
	Term  string   `json:"term"`
	Paths []string `json:"paths"`
}

IndexEntry is the JSONL-serialised form: one line per term.

type IndexResult

type IndexResult struct {
	Path  string
	Score int // number of query terms matched
}

IndexResult is returned by Search.

func Search(idx *Index, query string, limit int) []IndexResult

Search finds documents matching the query and returns up to limit results sorted by descending score (number of matching query terms).

Jump to

Keyboard shortcuts

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