Zvec.Schema (zvec v0.4.0)

Copy Markdown View Source

Builder for zvec collection schemas.

Example

schema =
  Zvec.Schema.new("my_collection")
  |> Zvec.Schema.add_field("text", :string, index: %{type: :invert})
  |> Zvec.Schema.add_vector("embedding", 384, index: %{type: :hnsw, metric_type: :cosine})

Summary

Functions

Add a scalar field to the schema.

Add a dense vector field to the schema.

Set the maximum document count per segment.

Create a new schema with the given collection name.

Convert the schema struct to the NIF-compatible map format.

Types

t()

@type t() :: %Zvec.Schema{
  fields: [map()],
  max_doc_count_per_segment: pos_integer() | nil,
  name: String.t()
}

Functions

add_field(schema, name, type, opts \\ [])

@spec add_field(t(), String.t(), atom(), keyword()) :: t()

Add a scalar field to the schema.

Options

  • :nullable - whether the field can be null (default: false)
  • :index - index params map, e.g. %{type: :invert}

add_vector(schema, name, dimension, opts \\ [])

@spec add_vector(t(), String.t(), pos_integer(), keyword()) :: t()

Add a dense vector field to the schema.

Options

  • :type - vector element type (default: :vector_fp32)
  • :nullable - whether the field can be null (default: false)
  • :index - index params map, e.g. %{type: :hnsw, metric_type: :cosine} Supported types: :hnsw, :flat, :ivf, :invert, :hnsw_rabitq, :vamana :hnsw options: :m (default 16), :ef_construction (default 200), :use_contiguous_memory (default false) :hnsw_rabitq options: :total_bits (default 7), :num_clusters (default 16), :m, :ef_construction :vamana options: :max_degree (default 64), :search_list_size (default 100), :alpha (default 1.2), :saturate_graph (default false), :use_contiguous_memory (default false), :use_id_map (default false) Quantization is specified in the :index params map with quantize_type: :fp16 | :int8 | :int4 | :rabitq Supported for vector index types :hnsw, :flat, :ivf, and :vamana

max_doc_count_per_segment(schema, count)

@spec max_doc_count_per_segment(t(), pos_integer()) :: t()

Set the maximum document count per segment.

new(name)

@spec new(String.t()) :: t()

Create a new schema with the given collection name.

to_nif(schema)

@spec to_nif(t()) :: map()

Convert the schema struct to the NIF-compatible map format.