Back to Llama Index

Nebius Embeddings

docs/examples/embeddings/nebius.ipynb

0.14.212.2 KB
Original Source

<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/embeddings/nebius.ipynb" target="_parent"></a>

Nebius Embeddings

This notebook demonstrates how to use Nebius AI Studio Embeddings with LlamaIndex. Nebius AI Studio implements all state-of-the-art embeddings models, available for commercial use.

First, let's install LlamaIndex and dependencies of Nebius AI Studio.

python
%pip install llama-index-embeddings-nebius llama-index

Upload your Nebius AI Studio key from system variables below or simply insert it. You can get it by registering for free at Nebius AI Studio and issuing the key at API Keys section.

python
import os

NEBIUS_API_KEY = os.getenv("NEBIUS_API_KEY")  # NEBIUS_API_KEY = ""

Now let's get embeddings using Nebius AI Studio

python
from llama_index.embeddings.nebius import NebiusEmbedding

embed_model = NebiusEmbedding(api_key=NEBIUS_API_KEY)

Basic usage

python
text = "Everyone loves justice at another person's expense"
embeddings = embed_model.get_text_embedding(text)
assert len(embeddings) == 4096
print(len(embeddings), embeddings[:5], sep="\n")

Asynchronous usage

python
text = "Everyone loves justice at another person's expense"
embeddings = await embed_model.aget_text_embedding(text)
assert len(embeddings) == 4096
print(len(embeddings), embeddings[:5], sep="\n")

Batched usage

python
texts = [
    "As the hours pass",
    "I will let you know",
    "That I need to ask",
    "Before I'm alone",
]

embeddings = embed_model.get_text_embedding_batch(texts)
assert len(embeddings) == 4
assert len(embeddings[0]) == 4096
print(*[x[:3] for x in embeddings], sep="\n")

Async batched usage

python
texts = [
    "As the hours pass",
    "I will let you know",
    "That I need to ask",
    "Before I'm alone",
]

embeddings = await embed_model.aget_text_embedding_batch(texts)
assert len(embeddings) == 4
assert len(embeddings[0]) == 4096
print(*[x[:3] for x in embeddings], sep="\n")