Milvex.Function (milvex v0.10.2)

Copy Markdown

Builder for Milvus function schemas.

Functions define transformations on fields, such as BM25 full-text search that converts text to sparse embeddings.

Examples

# BM25 function for full-text search
function = Function.bm25("bm25_fn", input: "content", output: "sparse")

# Using with fluent builder
function = Function.new("bm25_fn", :BM25)
|> Function.input_field_names(["content"])
|> Function.output_field_names(["sparse"])

Summary

Functions

Creates a BM25 function for full-text search.

Creates a Function from a protobuf FunctionSchema struct.

Sets the input field names for the function.

Creates a new function with the given name and type.

Sets the output field names for the function.

Adds a parameter to the function.

Converts the function to a protobuf FunctionSchema struct.

Types

function_type()

@type function_type() :: :BM25 | :TextEmbedding | :Rerank

t()

@type t() :: %Milvex.Function{
  input_field_names: [String.t()],
  name: String.t(),
  output_field_names: [String.t()],
  params: %{required(String.t()) => String.t()},
  type: function_type()
}

Functions

bm25(name, opts)

@spec bm25(
  String.t(),
  keyword()
) :: t()

Creates a BM25 function for full-text search.

BM25 converts text fields to sparse vector embeddings for full-text search.

Note: Milvus BM25 functions only support a single input field and a single output field. If you need to search multiple text fields, create separate BM25 functions for each field with their own sparse vector output fields, then use hybrid search to combine the results.

Options

  • :input - Input field name (required, single VARCHAR field)
  • :output - Output field name (required, single SPARSE_FLOAT_VECTOR field)

Examples

Function.bm25("bm25_fn", input: "content", output: "sparse")

# For multiple text fields, create separate functions:
Function.bm25("title_bm25", input: "title", output: "title_sparse")
Function.bm25("content_bm25", input: "content", output: "content_sparse")

from_proto(proto)

Creates a Function from a protobuf FunctionSchema struct.

input_field_names(func, names)

@spec input_field_names(t(), [String.t() | atom()]) :: t()

Sets the input field names for the function.

new(name, type)

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

Creates a new function with the given name and type.

Parameters

  • name - Function name
  • type - Function type (:BM25, :TextEmbedding, :Rerank)

Examples

Function.new("bm25_fn", :BM25)

output_field_names(func, names)

@spec output_field_names(t(), [String.t() | atom()]) :: t()

Sets the output field names for the function.

param(func, key, value)

@spec param(t(), String.t(), String.t()) :: t()

Adds a parameter to the function.

to_proto(func)

Converts the function to a protobuf FunctionSchema struct.