Documentation
¶
Index ¶
- Constants
- func Document(node graph.Node) string
- type BudgetReport
- type CacheEntry
- type CacheKey
- type CandidateRepository
- type Coverage
- type Embedder
- type EmbeddingCache
- type Match
- type SearchFilters
- type SearchRequest
- type SearchResult
- type SearchStatus
- type Service
- func (s *Service) Search(ctx context.Context, text string, limit int) (SearchResult, error)
- func (s *Service) SearchWith(ctx context.Context, request SearchRequest) (SearchResult, error)
- func (s *Service) Sync(ctx context.Context) (SyncReport, error)
- func (s *Service) WithBatchSize(size int) *Service
- func (s *Service) WithForce(force bool) *Service
- type Span
- type SyncReport
- type Timings
Constants ¶
const ( // DefaultSearchBudget bounds one reusable-code query. It stays well below // the 300s timeout common MCP clients apply, so an exhausted budget // produces a marked partial response instead of a client-side timeout. DefaultSearchBudget = 45 * time.Second // MaxSearchBudget caps a caller-supplied budget. MaxSearchBudget = 240 * time.Second // DefaultMinimumCoverage is the embedded fraction of current candidate // documents at or above which ranking is reported as trustworthy. DefaultMinimumCoverage = 0.9 )
const DocumentVersion = "1"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BudgetReport ¶
type BudgetReport struct {
Milliseconds int64 `json:"milliseconds"`
Exhausted bool `json:"exhausted"`
}
BudgetReport states the bound that was applied and whether it ran out.
type CacheEntry ¶
CacheEntry is the validated vector stored for a content-addressed key.
type CacheKey ¶
CacheKey is the source-free identity of one reusable embedding vector. Model and DocumentVersion are exact, case-sensitive namespaces.
type CandidateRepository ¶
CandidateRepository is the graph-backed port for semantic candidate selection. Embedding persistence belongs exclusively to EmbeddingCache.
type Coverage ¶
type Coverage struct {
// Candidates is the number of graph candidates after filters.
Candidates int `json:"candidates"`
// Documents is the number of distinct embedding documents those
// candidates reduce to.
Documents int `json:"documents"`
// Embedded is how many documents had a vector available for ranking.
Embedded int `json:"embedded"`
// Missing is how many documents still lack a vector.
Missing int `json:"missing"`
// Backfilled is how many documents this call embedded and cached.
Backfilled int `json:"backfilled"`
// RankedCandidates is how many candidates were scored.
RankedCandidates int `json:"ranked_candidates"`
// ResolvedMatches is how many returned matches carry graph context.
ResolvedMatches int `json:"resolved_matches"`
// Fraction is Embedded/Documents, rounded to four decimals.
Fraction float64 `json:"fraction"`
}
Coverage reports how much of the current candidate set could be ranked. It separates "waiting on embedding-cache backfill" from ranking work.
type Embedder ¶
Embedder is the provider boundary for semantic candidate discovery. Structural graph resolution never depends on this interface.
type EmbeddingCache ¶
type EmbeddingCache interface {
Load(context.Context, []CacheKey) (map[CacheKey][]float32, error)
Store(context.Context, []CacheEntry) error
}
EmbeddingCache is the persistence port for optional semantic vectors. Structural repositories deliberately do not implement this interface.
type SearchFilters ¶
type SearchFilters struct {
Languages []string `json:"languages,omitempty"`
PathPrefixes []string `json:"path_prefixes,omitempty"`
}
SearchFilters echoes the normalized candidate filters back to the caller.
type SearchRequest ¶
type SearchRequest struct {
Query string
Limit int
// Budget bounds the whole query. A non-positive value selects
// DefaultSearchBudget; values above MaxSearchBudget are clamped.
Budget time.Duration
// MinimumCoverage is the embedded fraction required before ranked results
// are reported as anything but StatusWarming. Non-positive selects
// DefaultMinimumCoverage.
MinimumCoverage float64
// Languages restricts candidates to these node languages, compared
// case-insensitively.
Languages []string
// PathPrefixes restricts candidates to nodes whose location path lies
// under one of these repository-relative segment prefixes.
PathPrefixes []string
}
SearchRequest is the bounded form of a reusable-code query. Every field is optional except Query, so an empty request behaves like the historical Search(ctx, text, limit) call with default bounds applied.
type SearchResult ¶
type SearchResult struct {
Query string `json:"query"`
Model string `json:"model"`
Matches []Match `json:"matches"`
// Status is complete, partial, or warming.
Status SearchStatus `json:"status,omitempty"`
// Partial is true whenever Status is not complete.
Partial bool `json:"partial,omitempty"`
// Coverage separates embedding-cache backfill progress from ranking and
// graph-resolution progress.
Coverage Coverage `json:"coverage,omitempty"`
// Timings reports per-phase durations in a fixed span order.
Timings Timings `json:"timings,omitempty"`
// Budget states the applied time bound and whether it ran out.
Budget BudgetReport `json:"budget,omitempty"`
// Filters echoes the normalized candidate filters.
Filters SearchFilters `json:"filters,omitempty"`
// Notes explain every deviation from a complete answer.
Notes []string `json:"notes,omitempty"`
// NextAction is the concrete remedy for a partial or warming answer.
NextAction string `json:"next_action,omitempty"`
}
SearchResult is one bounded reusable-code answer. Status, Partial, and Coverage are the contract for honesty: a caller must never read Matches as the complete ranking unless Status is StatusComplete.
type SearchStatus ¶
type SearchStatus string
SearchStatus names how completely a reusable-code query was answered. Callers must treat anything other than StatusComplete as a bounded, explicitly partial view of the index.
const ( // StatusComplete means every current candidate document was embedded and // ranked, and graph context resolved for every returned match. StatusComplete SearchStatus = "complete" // StatusPartial means ranking or graph resolution stopped early, so the // returned matches are the best bounded answer rather than the full one. StatusPartial SearchStatus = "partial" // StatusWarming means embedding coverage is still too low to rank the // candidate set honestly. Any matches are a preview of a warming cache. StatusWarming SearchStatus = "warming" )
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(candidates CandidateRepository, graphRepository graph.QueryRepository, cache EmbeddingCache, embedder Embedder) *Service
func (*Service) Search ¶
Search ranks candidates for a natural-language description with default bounds. It is the backward-compatible form of SearchWith.
func (*Service) SearchWith ¶
func (s *Service) SearchWith(ctx context.Context, request SearchRequest) (SearchResult, error)
SearchWith answers a reusable-code query inside a time budget.
The query never blocks on a full embedding backfill. Missing documents are embedded in deterministic cache-key order until the backfill share of the budget runs out; ranking then covers exactly the documents that have vectors, and the response states coverage, the applied budget, and per-phase timings. Ordering of ranked matches is unchanged from the unbounded path, so a warm cache returns the same matches it always did.