Skip to main content
Weaviate Docs (migrated from docs.weaviate.io) Docs

Search documentation

Type to search this documentation.

On this pageOverview

Multimedia search

Multimedia search uses images, video, audio and other multimedia formats as a search input to perform vector similarity search via the near_media operator.

Use the near_media operator to search by providing a file path to a video.

Python
from pathlib import Pathfrom weaviate.classes.query import NearMediaTypecollection = client.collections.use("MediaExample")response = collection.query.near_media(    media=Path("./videos/dog.mp4"),    media_type=NearMediaType.VIDEO,    return_properties=["title", "mediaType"],    limit=5,)for obj in response.objects:    print(obj.properties)

You can also provide a base64-encoded video string:

Python
import base64from weaviate.classes.query import NearMediaTypewith open("./videos/butterfly.mp4", "rb") as f:    video_base64 = base64.b64encode(f.read()).decode("utf-8")collection = client.collections.use("MediaExample")response = collection.query.near_media(    media=video_base64,    media_type=NearMediaType.VIDEO,    return_properties=["title", "mediaType"],    limit=5,)for obj in response.objects:    print(obj.properties)

Set a maximum distance to filter results and return the distance metadata:

Python
import base64from weaviate.classes.query import MetadataQuery, NearMediaTypewith open("./videos/cat.mp4", "rb") as f:    video_base64 = base64.b64encode(f.read()).decode("utf-8")collection = client.collections.use("MediaExample")response = collection.query.near_media(    media=video_base64,    media_type=NearMediaType.VIDEO,    distance=0.8,  # Maximum accepted distance    return_metadata=MetadataQuery(distance=True),    return_properties=["title", "mediaType"],    limit=5,)for obj in response.objects:    print(f"{obj.properties} - Distance: {obj.metadata.distance}")

Combine near media searches with filters to narrow results:

Python
import base64from weaviate.classes.query import NearMediaTypefrom weaviate.classes.query import Filterwith open("./videos/dog.mp4", "rb") as f:    video_base64 = base64.b64encode(f.read()).decode("utf-8")collection = client.collections.use("MediaExample")response = collection.query.near_media(    media=video_base64,    media_type=NearMediaType.VIDEO,    filters=Filter.by_property("mediaType").equal("animals"),    return_properties=["title", "mediaType"],    limit=5,)for obj in response.objects:    print(obj.properties)

The near_media operator supports other media types such as audio. Set the media_type parameter to the appropriate NearMediaType value:

Python
import base64from weaviate.classes.query import NearMediaTypecollection = client.collections.use("MediaExample")response = collection.query.near_media(    media=Path("./audio/dog.wav"),    media_type=NearMediaType.AUDIO,    return_properties=["title", "mediaType"],    limit=5,)for obj in response.objects:    print(obj.properties)

The NearMediaType enum supports the following media types. Available types depend on the vectorizer module and model used.

Media type Enum value Description
Audio NearMediaType.AUDIO Audio files (e.g., .wav, .mp3)
Image NearMediaType.IMAGE Image files (e.g., .jpg, .png). See also Image search.
Video NearMediaType.VIDEO Video files (e.g., .mp4, .avi)
Depth NearMediaType.DEPTH Depth map data
Thermal NearMediaType.THERMAL Thermal image data
IMU NearMediaType.IMU Inertial measurement unit data

Have a question or feedback? Here's how to reach us.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu