Use CacheBackedEmbedding class to manage the embeddings. You must avoid hash collisions as a common file system-based cache will be used for multiple models.
from langchain_community.embeddings import CohereEmbeddings
# Create the embeddings model
model_name = "embed-english-light-v3.0"
corpus = [
"A man is eating food.",
"A man is eating a piece of bread.",
"The girl is carrying a baby.",
"A man is riding a horse.",
"A woman is playing violin.",
"Two men pushed carts through the woods.",
"A man is riding a white horse on an enclosed ground.",
"A monkey is playing drums.",
"A cheetah is running behind its prey.",
]
The solution to the exercise is available in section#2 and #3 in the notebook: