mp.tasks.retrieval.SemanticRetriever

Class that manages a vector index and retrieves relevant media records.

Methods

close

View source

Shuts down and releases the retriever.

create_from_options

View source

Creates the SemanticRetriever object from options.

delete_all

View source

Deletes all records from database.

delete_record

View source

Deletes record with the specified ID.

delete_with_metadata_filter

View source

Deletes records matching the specified metadata filter.

get_all_record_ids

View source

Returns list of all active record IDs.

insert_audio

View source

Inserts an audio record into the vector store.

If audio_data is provided, the audio is loaded from those raw PCM samples directly. Otherwise, if audio_data is not passed, the audio is automatically loaded and decoded from audio_path on-demand.

Args
audio_id The unique identifier for the audio record.
audio_path The file path to the WAV file. Must be specified.
audio_data Optional list of raw mono PCM float samples.
metadata Optional dictionary of key-value metadata to associate.

insert_content

View source

Inserts multi-modal parts with optional metadata.

Args
record_id The unique identifier for the content record.
parts A list of part dictionaries. Each part dictionary should match the structure {'kind': TaskPartKind, 'text': ..., 'image_bytes': ..., 'file_path': ..., 'audio_data': ..., 'audio_path': ...}.
metadata Optional dictionary of key-value metadata to associate.

insert_document

View source

Inserts text document with optional metadata.

insert_image

View source

Inserts an image into the vector store.

If image_bytes is provided, the image is loaded from those raw bytes directly. Otherwise, if image_bytes is not passed, the image is automatically loaded and decoded from image_path on-demand.

Args
image_id The unique identifier for the image record.
image_path The file path or URI for the image. Must be specified.
image_bytes Optional raw encoded image bytes (e.g. JPEG, PNG).
metadata Optional dictionary of key-value metadata to associate.

retrieve

View source

Retrieves nearest matching documents from the vector store.

Args
query Either a plain text query string, or a list of query part dictionaries for multimodal retrieval. Each part dictionary should match the structure {'kind': TaskPartKind, 'text': ..., 'image_bytes': ..., 'file_path': ..., 'audio_data': ..., 'audio_path': ...}.
limit The maximum number of nearest records to return.
min_similarity The minimum similarity score threshold.
metadata_filter Optional dictionary of key-value pairs used to filter candidate records.

Returns
A RetrievalResult containing matching documents.

__enter__

View source

__exit__

View source