Ragex. Embeddings. Helper
(Ragex v0.21.0)
View Source
Helper functions to generate and store embeddings for analyzed code entities.
This module bridges the gap between code analyzers and the embedding system, automatically generating embeddings for modules, functions, and other entities.
Chunking
Large entities (modules or functions whose embeddable text exceeds
Chunker.defaults()[:min_lines] lines) are also stored as per-chunk
embeddings under node type :chunk. Each chunk key is
{parent_type, parent_id, chunk_index}.
The entity-level embedding is always stored as well for backward
compatibility with graph_first retrieval, which looks up embeddings by
exact entity key. Chunk embeddings are used by semantic and hybrid search
via the :include_chunks option on VectorStore.search/2.
Summary
Functions
Generates and stores embeddings for all entities in an analysis result.
Generate chunk embeddings for every entity in a batch.
Generates embeddings for a batch of entities efficiently.
Generate and store chunk embeddings for a single entity text.
Generates and stores an embedding for a single function.
Generates and stores an embedding for a single module.
Checks if the embedding system is available and ready.
Functions
Generates and stores embeddings for all entities in an analysis result.
Takes the output from an analyzer and generates embeddings for:
- Modules
- Functions
Returns :ok if embeddings were generated, or {:error, reason} if the
model is not ready or embedding generation fails.
Options
:only-MapSetof entity IDs whose embeddings should be (re)generated. Whennil(default) all entities are embedded. Set this to the result ofFileTracker.stale_entities_for_file/2to skip unchanged functions and avoid redundant re-embeddings on incremental re-analysis.
Generate chunk embeddings for every entity in a batch.
Called automatically after generate_batch_embeddings/2. Can also be called
independently.
Options
:only-MapSetof entity IDs to embed. Entities not in the set are skipped. Passnil(default) to process all entities.
Generates embeddings for a batch of entities efficiently.
Uses batch embedding to process multiple entities at once for better performance.
Options
:only-MapSetof entity IDs to embed. Whennil(default) all entities in the batch are embedded. Pass the result ofFileTracker.stale_entities_for_file/2to skip unchanged functions.
@spec generate_chunk_embeddings(atom(), term(), String.t(), keyword()) :: {:ok, non_neg_integer()} | :skip | {:error, term()}
Generate and store chunk embeddings for a single entity text.
Splits text into overlapping windows via Chunker.split/2, embeds each
window in one batch call, and stores them under node type :chunk with
compound keys {parent_type, parent_id, chunk_index}.
Returns {:ok, chunk_count} when chunks are stored, or :skip when the
text is short enough that a single entity embedding already suffices.
Generates and stores an embedding for a single function.
Generates and stores an embedding for a single module.
Checks if the embedding system is available and ready.