Search code examples
pythonvectorvespamarqo

How do I delete all documents from a Marqo index?


I have a ton of documents that have been vectorized poorly / are using an old multimodal_field_combination.

mappings={
    'combo_text_image': {
        "type": "multimodal_combination",
        "weights": {
            "name": 0.05,
            "description": 0.15,
            "image_url": 0.8
        }
    }
},

But I need to update to

mappings={
    'combo_text_image': {
        "type": "multimodal_combination",
        "weights": {
            "name": 0.2,
            "image_url": 0.8
        }
    }
},

I've realized that to do this in the same index, I should delete the documents and then reindex but I haven't been able to find a mq.delete_all_documents() call. What's the best way to do this?


Solution

  • Here is a code snippet that would delete all documents from the index:

    def empty_index(index_name):
        index = mq.index(index_name)
        res =  index.search(q = '', limit=400)
        while len(res['hits']) > 0:
            id_set = []
            for hit in res['hits']:
                id_set.append(hit['_id'])
            index.delete_documents(id_set)
            res = index.search(q = '', limit=400)