enricher

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package enricher implements the Context Enricher — Feature 2 of synapses-intelligence.

During a get_context call, the enricher runs two passes:

  1. Deterministic pass: SDLC phase (file path regex), complexity score (fanin+fanout), dependency names — always returns in <5ms, no LLM required.
  2. LLM pass (optional): 2-sentence insight + concerns — skipped when Ollama is unavailable, disabled, or slow. Deterministic fields are always returned.

This ensures context packets are never fully empty even when the LLM is down.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enricher

type Enricher struct {
	// contains filtered or unexported fields
}

Enricher adds semantic context to get_context responses.

func New

func New(client llm.LLMClient, st *store.Store, timeout time.Duration) *Enricher

New creates an Enricher.

func (*Enricher) Enrich

func (e *Enricher) Enrich(ctx context.Context, req Request) (Response, error)

Enrich generates context enrichment for the root entity.

The deterministic pass always runs first and returns Phase + ComplexityScore in <5ms regardless of LLM availability. The LLM pass (Insight + Concerns) is attempted after and its results merged in — but the response is never empty even when the LLM is unavailable or times out.

func (*Enricher) Stats

func (e *Enricher) Stats() Stats

Stats returns a snapshot of the enricher's execution path counters. Safe to call concurrently.

func (*Enricher) WithSILMode

func (e *Enricher) WithSILMode() *Enricher

WithSILMode configures the enricher to build "Graph: {json}" prompts suited to the fine-tuned SIL model rather than the generic JSON-output Ollama prompt. Call this when brain config backend == "local".

type Request

type Request struct {
	RootID       string
	RootName     string
	RootType     string
	RootFile     string // file path of the root entity; used for domain detection + phase inference
	CalleeNames  []string
	CallerNames  []string
	RelatedNames []string
	TaskContext  string
	// Topology signals used by the deterministic pass.
	// FanIn is the total caller count (may exceed len(CallerNames) when capped).
	FanIn int
}

Request carries the carved subgraph data for enrichment.

type Response

type Response struct {
	RootSummary string // populated by the SIL model (ROOT_SUMMARY: label)
	Insight     string
	Concerns    []string
	LLMUsed     bool // true when the LLM was called; false on cache hit or deterministic-only path

	// Deterministic fields — always populated, no LLM required.
	Phase            string  // SDLC phase inferred from file path ("entry_point", "persistence", "test", "api", "core", "")
	ComplexityScore  float64 // (fanin + fanout) * (1 + fanout/10.0); 0 when topology unknown
	DeterministicHit bool    // true when deterministic pass ran (even if LLM was also called)
}

Response is added to the get_context output.

type Stats

type Stats struct {
	DeterministicHits uint64 // calls where deterministic pass ran (always ≥ OllamaCalls)
	OllamaCalls       uint64 // calls where the LLM was invoked (subset of DeterministicHits)
	OllamaFailures    uint64 // LLM invocations that returned an error
	ParseFailures     uint64 // LLM responses that failed to parse
}

Stats holds observable counters for the enricher's two execution paths.

Jump to

Keyboard shortcuts

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