Skip to content

Document field types


Strings

These are vectorised, if the field is specified is in tensor_fields during index time.

Floats

These aren't vectorised, but can be used to filter search results.

Bools

These aren't vectorised, but can be used to filter search results.

Ints

These aren't vectorised, but can be used to filter search results.

Array

Currently, only arrays of strings are supported.

Array fields must not be a tensor field during index time, else an error will be thrown.

This type of field can be used to filter search results and for lexical search.

Example

# index an array field called "my_tags", making sure it is not a tensor field 
mq.index("my-index").add_documents(documents=[
    {"Title": "Cool summer t-shirt", "_id": "1234", 'my_tags': ['summer', 'yellow']}], 
    tensor_fields=['Title']
)

# do a search request that filters based on the tags
mq.index("my-index").search(
    q="Something to wear in warm weather",
    filter_string="(my_tags:yellow) AND (my_tags:summer)"
)

Multimodal combination object

The multimodal combination object works with mappings. This field can consist of multiple child fields. The contents of these child fields will be vectorized and combined into a single tensor using a weighted-sum approach. The weights are specified in mappings. Each child field must have an assigned weight.

The combined tensor will be used for tensor search. The multimodal combination field must be in tensor_fields.

Child fields can be used for lexical search or tensor search with filtering. All the child fields and child fields content must be str.

Note that only a single vector is generated for a multimodal combination object per document. No chunking is applied.

Example

# Create an index with "ViT-B/32" that can vectorise both text and images.
settings = {
    "treat_urls_and_pointers_as_images": True,
    "model": "ViT-B/32",
}

mq.create_index("my-index", **settings)

# We add the document into our index
mq.index("my-index").add_documents(
    documents=[
        {
            "_id": "111",
            "Title": "my document",
            "my_text_attribute_1": "Riding horse",
            "my_image_attribute_1": "https://raw.githubusercontent.com/marqo-ai/marqo/mainline/examples/ImageSearchGuide/data/image0.jpg",
        }
    ],
    tensor_fields=["combo_text_image"],
    mappings={
        "combo_text_image": {
            "type": "multimodal_combination",
            "weights": {"my_text_attribute_1": 0.5, "my_image_attribute_1": 0.5},
        }
    },
)

# tensor search
res = mq.index("my-index").search(q="Riding horse")

# lexical search
res = mq.index("my-index").search(
    q="Riding horse",
    search_method="LEXICAL",
)

# filter search
res = mq.index("my-index").search(
    q="Riding horse",
    filter_string="my_text_attribute_1:(Riding horse)",
)

Results

Here we have the search results for the filter search:

{
    "hits": [
        {
            "Title": "my document",
            "_highlights": [
                {
                    "combo_text_image": "{'my_text_attribute_1': 'Riding horse"
                    "'my_image_attribute_1': 'https://raw.githubusercontent.com/marqo-ai/marqo/mainline/examples/ImageSearchGuide/data/image0.jpg'}"
                }
            ],
            "_id": "111",
            "_score": 0.726511350523296,
            "my_image_attribute_1": "https://raw.githubusercontent.com/marqo-ai/marqo/mainline/examples/ImageSearchGuide/data/image0.jpg",
            "my_text_attribute_1": "Riding horse",
        }
    ],
    "limit": 10,
    "offset": 0,
    "processingTimeMs": 45,
    "query": "Riding horse",
}