index

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package index stores embeddings for source-code chunks and answers nearest-neighbor queries via cosine similarity. The implementation is intentionally minimal (in-memory + gob on disk) to avoid pulling in a vector-DB dependency for what is currently an opt-in feature.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFingerprints

func BuildFingerprints(root string, files []string) (map[string]string, error)

BuildFingerprints returns a path → sha256 map for the given repo-relative files. Files unreadable from root are skipped silently.

func DiffFingerprints

func DiffFingerprints(prev, curr map[string]string) (added, modified, deleted []string)

DiffFingerprints classifies paths between two snapshots.

func LoadFingerprints

func LoadFingerprints(path string) (map[string]string, error)

LoadFingerprints reads a snapshot from path. A missing file returns an empty map without error so first-run callers can treat it uniformly.

func SaveFingerprints

func SaveFingerprints(path string, fp map[string]string) error

SaveFingerprints persists a snapshot to path (creating parent dirs as needed).

func SaveMeta

func SaveMeta(path string, m EmbedMeta) error

SaveMeta persists m to path (creating parent dirs as needed).

Types

type EmbedMeta

type EmbedMeta struct {
	Model string `json:"model"`
	Dim   int    `json:"dim"`
}

EmbedMeta identifies the embedding model that produced a persisted index. Vectors from different models (or dimensions) are not comparable.

func LoadMeta

func LoadMeta(path string) (EmbedMeta, bool)

LoadMeta reads the metadata at path. ok is false when the file is missing or unreadable, meaning the originating model is unknown.

func MetaFor

func MetaFor(emb embedder.Embedder) EmbedMeta

MetaFor describes emb. Embedders without a Name method are recorded as "unknown" and distinguished by dimension only.

func (EmbedMeta) Compatible

func (m EmbedMeta) Compatible(cur EmbedMeta) bool

Compatible reports whether vectors saved under m can be compared with vectors produced under cur. An unknown (zero) dimension on either side is not treated as a mismatch.

type FileFingerprint

type FileFingerprint struct {
	Path   string `json:"path"`
	SHA256 string `json:"sha256"`
}

FileFingerprint is a single (path, sha256) entry. The SHA-256 is computed over the file's verbatim bytes.

type Hit

type Hit struct {
	Path      string
	ChunkName string
	Score     float32
}

Hit is a search result (file, chunk name, similarity score in [-1, 1]).

type Index

type Index interface {
	Add(ctx context.Context, chunks []chunker.Chunk, paths []string) error
	Remove(paths []string)
	Search(ctx context.Context, query string, k int) ([]Hit, error)
	Persist(path string) error
	Load(path string) error
}

Index stores chunk embeddings and answers similarity queries.

func New

func New(emb embedder.Embedder) Index

New constructs an in-memory index backed by emb for embeddings.

Jump to

Keyboard shortcuts

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