Skeg. Vector
(skeg v1.0.0)
Copy Markdown
Vector index commands.
:ok = Skeg.Vector.create(conn, "docs", 768)
:ok = Skeg.Vector.set(conn, "docs", 1, embedding, payload: "lang=it")
{:ok, hits} = Skeg.Vector.search(conn, "docs", question, 10, filter: "lang = it")Vectors are lists of numbers, or binaries of little-endian f32, and every
component must be finite in f32. IDs are integers from 0 to 2^64-1.
Arguments outside those ranges raise ArgumentError before anything is
sent. Every function takes :timeout in ms as an option.
Summary
Types
A row for set_many/4: {id, vector} stores no payload,
{id, vector, payload} stores a non-empty payload.
How an index stores its vectors.
Functions
Creates an index of dim dimensions: by default a durable disk index of
kind :tq2. Every setting is sent explicitly, so the result does not
depend on server defaults.
Deletes the row and reports whether a live row was removed.
Removes the index and every vector in it.
The stored vector as a list of floats, or nil when the row does not exist.
The indexes visible to this connection's tenant.
Most items set_many/4 sends in one request.
Largest payload stored with one vector.
The k rows nearest to vector, best first. The server reduces k
above its max_k limit.
Stores vector under id, replacing the row. Without :payload the row
keeps no payload; a payload of key=value fields can be used in search
filters.
Stores many rows in one request. The result has one entry per item, in
order: :ok for a stored row, {:error, %Skeg.Error{kind: :server}} for
a row the server refused. A refusal of the whole request is the outer
{:error, _}; like any server error, it does not prove that no row was
stored.
Types
@type error() :: {:error, Skeg.Error.t()}
@type id() :: non_neg_integer()
A row for set_many/4: {id, vector} stores no payload,
{id, vector, payload} stores a non-empty payload.
@type kind() :: :f32 | :int8 | :binary | :tq1 | :tq2 | :tq4
How an index stores its vectors.
Functions
@spec create(Skeg.conn(), String.t(), pos_integer(), keyword()) :: :ok | error()
Creates an index of dim dimensions: by default a durable disk index of
kind :tq2. Every setting is sent explicitly, so the result does not
depend on server defaults.
Options:
:kind- one of [:f32, :int8, :binary, :tq1, :tq2, :tq4], default:tq2:in_memory- a flat in-memory index, removed when the server restarts. Defaultfalse.:search_list- default search list length of a disk index:if_not_exists- succeed without changes when an index with the same settings exists; one with other settings is still an error
Deletes the row and reports whether a live row was removed.
Removes the index and every vector in it.
The stored vector as a list of floats, or nil when the row does not exist.
@spec info(Skeg.conn(), String.t(), keyword()) :: {:ok, Skeg.Vector.Info.t()} | error()
@spec list(Skeg.conn(), keyword()) :: {:ok, [Skeg.Vector.Summary.t()]} | error()
The indexes visible to this connection's tenant.
Most items set_many/4 sends in one request.
Largest payload stored with one vector.
@spec search(Skeg.conn(), String.t(), vector(), pos_integer(), keyword()) :: {:ok, [Skeg.Vector.Hit.t()]} | error()
The k rows nearest to vector, best first. The server reduces k
above its max_k limit.
Options:
:search_list- larger is slower and more accurate;0, the default, uses the index default. The server reduces values above itsmax_llimit.:with_payload- return each hit's payload. Defaultfalse.:filter- keep only rows whose payload matches, such as"lang = it AND year >= 2020"
Stores vector under id, replacing the row. Without :payload the row
keeps no payload; a payload of key=value fields can be used in search
filters.
@spec set_many(Skeg.conn(), String.t(), [item()], keyword()) :: {:ok, [:ok | {:error, Skeg.Error.t()}]} | error()
Stores many rows in one request. The result has one entry per item, in
order: :ok for a stored row, {:error, %Skeg.Error{kind: :server}} for
a row the server refused. A refusal of the whole request is the outer
{:error, _}; like any server error, it does not prove that no row was
stored.
At most max_batch_items/0 items, each payload at most
max_payload_bytes/0; the server also refuses a batch whose vectors
exceed 64 MiB in total. A batch cannot carry an empty payload, because
the server stores it as no payload: use {id, vector}, or set/5 with
payload: "".