Ragex.Embeddings.Persistence
(Ragex v0.10.1)
View Source
Persistence layer for embedding vectors.
Saves and loads embeddings to/from disk to avoid regeneration on restart. Uses ETS serialization for fast I/O and includes metadata for validation.
Summary
Functions
Returns the cache path for the current project.
Returns statistics about the cache (alias for stats/0).
Checks if a valid cache exists for the current configuration.
Clears cached embeddings from disk.
Returns the default cache root directory.
Generates a unique hash for a project directory.
Loads embeddings from disk if available and valid.
Saves embeddings to disk.
Gets statistics about the cache.
Types
@type cache_metadata() :: %{ version: integer(), model_id: atom(), model_repo: String.t(), dimensions: pos_integer(), timestamp: integer(), entity_count: non_neg_integer() }
Functions
Returns the cache path for the current project.
Returns statistics about the cache (alias for stats/0).
Provides information about cache file, size, age, and contents.
Returns
{:ok, stats_map}- Cache statistics including::cache_path- Path to the cache file:file_size- Size of the cache file in bytes:metadata- Cache metadata (version, model, dimensions, timestamp, entity count):valid?- Whether the cache is valid for the current configuration
{:error, :not_found}- No cache file exists{:error, reason}- Other error
Checks if a valid cache exists for the current configuration.
Clears cached embeddings from disk.
Modes
:current- Clear current project cache:all- Clear all caches{:older_than, days}- Clear caches older than N days
Returns
:ok- Success{:error, reason}- Failure reason
Returns the default cache root directory.
Generates a unique hash for a project directory.
This ensures different projects have separate caches.
When project_path is nil, falls back to the current working directory.
Parameters
project_path- Absolute path to the project (optional, defaults to CWD)
@spec load(String.t() | nil) :: {:ok, non_neg_integer()} | {:error, term()}
Loads embeddings from disk if available and valid.
Validates:
- Model compatibility (same model ID or compatible dimensions)
- Cache version
- File integrity
Returns
{:ok, count}- Successfully loaded count embeddings{:error, :not_found}- No cache file exists{:error, :incompatible_model}- Model mismatch{:error, reason}- Other failure
Saves embeddings to disk.
Can be called with:
- ETS table reference (for tests/direct use)
- No arguments (uses Store.embeddings_table())
Returns
{:ok, path}- Success with cache file path{:error, reason}- Failure reason
Gets statistics about the cache.
Returns information about cache file, size, age, and contents.