How to use Cosine Distance matrix for Clustering algorithms like mean-shift, DBSCAN, and optics?
Each of those selected clustering algorithms can be fit using cosine distances in scikit-learn:

from sklearn.cluster import DBSCAN, MeanShift, OPTICS
from sklearn.metrics.pairwise import cosine_distances

# Define clustering algorithms
algorithms = [DBSCAN, MeanShift, OPTICS]

# Placeholder for results
results = dict.fromkeys((a.__name__ for a in algorithms))

# Fit each clustering algorithm and store results
for algorithm in algorithms:
    results[algorithm] = algorithm(metric=cosine_distances).fit(X)