Skip to content

Commit eccda3a

Browse files
authored
Feature/integration nebius (run-llama#16783)
1 parent f7dc9ef commit eccda3a

File tree

43 files changed

+2329
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2329
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
::: llama_index.embeddings.nebius
2+
options:
3+
members:
4+
- NebiusEmbedding
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
::: llama_index.llms.nebius
2+
options:
3+
members:
4+
- NebiusLLM
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
::: llama_index.multi_modal_llms.nebius
2+
options:
3+
members:
4+
- NebiusMultiModal
+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/docs/examples/embeddings/nebius.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"# Nebius Embeddings\n",
15+
"\n",
16+
"This notebook demonstrates how to use [Nebius AI Studio](https://studio.nebius.ai/) Embeddings with LlamaIndex. Nebius AI Studio implements all state-of-the-art embeddings models, available for commercial use."
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"First, let's install LlamaIndex and dependencies of Nebius AI Studio."
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": null,
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"%pip install llama-index-embeddings-nebius"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"!pip install llama-index"
42+
]
43+
},
44+
{
45+
"cell_type": "markdown",
46+
"metadata": {},
47+
"source": [
48+
"Insert your Nebius AI Studio key below. You can get it by registering for free at [Nebius AI Studio](https://auth.eu.nebius.com/ui/login) and issuing the key at [API Keys section](https://studio.nebius.ai/settings/api-keys).\""
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": null,
54+
"metadata": {},
55+
"outputs": [],
56+
"source": [
57+
"NEBIUS_API_KEY = \"\""
58+
]
59+
},
60+
{
61+
"cell_type": "markdown",
62+
"metadata": {},
63+
"source": [
64+
"Now let's get embeddings using Nebius AI Studio"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": null,
70+
"metadata": {},
71+
"outputs": [],
72+
"source": [
73+
"from llama_index.embeddings.nebius import NebiusEmbedding\n",
74+
"\n",
75+
"embed_model = NebiusEmbedding(api_key=NEBIUS_API_KEY)"
76+
]
77+
},
78+
{
79+
"cell_type": "markdown",
80+
"metadata": {},
81+
"source": [
82+
"### Basic usage"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": null,
88+
"metadata": {},
89+
"outputs": [
90+
{
91+
"name": "stdout",
92+
"output_type": "stream",
93+
"text": [
94+
"4096\n",
95+
"[-0.002410888671875, 0.0083770751953125, -0.00542449951171875, 0.007366180419921875, -0.022216796875]\n"
96+
]
97+
}
98+
],
99+
"source": [
100+
"text = \"Everyone loves justice at another person's expense\"\n",
101+
"embeddings = embed_model.get_text_embedding(text)\n",
102+
"assert len(embeddings) == 4096\n",
103+
"print(len(embeddings), embeddings[:5], sep=\"\\n\")"
104+
]
105+
},
106+
{
107+
"cell_type": "markdown",
108+
"metadata": {},
109+
"source": [
110+
"### Asynchronous usage"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": null,
116+
"metadata": {},
117+
"outputs": [
118+
{
119+
"name": "stdout",
120+
"output_type": "stream",
121+
"text": [
122+
"4096\n",
123+
"[-0.002410888671875, 0.0083770751953125, -0.00542449951171875, 0.007366180419921875, -0.022216796875]\n"
124+
]
125+
}
126+
],
127+
"source": [
128+
"text = \"Everyone loves justice at another person's expense\"\n",
129+
"embeddings = await embed_model.aget_text_embedding(text)\n",
130+
"assert len(embeddings) == 4096\n",
131+
"print(len(embeddings), embeddings[:5], sep=\"\\n\")"
132+
]
133+
},
134+
{
135+
"cell_type": "markdown",
136+
"metadata": {},
137+
"source": [
138+
"### Batched usage"
139+
]
140+
},
141+
{
142+
"cell_type": "code",
143+
"execution_count": null,
144+
"metadata": {},
145+
"outputs": [
146+
{
147+
"name": "stdout",
148+
"output_type": "stream",
149+
"text": [
150+
"[-0.0003886222839355469, 0.0004887580871582031, 0.011199951171875]\n",
151+
"[-0.003734588623046875, 0.01143646240234375, 0.008758544921875]\n",
152+
"[0.005901336669921875, 0.005161285400390625, 0.00142669677734375]\n",
153+
"[-0.00946807861328125, -0.0048675537109375, 0.004817962646484375]\n"
154+
]
155+
}
156+
],
157+
"source": [
158+
"texts = [\n",
159+
" \"As the hours pass\",\n",
160+
" \"I will let you know\",\n",
161+
" \"That I need to ask\",\n",
162+
" \"Before I'm alone\",\n",
163+
"]\n",
164+
"\n",
165+
"embeddings = embed_model.get_text_embedding_batch(texts)\n",
166+
"assert len(embeddings) == 4\n",
167+
"assert len(embeddings[0]) == 4096\n",
168+
"print(*[x[:3] for x in embeddings], sep=\"\\n\")"
169+
]
170+
},
171+
{
172+
"cell_type": "markdown",
173+
"metadata": {},
174+
"source": [
175+
"### Async batched usage"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"metadata": {},
182+
"outputs": [
183+
{
184+
"name": "stdout",
185+
"output_type": "stream",
186+
"text": [
187+
"[-0.0003886222839355469, 0.0004887580871582031, 0.011199951171875]\n",
188+
"[-0.003734588623046875, 0.01143646240234375, 0.008758544921875]\n",
189+
"[0.005901336669921875, 0.005161285400390625, 0.00142669677734375]\n",
190+
"[-0.00946807861328125, -0.0048675537109375, 0.004817962646484375]\n"
191+
]
192+
}
193+
],
194+
"source": [
195+
"texts = [\n",
196+
" \"As the hours pass\",\n",
197+
" \"I will let you know\",\n",
198+
" \"That I need to ask\",\n",
199+
" \"Before I'm alone\",\n",
200+
"]\n",
201+
"\n",
202+
"embeddings = await embed_model.aget_text_embedding_batch(texts)\n",
203+
"assert len(embeddings) == 4\n",
204+
"assert len(embeddings[0]) == 4096\n",
205+
"print(*[x[:3] for x in embeddings], sep=\"\\n\")"
206+
]
207+
}
208+
],
209+
"metadata": {
210+
"kernelspec": {
211+
"display_name": "Python 3 (ipykernel)",
212+
"language": "python",
213+
"name": "python3"
214+
},
215+
"language_info": {
216+
"codemirror_mode": {
217+
"name": "ipython",
218+
"version": 3
219+
},
220+
"file_extension": ".py",
221+
"mimetype": "text/x-python",
222+
"name": "python",
223+
"nbconvert_exporter": "python",
224+
"pygments_lexer": "ipython3"
225+
}
226+
},
227+
"nbformat": 4,
228+
"nbformat_minor": 4
229+
}

0 commit comments

Comments
 (0)