Help us shape the future of Go! Take the 2026 Go Developer Survey

semantic

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const DocumentVersion = "1"

Variables

This section is empty.

Functions

func Document

func Document(node graph.Node) string

Document creates stable, source-free semantic input from indexed metadata.

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

type CacheEntry struct {
	Key    CacheKey
	Vector []float32
}

CacheEntry is the validated vector stored for a content-addressed key.

type CacheKey

type CacheKey struct {
	Model           string
	DocumentVersion string
	ContentHash     string
}

CacheKey is the source-free identity of one reusable embedding vector. Model and DocumentVersion are exact, case-sensitive namespaces.

type CandidateRepository

type CandidateRepository interface {
	CandidateNodes(context.Context) ([]graph.Node, error)
}

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

type Embedder interface {
	Model() string
	Embed(context.Context, []string) ([][]float32, error)
}

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 Match

type Match struct {
	Node    graph.Node      `json:"node"`
	Score   float64         `json:"score"`
	Context query.Traversal `json:"context"`
}

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

func (s *Service) Search(ctx context.Context, text string, limit int) (SearchResult, error)

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.

func (*Service) Sync

func (s *Service) Sync(ctx context.Context) (SyncReport, error)

func (*Service) WithBatchSize

func (s *Service) WithBatchSize(size int) *Service

func (*Service) WithForce

func (s *Service) WithForce(force bool) *Service

type Span

type Span struct {
	Name         string `json:"name"`
	Milliseconds int64  `json:"milliseconds"`
}

Span is one measured phase of a reusable-code query.

type SyncReport

type SyncReport struct {
	Model      string `json:"model"`
	Candidates int    `json:"candidates"`
	Updated    int    `json:"updated"`
	Unchanged  int    `json:"unchanged"`
	Removed    int64  `json:"removed"`
}

type Timings

type Timings struct {
	Spans             []Span `json:"spans"`
	TotalMilliseconds int64  `json:"total_milliseconds"`
}

Timings reports phase durations in a fixed, deterministic span order.

Jump to

Keyboard shortcuts

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