Store.Project.CommitIndex (fnord v0.9.23)

View Source

Manages semantic index data for git commits within a project.

Commit index data lives alongside the other project-scoped semantic indexes, but under its own root so commit entries remain isolated from file and conversation storage.

Summary

Functions

Enumerates all indexed commits, yielding {sha, embeddings, metadata}.

Builds the canonical commit document and metadata payload used for indexing.

Deletes the index entry for the given commit SHA.

Classifies commit index entries into new, stale, and deleted.

Reads embeddings and metadata for a commit.

Reads only the metadata for a commit index entry.

Returns true when the given commit still needs indexing in this project - either the index entry is missing, or its metadata indicates a model / format / doc-hash mismatch with the current commit payload.

Writes embeddings and metadata for a commit.

Types

commit_record()

@type commit_record() :: %{
  sha: String.t(),
  parent_shas: [String.t()],
  subject: String.t(),
  body: String.t(),
  author: String.t(),
  committed_at: String.t() | DateTime.t() | non_neg_integer(),
  changed_files: [String.t()],
  diffstat: String.t() | [map()],
  embedding_model: String.t() | nil,
  last_indexed_ts: non_neg_integer()
}

commit_status()

@type commit_status() :: %{
  new: [commit_record()],
  stale: [commit_record()],
  deleted: [String.t()]
}

metadata()

@type metadata() :: %{optional(String.t()) => any()}

Functions

all_embeddings(project)

@spec all_embeddings(Store.Project.t()) :: Enumerable.t()

Enumerates all indexed commits, yielding {sha, embeddings, metadata}.

build_metadata(commit)

@spec build_metadata(%{
  sha: binary(),
  parent_shas: [binary()],
  subject: binary(),
  body: binary(),
  author: binary(),
  committed_at: binary() | non_neg_integer() | DateTime.t(),
  changed_files: [binary()],
  diffstat: binary() | [map()]
}) :: %{document: binary(), metadata: metadata()}

Builds the canonical commit document and metadata payload used for indexing.

delete(project, sha)

@spec delete(Store.Project.t(), String.t()) :: :ok

Deletes the index entry for the given commit SHA.

index_status(project)

@spec index_status(Store.Project.t()) :: commit_status()

Classifies commit index entries into new, stale, and deleted.

A commit is stale when the stored embedding model, document version, or canonical commit document hash differs from the current values.

path_for(project, sha)

@spec path_for(Store.Project.t(), String.t()) :: String.t()

read_embeddings(project, sha)

@spec read_embeddings(Store.Project.t(), String.t()) ::
  {:ok, %{embeddings: any(), metadata: metadata()}} | {:error, term()}

Reads embeddings and metadata for a commit.

read_metadata(project, sha)

@spec read_metadata(Store.Project.t(), String.t()) ::
  {:ok, metadata()} | {:error, term()}

Reads only the metadata for a commit index entry.

root(project)

@spec root(Store.Project.t()) :: String.t()

stale?(project, commit)

@spec stale?(Store.Project.t(), commit_record()) :: boolean()

Returns true when the given commit still needs indexing in this project - either the index entry is missing, or its metadata indicates a model / format / doc-hash mismatch with the current commit payload.

Used by foreground indexers to re-check freshness inside a per-commit lock: if a parallel indexer already wrote the entry, there's no reason to pay the embed cost a second time.

write_embeddings(project, sha, embeddings, metadata)

@spec write_embeddings(Store.Project.t(), String.t(), any(), metadata()) ::
  :ok | {:error, term()}

Writes embeddings and metadata for a commit.

The embeddings are stored in embeddings.json and the metadata in metadata.json under the commit's index directory.