Milvex.Highlighter (milvex v0.10.2)

Copy Markdown

Builder functions for search result highlighting.

Two highlighting strategies are available:

  • Lexical - matches based on exact token overlap (BM25 search)
  • Semantic - matches based on meaning similarity using a deployed model

Examples

{:ok, hl} = Highlighter.lexical("content")
{:ok, hl} = Highlighter.semantic(["what is AI?"], ["content", "title"],
  model_deployment_id: "my-model"
)

Summary

Functions

Creates a lexical highlighter for the given field.

Creates a semantic highlighter.

Types

t()

@type t() :: %Milvex.Highlighter{params: map(), type: :lexical | :semantic}

Functions

lexical(field, opts \\ [])

@spec lexical(
  String.t(),
  keyword()
) :: {:ok, t()} | {:error, Milvex.Errors.Invalid.t()}

Creates a lexical highlighter for the given field.

Lexical highlighting matches based on exact token overlap between the query and the document text. Works with BM25 search.

Options

  • :pre_tag - Tag inserted before highlighted text (default: "<b>")
  • :post_tag - Tag inserted after highlighted text (default: "</b>")

Examples

{:ok, hl} = Highlighter.lexical("content")
{:ok, hl} = Highlighter.lexical("content", pre_tag: "<em>", post_tag: "</em>")

semantic(queries, input_fields, opts \\ [])

@spec semantic([String.t()], [String.t()], keyword()) ::
  {:ok, t()} | {:error, Milvex.Errors.Invalid.t()}

Creates a semantic highlighter.

Semantic highlighting matches based on meaning similarity using a deployed model. Requires explicit queries and input fields.

Parameters

  • queries - List of search query strings to match against documents
  • input_fields - List of field names to highlight

Options

  • :pre_tags - List of tags inserted before highlighted text
  • :post_tags - List of tags inserted after highlighted text
  • :threshold - Minimum confidence score (0.0 to 1.0) to trigger highlighting
  • :highlight_only - If true, returns only highlighted snippets instead of full text
  • :model_deployment_id - ID of the deployed model for semantic inference
  • :max_client_batch_size - Limits items processed in a single batch

Examples

{:ok, hl} = Highlighter.semantic(["what is AI?"], ["content"])
{:ok, hl} = Highlighter.semantic(["search query"], ["title", "body"],
  threshold: 0.5,
  model_deployment_id: "my-model"
)