First pass at uniformed types, specs and docs

- spec public functions (skipping controllers, views, live views and
components)
- use types instead of explanations in docs
- remove redundant docs
- fix typos
This commit is contained in:
Claudio Ortolina
2026-03-06 08:33:11 +00:00
parent 99e30d5fdf
commit 7cf9b4e7f8
81 changed files with 652 additions and 300 deletions
+8
View File
@@ -4,16 +4,24 @@ defmodule SqliteVec.Ecto.Float32 do
"""
use Ecto.Type
@impl true
@spec type() :: :binary
def type, do: :binary
@impl true
@spec cast(any()) :: {:ok, SqliteVec.Float32.t()}
def cast(value) do
{:ok, SqliteVec.Float32.new(value)}
end
@impl true
@spec load(binary()) :: {:ok, SqliteVec.Float32.t()}
def load(data) do
{:ok, SqliteVec.Float32.from_binary(data)}
end
@impl true
@spec dump(SqliteVec.Float32.t()) :: {:ok, binary()} | :error
def dump(%SqliteVec.Float32{} = vector) do
{:ok, SqliteVec.Float32.to_binary(vector)}
end
+3
View File
@@ -75,6 +75,9 @@ defmodule SqliteVec.Ecto.Query do
end
end
@doc """
Matches a vector against a virtual table using the `match` operator.
"""
defmacro vec_match(a, b) do
quote do
fragment("? match ?", unquote(a), unquote(b))
+4
View File
@@ -41,6 +41,7 @@ defmodule SqliteVec.Float32 do
iex> SqliteVec.Float32.new(Nx.tensor([1, 2], type: :f32))
%SqliteVec.Float32{data: <<1.0::float-32-native, 2.0::float-32-native>>}
"""
@spec new(t() | [number()]) :: t()
def new(vector_or_list_or_tensor)
def new(%SqliteVec.Float32{} = vector) do
@@ -74,6 +75,7 @@ defmodule SqliteVec.Float32 do
@doc """
Creates a new vector from its binary representation
"""
@spec from_binary(binary()) :: t()
def from_binary(binary) when is_binary(binary) do
%SqliteVec.Float32{data: binary}
end
@@ -81,6 +83,7 @@ defmodule SqliteVec.Float32 do
@doc """
Converts the vector to its binary representation
"""
@spec to_binary(t()) :: binary()
def to_binary(vector) when is_struct(vector, SqliteVec.Float32) do
vector.data
end
@@ -88,6 +91,7 @@ defmodule SqliteVec.Float32 do
@doc """
Converts the vector to a list
"""
@spec to_list(t()) :: [float()]
def to_list(vector) when is_struct(vector, SqliteVec.Float32) do
<<bin::binary>> = vector.data