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.
In [ ]:
Copied!
%pip install llama-index-embeddings-nebius
%pip install llama-index-embeddings-nebius
In [ ]:
Copied!
!pip install llama-index
!pip install llama-index
Insert your Nebius AI Studio key below. You can get it by registering for free at Nebius AI Studio and issuing the key at API Keys section."
In [ ]:
Copied!
NEBIUS_API_KEY = ""
NEBIUS_API_KEY = ""
Now let's get embeddings using Nebius AI Studio
In [ ]:
Copied!
from llama_index.embeddings.nebius import NebiusEmbedding
embed_model = NebiusEmbedding(api_key=NEBIUS_API_KEY)
from llama_index.embeddings.nebius import NebiusEmbedding
embed_model = NebiusEmbedding(api_key=NEBIUS_API_KEY)
Basic usage¶
In [ ]:
Copied!
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")
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")
4096 [-0.002410888671875, 0.0083770751953125, -0.00542449951171875, 0.007366180419921875, -0.022216796875]
Asynchronous usage¶
In [ ]:
Copied!
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")
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")
4096 [-0.002410888671875, 0.0083770751953125, -0.00542449951171875, 0.007366180419921875, -0.022216796875]
Batched usage¶
In [ ]:
Copied!
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")
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")
[-0.0003886222839355469, 0.0004887580871582031, 0.011199951171875] [-0.003734588623046875, 0.01143646240234375, 0.008758544921875] [0.005901336669921875, 0.005161285400390625, 0.00142669677734375] [-0.00946807861328125, -0.0048675537109375, 0.004817962646484375]
Async batched usage¶
In [ ]:
Copied!
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")
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")
[-0.0003886222839355469, 0.0004887580871582031, 0.011199951171875] [-0.003734588623046875, 0.01143646240234375, 0.008758544921875] [0.005901336669921875, 0.005161285400390625, 0.00142669677734375] [-0.00946807861328125, -0.0048675537109375, 0.004817962646484375]