WeaviateEx.Query.NearImage (WeaviateEx v0.7.4)

View Source

Image-based vector search for multimodal collections.

Supports multi2vec-clip, multi2vec-bind, and other image vectorizers.

Examples

# Search by base64 encoded image
NearImage.new(image: base64_data)
|> Query.execute(client, "ImageCollection")

# Search by file path
NearImage.new(image_file: "/path/to/image.png", certainty: 0.8)
|> Query.execute(client, "ImageCollection")

# With named vectors
NearImage.new(image: data, target_vectors: ["image_vector"])

# Using the Query builder
Query.get("ImageCollection")
|> Query.near_image(image: base64_data, certainty: 0.8)
|> Query.fields(["name", "description"])
|> Query.execute(client)

Summary

Functions

Encode an image file to base64.

Get the base64-encoded image data, reading from file if necessary.

Create a new near_image search configuration.

Convert to GraphQL query format.

Convert to gRPC NearImageSearch format.

Types

t()

@type t() :: %WeaviateEx.Query.NearImage{
  certainty: float() | nil,
  distance: float() | nil,
  image: String.t() | nil,
  image_file: String.t() | nil,
  target_vectors: [String.t()] | nil
}

Functions

encode_image_file(path)

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

Encode an image file to base64.

Examples

NearImage.encode_image_file("/path/to/image.png")
# => "iVBORw0KGgo..."

get_encoded_image(near_image)

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

Get the base64-encoded image data, reading from file if necessary.

If the struct was created with :image, returns it as-is. If the struct was created with :image_file, reads and encodes the file.

Examples

near_image = NearImage.new(image: "base64data")
NearImage.get_encoded_image(near_image)
# => "base64data"

near_image = NearImage.new(image_file: "/path/to/image.png")
NearImage.get_encoded_image(near_image)
# => "iVBORw0KGgo..." (file contents as base64)

new(opts)

@spec new(keyword()) :: t()

Create a new near_image search configuration.

Options

  • :image - Base64-encoded image data
  • :image_file - Path to image file (will be read and base64 encoded)
  • :certainty - Minimum certainty threshold (0.0 to 1.0)
  • :distance - Maximum distance threshold
  • :target_vectors - List of named vectors to target

Either :image or :image_file must be provided, but not both.

Examples

NearImage.new(image: "base64encodeddata==")
NearImage.new(image_file: "/path/to/image.png", certainty: 0.8)
NearImage.new(image: data, target_vectors: ["image_vector"])

to_graphql(near_image)

@spec to_graphql(t()) :: map()

Convert to GraphQL query format.

Returns a map with string keys suitable for GraphQL nearImage queries. Nil values are excluded from the result.

Examples

near_image = NearImage.new(image: "data", distance: 0.2)
NearImage.to_graphql(near_image)
# => %{"image" => "data", "distance" => 0.2}

to_grpc(near_image)

@spec to_grpc(t()) :: map()

Convert to gRPC NearImageSearch format.

Returns a map suitable for use with the gRPC search API. Nil values are excluded from the result.

Examples

near_image = NearImage.new(image: "data", certainty: 0.8)
NearImage.to_grpc(near_image)
# => %{image: "data", certainty: 0.8}