Negative example (slow and rate-limited)
Source: openai_cookbooks

## Using embeddingsThis notebook contains some helpful snippets you can use to embed text with the `text-embedding-3-small` model via the OpenAI API.```pythonfrom openai import OpenAIclient = OpenAI()embedding = client.embeddings.create(    input="Your text goes here", model="text-embedding-3-small").data[0].embeddinglen(embedding)```    1536It's recommended to use the 'tenacity' package or another exponential backoff implementation to better manage API rate limits, as hitting the API too much too fast can trigger rate limits. Using the following function ensures you get your embeddings as fast as possible.```python# Negative example (slow and rate-limited)from openai import OpenAIclient = OpenAI()num_embeddings = 10000 # Some large numberfor i in range(num_embeddings):    embedding = client.embeddings.create(        input="Your text goes here", model="text-embedding-3-small"    ).data[0].embedding    print(len(embedding))``````python# Best practicefrom tenacity import retry, wait_random_exponential, stop_after_attemptfrom openai import OpenAIclient = OpenAI()# Retry up to 6 times with exponential backoff, starting at 1 second and maxing out at 20 seconds delay@retry(wait=wait_random_exponential(min=1, max=20), stop=stop_after_attempt(6))def get_embedding(text: str, model="text-embedding-3-small") -> list[float]:    return client.embeddings.create(input=[text], model=model).data[0].embeddingembedding = get_embedding("Your text goes here", model="text-embedding-3-small")print(len(embedding))```    1536