# `Milvex.Function`

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"])

# `function_type`

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

# `t`

```elixir
@type t() :: %Milvex.Function{
  input_field_names: [String.t()],
  name: String.t(),
  output_field_names: [String.t()],
  params: %{required(String.t()) =&gt; String.t()},
  type: function_type()
}
```

# `bm25`

```elixir
@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`

```elixir
@spec from_proto(Milvex.Milvus.Proto.Schema.FunctionSchema.t()) :: t()
```

Creates a Function from a protobuf FunctionSchema struct.

# `input_field_names`

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

Sets the input field names for the function.

# `new`

```elixir
@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`

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

Sets the output field names for the function.

# `param`

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

Adds a parameter to the function.

# `to_proto`

```elixir
@spec to_proto(t()) :: Milvex.Milvus.Proto.Schema.FunctionSchema.t()
```

Converts the function to a protobuf FunctionSchema struct.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
