def test_search_index_commands_standalone(collection: Collection) -> None:
    """Tests create, update, and drop index utility functions."""
    index_name = VECTOR_INDEX_NAME
    dimensions = DIMENSIONS
    path = "embedding"
    similarity = "cosine"
    filters: Optional[List[str]] = None
    wait_until_complete = TIMEOUT

    for index_info in collection.list_search_indexes():
        index.drop_vector_search_index(
            collection, index_info["name"], wait_until_complete=wait_until_complete
        )
    assert len(list(collection.list_search_indexes())) == 0

    # Create a Vector Search Index on index_name
    index.create_vector_search_index(
        collection=collection,
        index_name=index_name,
        dimensions=dimensions,
        path=path,
        similarity=similarity,
        filters=filters,
        wait_until_complete=wait_until_complete,
    )

    indexes = list(collection.list_search_indexes())
    assert len(indexes) == 1
    assert indexes[0]["name"] == index_name

    # Update that index by adding a filter
    # This will additionally index the "bar" and "foo"  fields
    # The Update method is not yet supported in Atlas Local.
    if "mongodb+srv" in os.environ.get("MONGODB_URI"):
        new_similarity = "euclidean"
        index.update_vector_search_index(
            collection=collection,
            index_name=index_name,
            dimensions=DIMENSIONS,
            path="embedding",
            similarity=new_similarity,
            filters=[FILTER_FIELD_NAME],
            wait_until_complete=wait_until_complete,
        )

        indexes = list(collection.list_search_indexes())
        assert len(indexes) == 1
        assert indexes[0]["name"] == index_name
        fields = indexes[0]["latestDefinition"]["fields"]
        assert len(fields) == 2
        assert {"type": "filter", "path": FILTER_FIELD_NAME} in fields
        assert {
            "numDimensions": DIMENSIONS,
            "path": "embedding",
            "similarity": f"{new_similarity}",
            "type": "vector",
        } in fields

    # Now add a full-text search index for the filter field
    index.create_fulltext_search_index(
        collection=collection,
        index_name=FULLTEXT_INDEX_NAME,
        field=FILTER_FIELD_NAME,
        field_type=FILTER_FIELD_TYPE,
        wait_until_complete=TIMEOUT,
    )

    indexes = list(collection.list_search_indexes())
    assert len(indexes) == 2
    assert any(idx["name"] == FULLTEXT_INDEX_NAME for idx in indexes)
    idx_fulltext = (
        indexes[0] if indexes[0]["name"] == FULLTEXT_INDEX_NAME else indexes[1]
    )
    assert idx_fulltext["type"] == "search"
    fields = idx_fulltext["latestDefinition"]["mappings"]["fields"]
    assert fields[FILTER_FIELD_NAME]["type"] == FILTER_FIELD_TYPE

    # Finally, drop the index
    for name in [FULLTEXT_INDEX_NAME, VECTOR_INDEX_NAME]:
        index.drop_vector_search_index(
            collection, name, wait_until_complete=wait_until_complete
        )

    indexes = list(collection.list_search_indexes())
    for idx in indexes:
        assert idx["status"] == "DELETING"
Tests create, update, and drop index utility functions.
llama-index-integrations/vector_stores/llama-index-vector-stores-mongodb/tests/test_index_commands.py