View source on GitHub
|
Class that manages a vector index and retrieves relevant media records.
mp.tasks.retrieval.SemanticRetriever(
lib: serial_dispatcher.SerialDispatcher, handle: ctypes.c_void_p
) -> None
Methods
close
close() -> None
Shuts down and releases the retriever.
create_from_options
@classmethodcreate_from_options( options:mp.tasks.retrieval.SemanticRetrieverOptions) -> 'SemanticRetriever'
Creates the SemanticRetriever object from options.
delete_all
delete_all() -> None
Deletes all records from database.
delete_record
delete_record(
record_id: str
) -> None
Deletes record with the specified ID.
delete_with_metadata_filter
delete_with_metadata_filter(
metadata_filter: Dict[str, str]
) -> None
Deletes records matching the specified metadata filter.
get_all_record_ids
get_all_record_ids() -> List[str]
Returns list of all active record IDs.
insert_audio
insert_audio(
audio_id: str,
audio_path: str,
audio_data: Optional[List[float]] = None,
metadata: Optional[Dict[str, str]] = None
) -> None
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
insert_content(
record_id: str,
parts: List[Dict[str, Any]],
metadata: Optional[Dict[str, str]] = None
) -> None
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
insert_document(
doc_id: str, text: str, metadata: Optional[Dict[str, str]] = None
) -> None
Inserts text document with optional metadata.
insert_image
insert_image(
image_id: str,
image_path: str,
image_bytes: Optional[bytes] = None,
metadata: Optional[Dict[str, str]] = None
) -> None
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
retrieve(
query: Union[str, List[Dict[str, Any]]],
limit: int,
min_similarity: float = 0.5,
metadata_filter: Optional[Dict[str, str]] = None
) -> mp.tasks.retrieval.RetrievalResult
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__
__enter__() -> 'SemanticRetriever'
__exit__
__exit__(
exc_type, exc_val, exc_tb
) -> None
View source on GitHub