indexer

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package indexer coordinates file walking, embedding, querying with deduplication and optional reranking for embedding-based search.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildGitignore

func BuildGitignore(configPatterns string) *gitignore.GitIgnore

BuildGitignore combines .gitignore from the filesystem with config-defined patterns.

Types

type Indexer

type Indexer struct {

	// OnProgress is called at each phase transition with a human-readable status message.
	// If nil, progress is silently ignored.
	OnProgress func(phase string)
	// contains filtered or unexported fields
}

Indexer manages file walking, embedding, querying, and reranking.

func New

func New(
	provider providers.Provider,
	embedModel, dbDir string,
	chunkCfg chunker.Config,
	gi *gitignore.GitIgnore,
) (*Indexer, error)

New creates an Indexer with the given provider, model, storage directory, and gitignore.

func (*Indexer) Index

func (idx *Indexer) Index(ctx context.Context) (*embedder.Stats, error)

Index walks the directory and embeds files, returning stats.

func (*Indexer) Progress

func (idx *Indexer) Progress(phase string)

Progress calls OnProgress if set.

func (*Indexer) Query

func (idx *Indexer) Query(ctx context.Context, query string, k, rerankMultiplier int) (Results, Results, error)

Query searches the index and returns both unsorted and reranked results. When no reranker is set, both return values are identical.

func (*Indexer) Rerank

func (idx *Indexer) Rerank(ctx context.Context, query string, results Results) (Results, error)

Rerank reorders results using the rerank provider.

func (*Indexer) SetOffload

func (idx *Indexer) SetOffload(embed, rerank bool)

SetOffload enables explicit model load/unload for embedding and/or reranking. When enabled, models are loaded before use and unloaded after to free VRAM.

func (*Indexer) UseReranker

func (idx *Indexer) UseReranker(provider providers.Provider, model string)

UseReranker sets the provider and model to use for reranking.

func (*Indexer) Walk

func (idx *Indexer) Walk(dir string) error

Walk scans the directory tree, respecting gitignore rules, and computes file hashes.

type Result

type Result struct {
	Path       string  `json:"path"`
	Content    string  `json:"content,omitempty"`
	StartLine  int     `json:"start_line"`
	EndLine    int     `json:"end_line"`
	Similarity float32 `json:"similarity"`
}

Result represents a single search result with file location and similarity score.

func (Result) Display

func (r Result) Display() string

Display returns a human-readable summary of a single result.

type Results

type Results []Result

Results is a collection of search results.

func (Results) Display

func (rs Results) Display() string

Display returns a human-readable summary of all results.

func (Results) DisplayWithReranked

func (rs Results) DisplayWithReranked(reranked Results, hasReranker bool) string

DisplayWithReranked formats both unsorted and reranked results for display. When hasReranker is true, shows both sections; otherwise shows just the results.

Jump to

Keyboard shortcuts

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