llmprefix

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package llmprefix implements Anthropic-style contextual retrieval (roadmap Phase D.2): an LLM writes a one-sentence description of each code chunk, which is prepended to the chunk's embed text so the vector carries situating context. Generation is expensive, so results are disk-cached by chunk content hash and a generation failure degrades to no prefix (the caller falls back to the cheap rule-based prefix) rather than failing the build.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(c types.Chunk) string

BuildPrompt is the one-sentence contextual-description prompt for a chunk.

Types

type Cached

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

Cached is a disk-cached LLM prefixer. It keys prefixes by chunk content hash so a rebuild reuses them, and returns "" on any generation error rather than failing the build.

func NewCached

func NewCached(gen Generator, cacheDir string) (*Cached, error)

NewCached returns a Cached prefixer writing its cache under cacheDir (created if absent). A nil generator makes Prefix a no-op ("").

func (*Cached) Prefix

func (p *Cached) Prefix(ctx context.Context, c types.Chunk) string

Prefix returns the cached or freshly-generated one-sentence prefix for c, or "" if generation fails.

type Generator

type Generator interface {
	Generate(ctx context.Context, prompt string) (string, error)
}

Generator produces an LLM completion for a prompt. Injectable so the prefixer is unit-testable without a live model and swappable across backends (ollama, Claude CLI, API).

type OllamaGenerator

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

OllamaGenerator generates contextual prefixes via a local Ollama chat model (POST /api/generate, non-streaming). The default endpoint is overridable with CKV_OLLAMA_ENDPOINT, matching the embedder adapter.

func NewOllamaGenerator

func NewOllamaGenerator(model string) *OllamaGenerator

NewOllamaGenerator builds a generator for the named Ollama model (e.g. "llama3"). Requires `ollama serve` with the model pulled.

func (*OllamaGenerator) Generate

func (g *OllamaGenerator) Generate(ctx context.Context, prompt string) (string, error)

type Prefixer

type Prefixer interface {
	Prefix(ctx context.Context, c types.Chunk) string
}

Prefixer returns a short contextual prefix for a chunk's embed text, or "" when unavailable (the caller then falls back to the rule-based prefix).

Jump to

Keyboard shortcuts

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