Open In Colab

Anyscale Embeddings#

If you’re opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.

!pip install llama-index
from llama_index import ServiceContext, set_global_service_context
from llama_index.embeddings import AnyscaleEmbedding
from llama_index.llms import Anyscale

embed_model = AnyscaleEmbedding(
    api_key=ANYSCALE_ENDPOINT_TOKEN, embed_batch_size=10
)

service_context = ServiceContext.from_defaults(
    llm=Anyscale(api_key=ANYSCALE_ENDPOINT_TOKEN), embed_model=embed_model
)

# optionally set a global service context
set_global_service_context(service_context)
# Basically embedding example
embeddings = embed_model.get_text_embedding(
    "It is raining cats and dogs here!"
)
print(len(embeddings), embeddings[:10])