Structured Indexes with Other Features
For documentation on structured indexes see here.
Available Data Types and Features
The specification for all available data types and features can be found here.
Example structured index with multiple fields and features
The following example shows how to create a structured index with multiple fields and features.
import marqo
settings = {
"type": "structured",
"model": "open_clip/ViT-L-14/laion2b_s32b_b82k",
"allFields": [
{"name": "name", "type": "text", "features": ["lexical_search"]},
{"name": "description", "type": "text"},
{"name": "is_nsfw", "type": "bool", "features": ["filter"]},
{"name": "price", "type": "float", "features": ["filter"]},
{"name": "tags", "type": "array<text>", "features": ["filter"]},
{"name": "image_url", "type": "image_pointer"},
{"name": "seller_score", "type": "float", "features": ["score_modifier"]},
{
"name": "multimodal_field",
"type": "multimodal_combination",
"dependentFields": {"image_url": 0.9, "name": 0.1},
},
],
"tensorFields": ["multimodal_field"],
}
mq = marqo.Client(url="http://localhost:8882")
mq.create_index("my-complex-index", settings_dict=settings)
This example represents a more realistic system which allows for more complex behaviours such as filtering, score modification and multimodal search.
Example Add Documents Usage
documents = [
{
"_id": "1",
"name": "Marqo T-Shirt",
"description": "A high-quality t-shirt with the Marqo logo.",
"is_nsfw": False,
"price": 19.99,
"tags": ["clothing", "t-shirt", "merchandise"],
"image_url": "https://my-image-store.com/marqo-t-shirt.jpg",
"seller_score": 0.8,
},
{
"_id": "2",
"name": "Marqo Hoodie",
"description": "A high-quality hoodie with the Marqo logo.",
"is_nsfw": False,
"price": 39.99,
"tags": ["clothing", "hoodie", "merchandise"],
"image_url": "https://my-image-store.com/marqo-hoodie.jpg",
"seller_score": 0.9,
},
]
mq.index("my-complex-index").add_documents(documents)
Example Search Usage
Basic Search:
results = mq.index("my-complex-index").search(q="Marqo T-Shirt")
Search with Filtering:
results = mq.index("my-complex-index").search(
q="Marqo T-Shirt", filter_string="tags:hoodie"
)
Search with Score Modification:
mq.index("my-complex-index").search(
q="Marqo T-Shirt",
score_modifiers={"add_to_score": [{"field_name": "seller_score", "weight": 0.01}]},
)