Documentation
¶
Overview ¶
Package search runs a semantic query against the index: embed the query, cosine-rank it against every stored chunk, and return the top matches. At personal-vault scale a brute-force scan in memory is well under a millisecond, so there is no ANN index — just a sort.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChunkSource ¶
ChunkSource is the read side of the index that search needs. *index.Store satisfies it; tests supply a fake so search runs without a database.
type DupeOptions ¶
type DupeOptions struct {
MinScore float64 // report pairs at or above this cosine value
Limit int // max pairs to return; <= 0 means no cap
PathPrefix string // restrict to files under this rel-path prefix
Exclude []string // drop files under any of these rel-path prefixes
WithinFile bool // also report pairs from the same file (default: cross-file only)
}
DupeOptions tunes a near-duplicate scan.
type Embedder ¶
Embedder turns the query text into a vector. Injected so search runs without the ONNX runtime; production passes embed.Get.
type Hit ¶
type Hit struct {
RelPath string `json:"path"`
Line int `json:"line"`
Heading string `json:"heading,omitempty"`
Variant string `json:"variant"`
Key string `json:"key"`
Score float64 `json:"score"`
Text string `json:"text"`
}
Hit is one ranked result.
type Kind ¶
type Kind int
Kind narrows a search to one class of indexed content. Docs and Code partition the index: markdown is docs, every other indexed language is code. For a narrower cut than that one bit, see Options.Langs.
type Options ¶
type Options struct {
Limit int // max hits to return; <= 0 means no cap
PathPrefix string // restrict to files under this rel-path prefix
MinScore float64 // drop hits scoring below this cosine value
Collapse bool // keep only the best-scoring chunk per file
Kind Kind // restrict to docs or code; KindAny searches both
// Langs restricts results to these canonical language names (see
// chunk.NormalizeLanguage). Empty means every language. This is a finer
// cut than Kind: "code" is one bit, but with eighteen languages indexed
// the useful question is usually "the Python one" or "the manifests".
Langs []string
}
Options tunes a query.
type Pair ¶
Pair is two chunks found to be near-duplicates, ordered so A sorts before B (by rel-path then key) for a stable presentation.
func Duplicates ¶
func Duplicates(src ChunkSource, opts DupeOptions) ([]Pair, error)
Duplicates scans the index for pairs of chunks whose cosine similarity is at or above opts.MinScore — near-duplicate sections that likely encode redundant docs or guidance. By default only cross-file pairs are reported (set WithinFile to include repetition inside one file). Vectors from the embedder are L2-normalized, so this is an all-pairs dot product; at personal-vault scale the O(n²) scan is well under a second.