Rag.VectorStore.Chunk (rag v0.3.4)
View SourceEcto schema for storing text chunks with embeddings.
Each chunk represents a piece of text from a source document along with its vector embedding for semantic search.
Fields
content- The text content of the chunksource- The source file or document pathembedding- The vector embedding (768 dimensions for Gemini)metadata- Additional metadata as a map
Examples
chunk = Chunk.new(%{
content: "def hello, do: :world",
source: "lib/greeting.ex",
metadata: %{line_start: 1, line_end: 1}
})
Summary
Functions
Creates a changeset for inserting or updating a chunk.
Creates a changeset for updating only the embedding.
Creates a new Chunk struct from the given attributes.
Converts a Chunk struct to a plain map.
Types
@type t() :: %Rag.VectorStore.Chunk{ __meta__: term(), content: String.t(), embedding: [float()] | nil, id: integer() | nil, inserted_at: NaiveDateTime.t() | nil, metadata: map(), source: String.t() | nil, updated_at: NaiveDateTime.t() | nil }
Functions
@spec changeset(t(), map()) :: Ecto.Changeset.t()
Creates a changeset for inserting or updating a chunk.
Validates that content is present and not blank.
Examples
iex> Chunk.changeset(%Chunk{}, %{content: "Hello", source: "test.ex"})
#Ecto.Changeset<...>
@spec embedding_changeset(t(), map()) :: Ecto.Changeset.t()
Creates a changeset for updating only the embedding.
Use this when adding embeddings to existing chunks.
Examples
iex> Chunk.embedding_changeset(chunk, %{embedding: [0.1, 0.2, ...]})
#Ecto.Changeset<...>
Creates a new Chunk struct from the given attributes.
Parameters
attrs- Map with:content(required),:source,:embedding,:metadata
Examples
iex> Chunk.new(%{content: "Hello", source: "test.ex"})
%Chunk{content: "Hello", source: "test.ex", metadata: %{}}
Converts a Chunk struct to a plain map.
Useful for vector store operations that expect maps.
Examples
iex> Chunk.to_map(%Chunk{content: "Hi", source: "t.ex"})
%{content: "Hi", source: "t.ex", embedding: nil, metadata: %{}}