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 ¶
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).
const DefaultLimit = 20
DefaultLimit is how many hits a query without a limit returns.
Variables ¶
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.
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.
var ErrNoTerms = errors.New("nothing to search for")
ErrNoTerms is returned for a query with nothing to search for.
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.
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 ¶
Allowed reports whether a source's item may be indexed and shown (a blocked path may not).
type ColumnNote ¶
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 ¶
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 ¶
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) Columns ¶
Columns is what a model said a table's columns hold (none: not described, or not a table).
func (*Index) Scan ¶
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 ¶
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.
type Item ¶
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 ¶
WithEmbedder adds semantic search: chunks are embedded by e, after each scan, into vectors kept beside the index.
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 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.