Documentation
¶
Overview ¶
Package retrieve implements the token-minimal retrieval funnel: gate → scope filter + shadowing → trigger pinning → (BM25 ‖ embed+cosine) → RRF fuse × utility → floor. The embedding arm is optional at every level: nil Embedder, open breaker, or a dead Ollama all collapse the fusion to BM25-only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtendLexicon ¶
func ExtendLexicon(acks, stops []string)
ExtendLexicon adds user-configured ack phrases and stopwords (from config.yaml) to the built-in packs. Called once at startup before any Gate call; not safe to call concurrently with retrieval.
func FTSExpr ¶
FTSExpr builds a safe FTS5 MATCH expression from raw prompt text. Prompt text is hostile input to FTS5 (quotes and operators crash MATCH — 14.42): we extract bare folded terms and OR-join them, each double-quoted. Returns "" when nothing searchable remains.
Types ¶
type Candidate ¶
type Candidate struct {
Card store.StoredCard
Score float64
Pinned bool
Vec []float32
}
Candidate is one card that survived the funnel, best first. Vec is the card's embedding when the cosine arm ran (nil otherwise) — the packer uses it for MMR dedup.
type GateDecision ¶
type GateDecision struct {
Skip bool
Reason string // ack | short | slash | paste | novelty | "" (retrieve)
Query string // prompt possibly truncated for huge pastes
}
GateDecision says whether retrieval should run at all. The gate is the biggest token saver: 40-60% of real prompts are acks, follow-ups, or slash commands that need zero new context.
func Gate ¶
func Gate(prompt, lastPrompt string) GateDecision
Gate decides skip-vs-retrieve for one prompt. lastPrompt is the previous prompt in this session ("" if none) for the novelty check.
type Retriever ¶
type Retriever struct {
Store *store.Store
Embedder embed.Embedder
Model string // embedding model tag; vectors from other models are stale
}
Retriever runs the funnel against a store. Embedder nil ⇒ BM25-only.
type Scope ¶
type Scope struct {
Repo string // "" outside git
Branch string
Langs []string
Allowed map[string]bool
}
Scope is the deterministic routing context for one prompt: which card scopes are candidates and their precedence boosts. Costs a few stats and small file reads — no exec, no LLM.
func DetectScope ¶
DetectScope resolves cwd → scope chain. Never fails: worst case is global + dir:<hash>.