Documentation
¶
Overview ¶
Package research implements code-research: multi-signal retrieval that combines keyword (BM25F), semantic (vector embeddings), import-DAG graph expansion, and token-budget pruning to produce a compact, LLM-ready context from a repository.
Pipeline: seeds(BM25F+embed+RRF) → DAG expand → prune → Aider-style map
Index ¶
Constants ¶
const DefaultExpandHops = 2
DefaultExpandHops is the default number of import-graph hops.
const DefaultMaxTokens = 8000
DefaultMaxTokens is the default token budget (~8k tokens ≈ comfortable context).
Variables ¶
This section is empty.
Functions ¶
func RenderMap ¶
RenderMap produces an Aider-style compact text map from the pruned file set. Format per file:
internal/parser/parser.go [distance=0, seed]
ParseFile(path string, opts ParseOpts) (*ParseResult, error)
ParseResult
If includeBody is true, function bodies are included (higher token cost). rootPrefix is stripped from file paths (e.g. "/tmp/go-code-workspace/owner_repo/").
Types ¶
type Deps ¶
type Deps struct {
// AnalyzeDeps provides ingest, parse, and BM25 capabilities (required).
AnalyzeDeps analyze.Deps
// EmbedClient enables semantic search signal. Optional.
EmbedClient EmbedClient
// EmbedStore provides vector similarity search. Optional.
EmbedStore EmbedStore
// RepoKey is the embedding store key for this repository. Required when
// EmbedClient/EmbedStore are set.
RepoKey string
// BuildCallGraph is an optional hook that returns the call graph for a
// repository root. Used when Input.IncludeCallGraph=true. Non-fatal — if
// nil or it returns an error, import-DAG expansion still runs normally.
BuildCallGraph func(ctx context.Context, root string) (*callgraph.CallGraph, error)
// SymbolSearcher enables pg_trgm symbol name search.
// Optional — nil disables symbol name augmentation.
SymbolSearcher SymbolSearcher
// Graph provides PageRank signals for symbol-importance file boosting.
// Optional - nil disables PageRank file prioritization.
Graph graphx.Analytics
// GraphRepoKey is the repo root path passed to TopPageRank. Required when Graph is non-nil.
GraphRepoKey string
}
Deps holds optional dependencies for the research pipeline. All fields are optional — the pipeline degrades gracefully.
type EmbedClient ¶
EmbedClient is the minimal interface the research package needs from an embedding provider. Satisfied by *embed.Client (go-kit/embed) via structural typing.
type EmbedStore ¶
type EmbedStore interface {
Search(ctx context.Context, vec []float32, opts embeddings.SearchOpts) ([]embeddings.SearchResult, error)
}
EmbedStore is the minimal interface the research package needs from a vector store. Satisfied by *embeddings.Store.
type Input ¶
type Input struct {
// Root is the local path to the (already-cloned) repository.
Root string
// Query is the natural-language or keyword query.
Query string
// Language limits analysis to files of this language. Optional.
Language string
// MaxTokens is the approximate token budget for the output map.
// 0 uses DefaultMaxTokens.
MaxTokens int
// ExpandHops is the number of import-graph hops from seed files.
// 0 uses DefaultExpandHops.
ExpandHops int
// IncludeBody includes full symbol bodies in the output map.
IncludeBody bool
// FileGlob restricts analysis to files matching this glob (e.g.
// "internal/**", "pkg/foo/*.go"). Empty = no filter.
FileGlob string
// IncludeTests controls whether *_test.go / test files are indexed.
// Default false — test files are usually noise for "how does X work"
// queries. Set true to include them.
IncludeTests bool
// IncludeCallGraph enables a second BFS expansion pass using call edges
// (callers + callees) in addition to import-DAG edges. Slower but higher
// precision for "what calls X" queries. Results are merged with the import
// expansion, keeping the shorter distance when both reach the same file.
IncludeCallGraph bool
}
Input holds parameters for a code-research request.
type LinkedFile ¶
type LinkedFile struct {
RelPath string // path relative to repo root
Distance int // hop distance from nearest seed (0 = seed file itself)
WhyLinked string // human-readable explanation, e.g. "imports seed internal/parser"
Symbols []*parser.Symbol // symbols in this file relevant to the query
Score float64 // combined relevance score after decay
}
LinkedFile is a file reached via import-DAG expansion from a seed.
type Result ¶
type Result struct {
// Seeds are symbols directly matching the query (from BM25F / embed).
Seeds []SeedSymbol
// Graph is the DAG-expanded set of related files, ordered by relevance.
Graph []LinkedFile
// Map is the Aider-style compact text representation for LLM consumption.
Map string
// EstimatedTokens is the estimated token count of Map.
EstimatedTokens int
// PrunedFiles is the number of files dropped by the token-budget pruner.
PrunedFiles int
// Mode describes which signals were active: "full", "no-embed", "keyword-only".
Mode string
}
Result is the output of a code-research request.
type SeedSymbol ¶
type SeedSymbol struct {
File string
Name string
Kind string
Line int
Score float64 // RRF or BM25F score
Source string // "semantic", "keyword", or "hybrid"
}
SeedSymbol is a symbol that directly matched the query.
type SymbolSearcher ¶
type SymbolSearcher interface {
SearchBySymbolName(ctx context.Context, repoKey string, keywords []string, language string, limit int) ([]embeddings.SearchResult, error)
}
SymbolSearcher finds indexed symbols whose names match query keywords. Enables pg_trgm symbol name augmentation — catches functions with abbreviated names that vector search misses (e.g. "init" -> "initializes"). Optional. Satisfied by *embeddings.Store (structural typing).