WeaviateEx.Query.NearMedia (WeaviateEx v0.7.4)
View SourceMedia-based vector search for multimodal collections.
Supports audio, video, thermal, depth, and IMU data types for multi2vec-bind and similar multimodal vectorizers.
Supported Media Types
:audio- Audio files (wav, mp3, etc.):video- Video files (mp4, avi, etc.):thermal- Thermal imaging data:depth- Depth sensor data:imu- Inertial measurement unit data
Examples
# Search by audio
NearMedia.new(:audio, media: base64_audio)
|> Query.execute(client, "MediaCollection")
# Search by video file
NearMedia.new(:video, media_file: "/path/to/video.mp4", certainty: 0.8)
# Using the Query builder
Query.get("MediaCollection")
|> Query.near_media(:audio, media: base64_audio, certainty: 0.7)
|> Query.fields(["name", "description"])
|> Query.execute(client)
Summary
Functions
Encode a media file to base64.
Get the base64-encoded media data, reading from file if necessary.
Returns the list of supported media types.
Create a new near_media search configuration.
Convert to GraphQL query format.
Convert to gRPC NearMediaSearch format.
Types
Functions
Encode a media file to base64.
Examples
NearMedia.encode_media_file("/path/to/audio.wav")
# => "UklGRi4A..." (WAV header as base64)
Get the base64-encoded media data, reading from file if necessary.
If the struct was created with :media, returns it as-is.
If the struct was created with :media_file, reads and encodes the file.
Examples
near_media = NearMedia.new(:audio, media: "base64data")
NearMedia.get_encoded_media(near_media)
# => "base64data"
near_media = NearMedia.new(:audio, media_file: "/path/to/audio.wav")
NearMedia.get_encoded_media(near_media)
# => "UklGRi4A..." (file contents as base64)
@spec media_types() :: [media_type()]
Returns the list of supported media types.
Examples
NearMedia.media_types()
# => [:audio, :video, :thermal, :depth, :imu]
@spec new( media_type(), keyword() ) :: t()
Create a new near_media search configuration.
Arguments
type- Media type::audio,:video,:thermal,:depth, or:imuopts- Keyword options
Options
:media- Base64-encoded media data:media_file- Path to media 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 :media or :media_file must be provided, but not both.
Examples
NearMedia.new(:audio, media: base64_audio)
NearMedia.new(:video, media_file: "/path/to/video.mp4", certainty: 0.8)
NearMedia.new(:thermal, media: data, target_vectors: ["thermal_vector"])
Convert to GraphQL query format.
Returns a map with string keys suitable for GraphQL nearMedia queries. The media type is converted to a lowercase string (e.g., "audio"). Nil values are excluded from the result.
Examples
near_media = NearMedia.new(:depth, media: "data", distance: 0.2)
NearMedia.to_graphql(near_media)
# => %{"media" => "data", "type" => "depth", "distance" => 0.2}
Convert to gRPC NearMediaSearch format.
Returns a map suitable for use with the gRPC search API.
The media type is converted to the gRPC enum format (e.g., :MEDIA_TYPE_AUDIO).
Nil values are excluded from the result.
Examples
near_media = NearMedia.new(:thermal, media: "data", certainty: 0.8)
NearMedia.to_grpc(near_media)
# => %{media: "data", type: :MEDIA_TYPE_THERMAL, certainty: 0.8}