|
26 | 26 | "metadata": {}, |
27 | 27 | "outputs": [], |
28 | 28 | "source": [ |
29 | | - "%pip install \"redisvl>=0.9.0\"" |
| 29 | + "%pip install \"redisvl>0.9.1\"" |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "code", |
| 34 | + "execution_count": null, |
| 35 | + "metadata": {}, |
| 36 | + "outputs": [], |
| 37 | + "source": [ |
| 38 | + "import redisvl\n", |
| 39 | + "# check version\n", |
| 40 | + "redisvl.__version__" |
30 | 41 | ] |
31 | 42 | }, |
32 | 43 | { |
|
119 | 130 | }, |
120 | 131 | { |
121 | 132 | "cell_type": "code", |
122 | | - "execution_count": null, |
| 133 | + "execution_count": 6, |
123 | 134 | "metadata": {}, |
124 | 135 | "outputs": [], |
125 | 136 | "source": [ |
|
131 | 142 | "REDIS_PASSWORD = os.getenv(\"REDIS_PASSWORD\", \"\") # ex: \"1TNxTEdYRDgIDKM2gDfasupCADXXXX\"\n", |
132 | 143 | "\n", |
133 | 144 | "# If SSL is enabled on the endpoint, use rediss:// as the URL prefix\n", |
134 | | - "REDIS_URL = f\"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}\"" |
| 145 | + "# REDIS_URL = f\"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}\"\n", |
| 146 | + "REDIS_URL = \"redis://localhost:6380\" # running redis 8 here" |
135 | 147 | ] |
136 | 148 | }, |
137 | 149 | { |
|
143 | 155 | }, |
144 | 156 | { |
145 | 157 | "cell_type": "code", |
146 | | - "execution_count": null, |
| 158 | + "execution_count": 7, |
147 | 159 | "metadata": {}, |
148 | | - "outputs": [], |
| 160 | + "outputs": [ |
| 161 | + { |
| 162 | + "data": { |
| 163 | + "text/plain": [ |
| 164 | + "True" |
| 165 | + ] |
| 166 | + }, |
| 167 | + "execution_count": 7, |
| 168 | + "metadata": {}, |
| 169 | + "output_type": "execute_result" |
| 170 | + } |
| 171 | + ], |
149 | 172 | "source": [ |
150 | 173 | "from redis import Redis\n", |
151 | 174 | "\n", |
|
155 | 178 | }, |
156 | 179 | { |
157 | 180 | "cell_type": "code", |
158 | | - "execution_count": null, |
| 181 | + "execution_count": 8, |
159 | 182 | "metadata": {}, |
160 | 183 | "outputs": [], |
161 | 184 | "source": [ |
|
182 | 205 | }, |
183 | 206 | { |
184 | 207 | "cell_type": "code", |
185 | | - "execution_count": null, |
| 208 | + "execution_count": 9, |
186 | 209 | "metadata": {}, |
187 | | - "outputs": [], |
| 210 | + "outputs": [ |
| 211 | + { |
| 212 | + "name": "stdout", |
| 213 | + "output_type": "stream", |
| 214 | + "text": [ |
| 215 | + "13:55:47 datasets INFO PyTorch version 2.3.0 available.\n", |
| 216 | + "13:55:48 sentence_transformers.SentenceTransformer INFO Use pytorch device_name: mps\n", |
| 217 | + "13:55:48 sentence_transformers.SentenceTransformer INFO Load pretrained SentenceTransformer: sentence-transformers/all-MiniLM-L6-v2\n", |
| 218 | + "13:55:50 sentence_transformers.SentenceTransformer INFO Use pytorch device_name: mps\n", |
| 219 | + "13:55:50 sentence_transformers.SentenceTransformer INFO Load pretrained SentenceTransformer: sentence-transformers/all-mpnet-base-v2\n", |
| 220 | + "13:55:51 sentence_transformers.SentenceTransformer INFO Use pytorch device_name: mps\n", |
| 221 | + "13:55:51 sentence_transformers.SentenceTransformer INFO Load pretrained SentenceTransformer: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2\n" |
| 222 | + ] |
| 223 | + } |
| 224 | + ], |
188 | 225 | "source": [ |
189 | 226 | "from redisvl.utils.vectorize import HFTextVectorizer\n", |
| 227 | + "from redisvl.extensions.cache.embeddings import EmbeddingsCache\n", |
190 | 228 | "\n", |
191 | 229 | "# Model 1: General purpose embeddings (what we used before)\n", |
192 | 230 | "general_model = HFTextVectorizer(\n", |
|
195 | 233 | " name=\"embedcache_general\",\n", |
196 | 234 | " ttl=600,\n", |
197 | 235 | " redis_client=client,\n", |
198 | | - " )\n", |
| 236 | + " ),\n", |
199 | 237 | " dtype=\"float64\"\n", |
200 | 238 | ")\n", |
201 | 239 | "\n", |
|
206 | 244 | " name=\"embedcache_movie\",\n", |
207 | 245 | " ttl=600,\n", |
208 | 246 | " redis_client=client,\n", |
209 | | - " )\n", |
| 247 | + " ),\n", |
210 | 248 | " dtype=\"float32\"\n", |
211 | 249 | ")\n", |
212 | 250 | "\n", |
|
217 | 255 | " name=\"embedcache_genre\",\n", |
218 | 256 | " ttl=600,\n", |
219 | 257 | " redis_client=client,\n", |
220 | | - " )\n", |
| 258 | + " ),\n", |
221 | 259 | " dtype=\"float32\"\n", |
222 | 260 | ")" |
223 | 261 | ] |
|
234 | 272 | }, |
235 | 273 | { |
236 | 274 | "cell_type": "code", |
237 | | - "execution_count": null, |
| 275 | + "execution_count": 10, |
238 | 276 | "metadata": {}, |
239 | | - "outputs": [], |
| 277 | + "outputs": [ |
| 278 | + { |
| 279 | + "name": "stdout", |
| 280 | + "output_type": "stream", |
| 281 | + "text": [ |
| 282 | + "Generating multiple embeddings for movies...\n", |
| 283 | + "Generated embeddings for 20 movies\n" |
| 284 | + ] |
| 285 | + } |
| 286 | + ], |
240 | 287 | "source": [ |
241 | 288 | "# Generate multiple embeddings for each movie\n", |
242 | 289 | "print(\"Generating multiple embeddings for movies...\")\n", |
|
256 | 303 | }, |
257 | 304 | { |
258 | 305 | "cell_type": "code", |
259 | | - "execution_count": null, |
| 306 | + "execution_count": 12, |
260 | 307 | "metadata": {}, |
261 | | - "outputs": [], |
| 308 | + "outputs": [ |
| 309 | + { |
| 310 | + "name": "stdout", |
| 311 | + "output_type": "stream", |
| 312 | + "text": [ |
| 313 | + "13:56:14 redisvl.index.index INFO Index already exists, overwriting.\n", |
| 314 | + "Multi-vector index created and populated successfully!\n" |
| 315 | + ] |
| 316 | + } |
| 317 | + ], |
262 | 318 | "source": [ |
263 | 319 | "from redisvl.schema import IndexSchema\n", |
264 | 320 | "from redisvl.index import SearchIndex\n", |
|
336 | 392 | }, |
337 | 393 | { |
338 | 394 | "cell_type": "code", |
339 | | - "execution_count": null, |
| 395 | + "execution_count": 13, |
340 | 396 | "metadata": {}, |
341 | | - "outputs": [], |
| 397 | + "outputs": [ |
| 398 | + { |
| 399 | + "name": "stdout", |
| 400 | + "output_type": "stream", |
| 401 | + "text": [ |
| 402 | + "1. The Incredibles \n", |
| 403 | + " Genre: comedy, Rating: 8\n", |
| 404 | + " Description: A family of undercover superheroes, while trying to live the quiet suburban life, are forced into ac...\n", |
| 405 | + "\n", |
| 406 | + "2. The Avengers \n", |
| 407 | + " Genre: action, Rating: 8\n", |
| 408 | + " Description: Earth's mightiest heroes come together to stop an alien invasion that threatens the entire planet....\n", |
| 409 | + "\n", |
| 410 | + "3. Mad Max: Fury Road \n", |
| 411 | + " Genre: action, Rating: 8\n", |
| 412 | + " Description: In a post-apocalyptic wasteland, Max teams up with Furiosa to escape a tyrant's clutches and find fr...\n", |
| 413 | + "\n", |
| 414 | + "4. John Wick \n", |
| 415 | + " Genre: action, Rating: 8\n", |
| 416 | + " Description: A retired hitman seeks vengeance against those who wronged him, leaving a trail of destruction in hi...\n", |
| 417 | + "\n", |
| 418 | + "5. The Dark Knight \n", |
| 419 | + " Genre: action, Rating: 9\n", |
| 420 | + " Description: Batman faces off against the Joker, a criminal mastermind who threatens to plunge Gotham into chaos....\n", |
| 421 | + "\n" |
| 422 | + ] |
| 423 | + } |
| 424 | + ], |
342 | 425 | "source": [ |
343 | | - "from redisvl.query import Vector\n", |
| 426 | + "from redisvl.query import Vector, MultiVectorQuery\n", |
344 | 427 | "query_text = \"action movie with superheroes and explosions\"\n", |
345 | 428 | "\n", |
| 429 | + "num_results = 5\n", |
| 430 | + "\n", |
346 | 431 | "# Create Vector objects for each embedding model\n", |
347 | 432 | "query_vectors = [\n", |
348 | 433 | " Vector(\n", |
|
390 | 475 | }, |
391 | 476 | { |
392 | 477 | "cell_type": "code", |
393 | | - "execution_count": null, |
| 478 | + "execution_count": 14, |
394 | 479 | "metadata": {}, |
395 | 480 | "outputs": [], |
396 | 481 | "source": [ |
397 | 482 | "# clean up!\n", |
398 | | - "index.delete()" |
| 483 | + "multi_vector_index.delete()" |
399 | 484 | ] |
400 | 485 | } |
401 | 486 | ], |
402 | 487 | "metadata": { |
403 | 488 | "kernelspec": { |
404 | | - "display_name": "redis-ai-res", |
| 489 | + "display_name": "3.11.9", |
405 | 490 | "language": "python", |
406 | 491 | "name": "python3" |
407 | 492 | }, |
|
0 commit comments