|
6 | 6 | "source": [ |
7 | 7 | "# Threshold Optimization\n", |
8 | 8 | "\n", |
9 | | - "After setting up `SemanticRouter` or `SemanticCache` it best to tune the `distance_threshold` to get the best performance out of your system. RedisVL provides helper classes to make this light weight optimization easy.\n", |
| 9 | + "After setting up `SemanticRouter` or `SemanticCache` it's best to tune the `distance_threshold` to get the most performance out of your system. RedisVL provides helper classes to make this light weight optimization easy.\n", |
| 10 | + "\n", |
| 11 | + "> **Note:** Threshold optimization relies on `python > 3.9.`\n", |
10 | 12 | "\n", |
11 | 13 | "# CacheThresholdOptimizer\n", |
12 | 14 | "\n", |
|
53 | 55 | " 'prompt': 'what is the capital of france?',\n", |
54 | 56 | " 'response': 'paris',\n", |
55 | 57 | " 'vector_distance': 0.421104669571,\n", |
56 | | - " 'inserted_at': 1741033054.9,\n", |
57 | | - " 'updated_at': 1741033054.9,\n", |
| 58 | + " 'inserted_at': 1741039231.99,\n", |
| 59 | + " 'updated_at': 1741039231.99,\n", |
58 | 60 | " 'key': 'sem_cache:c990cc06e5e77570e5f03360426d2b7f947cbb5a67daa8af8164bfe0b3e24fe3'}]" |
59 | 61 | ] |
60 | 62 | }, |
|
112 | 114 | } |
113 | 115 | ], |
114 | 116 | "source": [ |
115 | | - "from redisvl.utils.threshold_optimizer.cache import CacheThresholdOptimizer\n", |
| 117 | + "from redisvl.utils.optimize import CacheThresholdOptimizer\n", |
116 | 118 | "\n", |
117 | 119 | "test_data = [\n", |
118 | 120 | " {\n", |
|
181 | 183 | " 'prompt': 'what is the capital of france?',\n", |
182 | 184 | " 'response': 'paris',\n", |
183 | 185 | " 'vector_distance': 0.0835866332054,\n", |
184 | | - " 'inserted_at': 1741033054.9,\n", |
185 | | - " 'updated_at': 1741033054.9,\n", |
| 186 | + " 'inserted_at': 1741039231.99,\n", |
| 187 | + " 'updated_at': 1741039231.99,\n", |
186 | 188 | " 'key': 'sem_cache:c990cc06e5e77570e5f03360426d2b7f947cbb5a67daa8af8164bfe0b3e24fe3'}]" |
187 | 189 | ] |
188 | 190 | }, |
|
331 | 333 | "text": [ |
332 | 334 | "Route thresholds before: {'greeting': 0.5, 'farewell': 0.5} \n", |
333 | 335 | "\n", |
334 | | - "Eval metric F1: start 0.438, end 0.562 \n", |
335 | | - "Ending thresholds: {'greeting': 0.09239303792843903, 'farewell': 0.6535353535353534}\n" |
| 336 | + "Eval metric F1: start 0.438, end 0.719 \n", |
| 337 | + "Ending thresholds: {'greeting': 1.0858585858585856, 'farewell': 0.5545454545454545}\n" |
336 | 338 | ] |
337 | 339 | } |
338 | 340 | ], |
339 | 341 | "source": [ |
340 | | - "from redisvl.utils.threshold_optimizer.router import RouterThresholdOptimizer\n", |
| 342 | + "from redisvl.utils.optimize import RouterThresholdOptimizer\n", |
341 | 343 | "\n", |
342 | 344 | "print(f\"Route thresholds before: {router.route_thresholds} \\n\")\n", |
343 | 345 | "optimizer = RouterThresholdOptimizer(router, test_data)\n", |
|
0 commit comments