|
171 | 171 | {
|
172 | 172 | "data": {
|
173 | 173 | "text/plain": [
|
174 |
| - "RouteMatch(name='technology', distance=0.119614183903)" |
| 174 | + "RouteMatch(name='technology', distance=0.119614243507)" |
175 | 175 | ]
|
176 | 176 | },
|
177 | 177 | "execution_count": 5,
|
|
244 | 244 | {
|
245 | 245 | "data": {
|
246 | 246 | "text/plain": [
|
247 |
| - "[RouteMatch(name='sports', distance=0.758580672741),\n", |
248 |
| - " RouteMatch(name='entertainment', distance=0.812423805396),\n", |
249 |
| - " RouteMatch(name='technology', distance=0.884235262871)]" |
| 247 | + "[RouteMatch(name='sports', distance=0.758580708504),\n", |
| 248 | + " RouteMatch(name='entertainment', distance=0.812423825264),\n", |
| 249 | + " RouteMatch(name='technology', distance=0.88423516353)]" |
250 | 250 | ]
|
251 | 251 | },
|
252 | 252 | "execution_count": 8,
|
|
268 | 268 | {
|
269 | 269 | "data": {
|
270 | 270 | "text/plain": [
|
271 |
| - "[RouteMatch(name='sports', distance=0.663254022598),\n", |
272 |
| - " RouteMatch(name='entertainment', distance=0.712985336781),\n", |
273 |
| - " RouteMatch(name='technology', distance=0.832674443722)]" |
| 271 | + "[RouteMatch(name='sports', distance=0.663253903389),\n", |
| 272 | + " RouteMatch(name='entertainment', distance=0.712985396385),\n", |
| 273 | + " RouteMatch(name='technology', distance=0.832674384117)]" |
274 | 274 | ]
|
275 | 275 | },
|
276 | 276 | "execution_count": 9,
|
|
321 | 321 | {
|
322 | 322 | "data": {
|
323 | 323 | "text/plain": [
|
324 |
| - "[RouteMatch(name='sports', distance=0.663254022598),\n", |
325 |
| - " RouteMatch(name='entertainment', distance=0.712985336781),\n", |
326 |
| - " RouteMatch(name='technology', distance=0.832674443722)]" |
| 324 | + "[RouteMatch(name='sports', distance=0.663253903389),\n", |
| 325 | + " RouteMatch(name='entertainment', distance=0.712985396385),\n", |
| 326 | + " RouteMatch(name='technology', distance=0.832674384117)]" |
327 | 327 | ]
|
328 | 328 | },
|
329 | 329 | "execution_count": 11,
|
|
340 | 340 | "cell_type": "markdown",
|
341 | 341 | "metadata": {},
|
342 | 342 | "source": [
|
343 |
| - "## Clean up the router" |
| 343 | + "## Router serialization" |
344 | 344 | ]
|
345 | 345 | },
|
346 | 346 | {
|
347 | 347 | "cell_type": "code",
|
348 | 348 | "execution_count": 12,
|
349 | 349 | "metadata": {},
|
| 350 | + "outputs": [ |
| 351 | + { |
| 352 | + "data": { |
| 353 | + "text/plain": [ |
| 354 | + "{'name': 'topic-router',\n", |
| 355 | + " 'routes': [{'name': 'technology',\n", |
| 356 | + " 'references': ['what are the latest advancements in AI?',\n", |
| 357 | + " 'tell me about the newest gadgets',\n", |
| 358 | + " \"what's trending in tech?\"],\n", |
| 359 | + " 'metadata': {'category': 'tech', 'priority': '1'}},\n", |
| 360 | + " {'name': 'sports',\n", |
| 361 | + " 'references': ['who won the game last night?',\n", |
| 362 | + " 'tell me about the upcoming sports events',\n", |
| 363 | + " \"what's the latest in the world of sports?\",\n", |
| 364 | + " 'sports',\n", |
| 365 | + " 'basketball and football'],\n", |
| 366 | + " 'metadata': {'category': 'sports', 'priority': '2'}},\n", |
| 367 | + " {'name': 'entertainment',\n", |
| 368 | + " 'references': ['what are the top movies right now?',\n", |
| 369 | + " 'who won the best actor award?',\n", |
| 370 | + " \"what's new in the entertainment industry?\"],\n", |
| 371 | + " 'metadata': {'category': 'entertainment', 'priority': '3'}}],\n", |
| 372 | + " 'vectorizer': {'type': 'hf',\n", |
| 373 | + " 'model': 'sentence-transformers/all-mpnet-base-v2'},\n", |
| 374 | + " 'routing_config': {'distance_threshold': 1.0,\n", |
| 375 | + " 'max_k': 3,\n", |
| 376 | + " 'aggregation_method': 'min'}}" |
| 377 | + ] |
| 378 | + }, |
| 379 | + "execution_count": 12, |
| 380 | + "metadata": {}, |
| 381 | + "output_type": "execute_result" |
| 382 | + } |
| 383 | + ], |
| 384 | + "source": [ |
| 385 | + "router.to_dict()" |
| 386 | + ] |
| 387 | + }, |
| 388 | + { |
| 389 | + "cell_type": "code", |
| 390 | + "execution_count": 13, |
| 391 | + "metadata": {}, |
| 392 | + "outputs": [ |
| 393 | + { |
| 394 | + "name": "stdout", |
| 395 | + "output_type": "stream", |
| 396 | + "text": [ |
| 397 | + "15:16:28 redisvl.index.index INFO Index already exists, not overwriting.\n" |
| 398 | + ] |
| 399 | + } |
| 400 | + ], |
| 401 | + "source": [ |
| 402 | + "router2 = SemanticRouter.from_dict(router.to_dict(), redis_url=\"redis://localhost:6379\")\n", |
| 403 | + "\n", |
| 404 | + "assert router2 == router" |
| 405 | + ] |
| 406 | + }, |
| 407 | + { |
| 408 | + "cell_type": "code", |
| 409 | + "execution_count": 14, |
| 410 | + "metadata": {}, |
| 411 | + "outputs": [], |
| 412 | + "source": [ |
| 413 | + "router.to_yaml(\"router.yaml\", overwrite=True)" |
| 414 | + ] |
| 415 | + }, |
| 416 | + { |
| 417 | + "cell_type": "code", |
| 418 | + "execution_count": 16, |
| 419 | + "metadata": {}, |
| 420 | + "outputs": [ |
| 421 | + { |
| 422 | + "name": "stdout", |
| 423 | + "output_type": "stream", |
| 424 | + "text": [ |
| 425 | + "15:17:42 redisvl.index.index INFO Index already exists, not overwriting.\n" |
| 426 | + ] |
| 427 | + } |
| 428 | + ], |
| 429 | + "source": [ |
| 430 | + "router3 = SemanticRouter.from_yaml(\"router.yaml\", redis_url=\"redis://localhost:6379\")\n", |
| 431 | + "\n", |
| 432 | + "assert router3 == router2 == router" |
| 433 | + ] |
| 434 | + }, |
| 435 | + { |
| 436 | + "cell_type": "markdown", |
| 437 | + "metadata": {}, |
| 438 | + "source": [ |
| 439 | + "## Clean up the router" |
| 440 | + ] |
| 441 | + }, |
| 442 | + { |
| 443 | + "cell_type": "code", |
| 444 | + "execution_count": 17, |
| 445 | + "metadata": {}, |
350 | 446 | "outputs": [],
|
351 | 447 | "source": [
|
352 | 448 | "# Use clear to flush all routes from the index\n",
|
|
355 | 451 | },
|
356 | 452 | {
|
357 | 453 | "cell_type": "code",
|
358 |
| - "execution_count": 13, |
| 454 | + "execution_count": 18, |
359 | 455 | "metadata": {},
|
360 | 456 | "outputs": [],
|
361 | 457 | "source": [
|
|
0 commit comments