Mappings
The mappings object is a parameter (mappings
) for an add_documents
call. Mappings can be used for granular control over a field. Currently, it is only supported for the multimodal_combination
field.
Mappings object
Defining the mapping for multimodal_combination
fields:
my_mapping = {
"my_combination_field": {
"type": "multimodal_combination",
"weights": {"my_image": 0.5, "some_text": 0.5},
},
"my_2nd_combination_field": {
"type": "multimodal_combination",
"weights": {"Title": -2.5, "Description": 0.3},
},
}
Adding multimodal documents using that mapping object:
import marqo
mq = marqo.Client(url="http://localhost:8882")
settings = {"treat_urls_and_pointers_as_images": True, "model": "ViT-B/32"}
mq.create_index("my-first-multimodal-index", **settings)
# Add 1 sample document
mq.index("my-first-multimodal-index").add_documents(
[
{
"Title": "A document with multiple multimodal fields",
"my_combination_field": {
"my_image": "https://raw.githubusercontent.com/marqo-ai/marqo/mainline/examples/ImageSearchGuide/data/image2.jpg",
"some_text": "An image of a passenger plane flying in front of the moon.",
},
"my_2nd_combination_field": {
"Title": "Superhero Movie 5",
"Description": "Good guy beats bad guy for the 5th time!",
},
}
],
mappings=my_mapping,
)