search

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package search is workspace search: an index of what a workspace holds (its files, the text of its PDFs and notebooks, its chats, its notes), kept on disk per workspace, brought up to date by scans that read only what changed, and searched by words (SQLite FTS5, ranked by BM25) and by substrings for code (spec_035_search). The engine hands it the sources and says which items may be shown; it knows nothing else of the engine.

Index

Constants

View Source
const (
	ModeKeyword  = "keyword"
	ModeSemantic = "semantic"
	ModeHybrid   = "hybrid"
)

The ways to search: by the words (keyword), by meaning (semantic, with an embedding model), or both fused (hybrid, the default with one).

View Source
const DefaultLimit = 20

DefaultLimit is how many hits a query without a limit returns.

Variables

View Source
var ErrBadDescription = errors.New("the model's description can't be read")

ErrBadDescription is an Enricher's error for a model reply it can't read: the call was made (and paid for), so the item is marked done without a description rather than asked about again at every scan.

View Source
var ErrNoEmbeddings = errors.New("semantic search needs an embedding model (search.embedding_model)")

ErrNoEmbeddings is returned for a semantic search when no embedding model is set.

View Source
var ErrNoTerms = errors.New("nothing to search for")

ErrNoTerms is returned for a query with nothing to search for.

View Source
var ErrSkip = errors.New("not searchable")

ErrSkip is what Read returns for an item that isn't searchable (binary, too large): it's left out, and dropped if it was indexed.

View Source
var ErrUnknownMode = errors.New("unknown search mode (keyword, semantic or hybrid)")

ErrUnknownMode is returned for a mode that isn't one of the three.

Functions

This section is empty.

Types

type Allowed

type Allowed func(source, ref string) bool

Allowed reports whether a source's item may be indexed and shown (a blocked path may not).

type ColumnNote

type ColumnNote struct {
	Name   string `json:"name"`
	Intent string `json:"intent"`
}

ColumnNote is a table column and what it holds ("water temperature in °C"), as a model read it.

type Description

type Description struct {
	Summary string
	Tags    []string
	// Columns are a table's columns and what each holds.
	Columns []ColumnNote
}

Description is what an Enricher wrote of an item.

type Doc

type Doc struct {
	Title    string
	Text     string
	Sections []Section
}

Doc is an item's searchable text, with its title and the sections it falls into (a PDF's pages, a notebook's cells).

type Embedder

type Embedder interface {
	// Model names the embedding model; vectors of another model are
	// thrown away.
	Model() string
	Embed(ctx context.Context, texts []string) ([][]float32, error)
}

Embedder turns texts into vectors: a provider's embedding model, for semantic search (SRCH-50).

type Enricher

type Enricher interface {
	Describe(ctx context.Context, title, text string) (Description, error)
}

Enricher describes a file: a summary and tags a model writes, and for a table what each column holds, for search to find it by what it's about (SRCH-60).

type Hit

type Hit struct {
	Source  string
	Ref     string
	Title   string
	Line    int
	Section string
	Snippet string
	Score   float64
	// Summary and Tags are what a model wrote of the item (SRCH-51), if
	// it has.
	Summary string
	Tags    []string
}

Hit is one item found: where, its best passage and how well it matched. Line is the passage's line in the item's text (1-based); Section labels it (a PDF's page).

type Index

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

Index is one workspace's search index.

func Open

func Open(dir string, sources []Source, allowed Allowed, opts ...Option) (*Index, error)

Open opens (or makes) the index in dir for sources; allowed filters what is indexed and shown. An index of another version is rebuilt.

func (*Index) Close

func (x *Index) Close() error

Close closes the index; a scan running is the caller's to stop first.

func (*Index) Columns

func (x *Index) Columns(ctx context.Context, source, ref string) ([]ColumnNote, error)

Columns is what a model said a table's columns hold (none: not described, or not a table).

func (*Index) Scan

func (x *Index) Scan(ctx context.Context) error

Scan brings the index up to date with every source: changed items are read again, new ones added, gone or no longer allowed ones dropped. Unchanged items (same size and time) aren't read. One scan runs at a time; ctx stops it between items.

func (*Index) Search

func (x *Index) Search(ctx context.Context, q Query) ([]Hit, error)

Search finds the items that best match q: words ranked by BM25, fused with substring matches (for identifiers and paths) by reciprocal rank, the best passage of each item once. Items the index may no longer show are left out.

func (*Index) Sources

func (x *Index) Sources() []string

Sources are the names of the index's sources, in order.

func (*Index) Status

func (x *Index) Status() Status

Status is the index's status now.

type Item

type Item struct {
	Ref      string
	Size     int64
	Modified time.Time
	Hidden   bool
}

Item is one thing a source holds: its reference (a path relative to the workspace, a session's ID), what tells a change, and whether it's hidden (a dotfile, a file git ignores: shown only when asked for).

type Option

type Option func(*Index)

Option changes how Open opens an index.

func WithEmbedder

func WithEmbedder(e Embedder) Option

WithEmbedder adds semantic search: chunks are embedded by e, after each scan, into vectors kept beside the index.

func WithEnricher

func WithEnricher(e Enricher, perDay int, paused func() bool) Option

WithEnricher has e describe up to perDay files and documents a day, after each scan, while paused reports false (no turn runs).

type Query

type Query struct {
	Text    string
	Sources []string
	Limit   int
	Mode    string
	// Hidden includes hidden items (dotfiles, files git ignores).
	Hidden bool
	// Folder keeps the items under one folder (a path relative to the
	// workspace, "/" separated; "" for all): files and documents, since
	// chats and notes aren't in a folder.
	Folder string
}

Query is what to search for: words and "quoted phrases", in which sources (none: all of the index's), and how (Mode).

type Section

type Section struct {
	Line  int
	Label string
}

Section labels the text from Line (1-based) to the next section.

type Source

type Source interface {
	// Name is the source's name in queries and results.
	Name() string
	// List is the source's items as they are now, without their text.
	List(ctx context.Context) ([]Item, error)
	// Read is an item's text; ErrSkip leaves it out of the index.
	Read(ctx context.Context, ref string) (Doc, error)
}

Source is one kind of thing to search: files, documents, chats, notes.

type Status

type Status struct {
	Items    map[string]int
	Scanning bool
	LastScan time.Time
	// EmbeddingModel is the model semantic search uses ("": none);
	// Embedded counts the chunks it has vectors for, and EmbedErr is why
	// the last pass stopped.
	EmbeddingModel string
	Embedded       int
	EmbedErr       string
	// Enriched counts the items with a summary; EnrichErr is why the last
	// pass stopped.
	Enriched  int
	EnrichErr string
	// Unreadable counts items that couldn't be read (they're read again
	// once they change).
	Unreadable int
	Err        string
}

Status is how the index is: items per source, whether a scan runs, and how the last one went.

Jump to

Keyboard shortcuts

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