localindex

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProjectDir

func ProjectDir(originURL, repoRoot string) (string, error)

ProjectDir returns where this repo's index lives, creating parents.

Types

type Chunk

type Chunk struct {
	RelPath     string
	Language    string
	Kind        string // "lines" for v0.2 first cut; "function|method|class|module" once tree-sitter ports
	LineStart   int
	LineEnd     int
	ContentText string
	ContentHash string
}

Chunk is what the indexer hands us — minimal enough to be language-agnostic.

type Manifest

type Manifest struct {
	SchemaVersion  int       `json:"schemaVersion"`
	Model          string    `json:"model"`
	Dim            int       `json:"dim"`
	LastIndexedSha string    `json:"lastIndexedSha,omitempty"`
	LastIndexedAt  time.Time `json:"lastIndexedAt"`
	ProjectKey     string    `json:"projectKey"`
	OriginURL      string    `json:"originUrl,omitempty"`
	RepoRoot       string    `json:"repoRoot,omitempty"`
}

Manifest sits next to index.db so we can detect model/dim mismatches without opening the DB.

type SearchResult

type SearchResult struct {
	ChunkID   string
	RelPath   string
	Language  string
	Kind      string
	LineStart int
	LineEnd   int
	Score     float64 // 1 - cosine_distance; higher is better
	Content   string
}

SearchResult mirrors the server-side shape so the CLI renderer can be shared.

type Store

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

Store wraps the sqlite handle + the manifest path so callers don't track them separately.

func Open

func Open(originURL, repoRoot, model string, dim int) (*Store, error)

Open opens (or creates) the local index for a repo. model + dim are recorded in the manifest on first open; a subsequent Open with a different model+dim errors so we never mix vectors of different shapes in the same DB.

func (*Store) Close

func (s *Store) Close() error

Close releases the sqlite handle.

func (*Store) CountChunks

func (s *Store) CountChunks() (int, error)

CountChunks returns how many chunks are in the index — used by `index` status output and by tests.

func (*Store) Dir

func (s *Store) Dir() string

Dir returns the on-disk directory holding this store's files.

func (*Store) HasChunk

func (s *Store) HasChunk(contentHash string) (bool, error)

HasChunk returns true if a chunk with this content_hash already exists (the indexer uses this to skip re-embedding unchanged content).

func (*Store) ReadManifest

func (s *Store) ReadManifest() (*Manifest, error)

ReadManifest re-reads the manifest from disk — used by `getdebug status` or future commands that want index metadata without opening the DB.

func (*Store) Search

func (s *Store) Search(query []float32, k int, languages []string) ([]SearchResult, error)

Search runs brute-force cosine similarity. Fine at the v0.2 scale (≤30k chunks per repo). When that ceiling is hit, swap to sqlite-vec (or split the index into shards) — the row scan model stays.

func (*Store) UpdateLastIndexed

func (s *Store) UpdateLastIndexed(sha string) error

UpdateLastIndexed bumps the manifest's last-indexed bookkeeping after a successful index run.

func (*Store) Upsert

func (s *Store) Upsert(id string, c Chunk, embedding []float32) error

Upsert stores (or skips) a chunk + its embedding. Idempotent on content_hash.

Jump to

Keyboard shortcuts

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