Save a dynamic knowledge base configuration.

    :param kb_id: the id
    :param field: the field where values are extracted
    :param expression: ..using this expression
    :param collection: ..in a certain collection (default is all)

def save_kb_dyn_config(kb_id, field, expression, collection=None):
    """Save a dynamic knowledge base configuration.

    :param kb_id: the id
    :param field: the field where values are extracted
    :param expression: ..using this expression
    :param collection: ..in a certain collection (default is all)
    """
    # check that collection exists
    if collection:
        collection = Collection.query.filter_by(name=collection).one()

    kb = get_kb_by_id(kb_id)
    kb.set_dyn_config(field, expression, collection)