Prerequisites
- Create an API key for authentication.
-
Save the API key to an environment variable:
-
Install LlamaIndex packages:
Prepare a script
-
Copy the following part of the script:
-
Add one of the following methods, depending on your use case:
Use case Description How to implement Regular request Get a vector for a text. Call the embed_model.get_text_embedding(<text>)
method and print its output asprint(embeddings[:5], sep="\n").
Asynchronous request Get a vector asynchronously, so methods that follow your request do not wait for the response. Call the await embed_model.aget_text_embedding(<text>)
method.Batch of texts Get vectors for several texts. Call the embed_model.get_text_embedding_batch(texts)
method wheretexts
is an array of strings. Next, print vectors asprint(*[x[:3] for x in embeddings], sep="\n").
Asynchronous request with a batch of texts Get vectors for several texts asynchronously. Call the await embed_model.aget_text_embedding_batch(texts)
method wheretexts
is an array of strings.