|
21 | 21 | { |
22 | 22 | "metadata": { |
23 | 23 | "ExecuteTime": { |
24 | | - "end_time": "2025-11-15T01:55:41.800439Z", |
25 | | - "start_time": "2025-11-15T01:55:38.869222Z" |
| 24 | + "end_time": "2025-11-22T07:10:04.327797Z", |
| 25 | + "start_time": "2025-11-22T07:10:01.111867Z" |
26 | 26 | } |
27 | 27 | }, |
28 | 28 | "cell_type": "code", |
|
46 | 46 | ] |
47 | 47 | } |
48 | 48 | ], |
49 | | - "execution_count": 1 |
| 49 | + "execution_count": 5 |
50 | 50 | }, |
51 | 51 | { |
52 | 52 | "metadata": {}, |
|
64 | 64 | { |
65 | 65 | "metadata": { |
66 | 66 | "ExecuteTime": { |
67 | | - "end_time": "2025-11-15T01:55:41.806781Z", |
68 | | - "start_time": "2025-11-15T01:55:41.804858Z" |
| 67 | + "end_time": "2025-11-22T07:10:04.339135Z", |
| 68 | + "start_time": "2025-11-22T07:10:04.337286Z" |
69 | 69 | } |
70 | 70 | }, |
71 | 71 | "cell_type": "code", |
|
86 | 86 | ] |
87 | 87 | } |
88 | 88 | ], |
89 | | - "execution_count": 2 |
| 89 | + "execution_count": 6 |
90 | 90 | }, |
91 | 91 | { |
92 | 92 | "metadata": {}, |
|
96 | 96 | { |
97 | 97 | "metadata": { |
98 | 98 | "ExecuteTime": { |
99 | | - "end_time": "2025-11-15T01:55:43.782562Z", |
100 | | - "start_time": "2025-11-15T01:55:41.813175Z" |
| 99 | + "end_time": "2025-11-22T07:10:04.351558Z", |
| 100 | + "start_time": "2025-11-22T07:10:04.349814Z" |
101 | 101 | } |
102 | 102 | }, |
103 | 103 | "cell_type": "code", |
|
111 | 111 | "\n", |
112 | 112 | "from langchain_redis import RedisCache, RedisSemanticCache, LangCacheSemanticCache" |
113 | 113 | ], |
114 | | - "outputs": [ |
115 | | - { |
116 | | - "name": "stderr", |
117 | | - "output_type": "stream", |
118 | | - "text": [ |
119 | | - "/Users/andrew.brookins/src/langchain-redis/libs/redis/env/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", |
120 | | - " from .autonotebook import tqdm as notebook_tqdm\n" |
121 | | - ] |
122 | | - } |
123 | | - ], |
124 | | - "execution_count": 3 |
| 114 | + "outputs": [], |
| 115 | + "execution_count": 7 |
125 | 116 | }, |
126 | 117 | { |
127 | 118 | "metadata": {}, |
|
131 | 122 | { |
132 | 123 | "metadata": { |
133 | 124 | "ExecuteTime": { |
134 | | - "end_time": "2025-11-15T01:55:43.825483Z", |
135 | | - "start_time": "2025-11-15T01:55:43.823677Z" |
| 125 | + "end_time": "2025-11-22T07:10:04.360419Z", |
| 126 | + "start_time": "2025-11-22T07:10:04.358547Z" |
136 | 127 | } |
137 | 128 | }, |
138 | 129 | "cell_type": "code", |
|
159 | 150 | ] |
160 | 151 | } |
161 | 152 | ], |
162 | | - "execution_count": 4 |
| 153 | + "execution_count": 8 |
163 | 154 | }, |
164 | 155 | { |
165 | 156 | "metadata": {}, |
|
169 | 160 | { |
170 | 161 | "metadata": { |
171 | 162 | "ExecuteTime": { |
172 | | - "end_time": "2025-11-15T01:55:44.767366Z", |
173 | | - "start_time": "2025-11-15T01:55:43.829967Z" |
| 163 | + "end_time": "2025-11-22T07:10:05.188067Z", |
| 164 | + "start_time": "2025-11-22T07:10:04.365151Z" |
174 | 165 | } |
175 | 166 | }, |
176 | 167 | "cell_type": "code", |
|
213 | 204 | "name": "stdout", |
214 | 205 | "output_type": "stream", |
215 | 206 | "text": [ |
216 | | - "17:55:44 httpx INFO HTTP Request: POST https://api.openai.com/v1/completions \"HTTP/1.1 200 OK\"\n", |
| 207 | + "23:10:05 httpx INFO HTTP Request: POST https://api.openai.com/v1/completions \"HTTP/1.1 200 OK\"\n", |
217 | 208 | "First call (not cached):\n", |
218 | 209 | "Result: \n", |
219 | 210 | "\n", |
220 | 211 | "Caching is the process of storing frequently accessed data in a temporary storage location for faster retrieval. This helps to reduce the time and resources needed to access the data from its original source. Caching is commonly used in computer systems, web browsers, and databases to improve performance and efficiency.\n", |
221 | | - "Time: 0.69 seconds\n", |
| 212 | + "Time: 0.68 seconds\n", |
222 | 213 | "\n", |
223 | 214 | "Second call (cached):\n", |
224 | 215 | "Result: \n", |
225 | 216 | "\n", |
226 | 217 | "Caching is the process of storing frequently accessed data in a temporary storage location for faster retrieval. This helps to reduce the time and resources needed to access the data from its original source. Caching is commonly used in computer systems, web browsers, and databases to improve performance and efficiency.\n", |
227 | 218 | "Time: 0.00 seconds\n", |
228 | 219 | "\n", |
229 | | - "Speed improvement: 483.60x faster\n", |
| 220 | + "Speed improvement: 525.11x faster\n", |
230 | 221 | "Cache cleared\n" |
231 | 222 | ] |
232 | 223 | } |
233 | 224 | ], |
234 | | - "execution_count": 5 |
| 225 | + "execution_count": 9 |
235 | 226 | }, |
236 | 227 | { |
237 | 228 | "metadata": {}, |
|
241 | 232 | { |
242 | 233 | "metadata": { |
243 | 234 | "ExecuteTime": { |
244 | | - "end_time": "2025-11-15T01:55:46.520639Z", |
245 | | - "start_time": "2025-11-15T01:55:44.787172Z" |
| 235 | + "end_time": "2025-11-22T07:10:07.296869Z", |
| 236 | + "start_time": "2025-11-22T07:10:05.206110Z" |
246 | 237 | } |
247 | 238 | }, |
248 | 239 | "cell_type": "code", |
|
288 | 279 | "name": "stdout", |
289 | 280 | "output_type": "stream", |
290 | 281 | "text": [ |
291 | | - "17:55:45 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
292 | | - "17:55:45 redisvl.index.index INFO Index already exists, not overwriting.\n", |
293 | | - "17:55:45 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
294 | | - "17:55:46 httpx INFO HTTP Request: POST https://api.openai.com/v1/completions \"HTTP/1.1 200 OK\"\n", |
295 | | - "17:55:46 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
| 282 | + "23:10:05 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
| 283 | + "23:10:05 redisvl.index.index INFO Index already exists, not overwriting.\n", |
| 284 | + "23:10:06 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
| 285 | + "23:10:06 httpx INFO HTTP Request: POST https://api.openai.com/v1/completions \"HTTP/1.1 200 OK\"\n", |
| 286 | + "23:10:06 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
296 | 287 | "Original query:\n", |
297 | 288 | "Prompt: What is the capital of France?\n", |
298 | 289 | "\n", |
299 | 290 | "Result: \n", |
300 | 291 | "\n", |
301 | 292 | "The capital of France is Paris.\n", |
302 | | - "Time: 1.18 seconds\n", |
| 293 | + "Time: 1.37 seconds\n", |
303 | 294 | "\n", |
304 | | - "17:55:46 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
| 295 | + "23:10:07 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
305 | 296 | "Similar query:\n", |
306 | 297 | "Prompt: Can you tell me the capital city of France?\n", |
307 | 298 | "\n", |
308 | 299 | "Result: \n", |
309 | 300 | "\n", |
310 | 301 | "The capital of France is Paris.\n", |
311 | | - "Time: 0.23 seconds\n", |
| 302 | + "Time: 0.39 seconds\n", |
312 | 303 | "\n", |
313 | | - "Speed improvement: 5.15x faster\n", |
| 304 | + "Speed improvement: 3.48x faster\n", |
314 | 305 | "Semantic cache cleared\n" |
315 | 306 | ] |
316 | 307 | } |
317 | 308 | ], |
318 | | - "execution_count": 6 |
| 309 | + "execution_count": 10 |
319 | 310 | }, |
320 | 311 | { |
321 | 312 | "metadata": {}, |
|
334 | 325 | { |
335 | 326 | "metadata": { |
336 | 327 | "ExecuteTime": { |
337 | | - "end_time": "2025-11-15T01:55:48.215662Z", |
338 | | - "start_time": "2025-11-15T01:55:46.538770Z" |
| 328 | + "end_time": "2025-11-22T07:10:09.664948Z", |
| 329 | + "start_time": "2025-11-22T07:10:07.313993Z" |
339 | 330 | } |
340 | 331 | }, |
341 | 332 | "cell_type": "code", |
|
364 | 355 | " print(\"Not running LangCache examples because we do not have an API key and cache ID.\")\n", |
365 | 356 | " exit(0)\n", |
366 | 357 | "\n", |
367 | | - "# Initialize LAngCacheSemanticCache\n", |
| 358 | + "# Initialize LangCacheSemanticCache\n", |
368 | 359 | "semantic_cache = LangCacheSemanticCache(\n", |
369 | 360 | " cache_id=langcache_cache_id,\n", |
370 | 361 | " api_key=langcache_api_key,\n", |
|
389 | 380 | "print(f\"Original query:\\nPrompt: {original_prompt}\\n\")\n", |
390 | 381 | "print(f\"Result: {result1}\\nTime: {time1:.2f} seconds\\n\")\n", |
391 | 382 | "\n", |
| 383 | + "\n", |
392 | 384 | "# Semantically similar query\n", |
393 | 385 | "similar_prompt = \"Can you tell me the capital city of France?\"\n", |
394 | 386 | "result2, time2 = test_semantic_cache(similar_prompt)\n", |
395 | 387 | "print(f\"Similar query:\\nPrompt: {similar_prompt}\\n\")\n", |
396 | 388 | "print(f\"Result: {result2}\\nTime: {time2:.2f} seconds\\n\")\n", |
397 | | - "\n", |
398 | | - "print(f\"Speed improvement: {time1 / time2:.2f}x faster\")\n", |
| 389 | + "print(f\"(Similar query) Speed improvement: {time1 / time2:.2f}x faster\")\n", |
399 | 390 | "\n", |
400 | 391 | "# Clear the semantic cache\n", |
401 | 392 | "semantic_cache.clear()\n", |
|
407 | 398 | "output_type": "stream", |
408 | 399 | "text": [ |
409 | 400 | "LangCache API key and cache ID found in environment variables.\n", |
410 | | - "17:55:46 httpx INFO HTTP Request: POST https://aws-us-east-1.langcache.redis.io/v1/caches/727a79865ac848c7900caabad5db1afe/entries/search \"HTTP/1.1 200 OK\"\n", |
411 | | - "17:55:47 httpx INFO HTTP Request: POST https://api.openai.com/v1/completions \"HTTP/1.1 200 OK\"\n", |
412 | | - "17:55:47 httpx INFO HTTP Request: POST https://aws-us-east-1.langcache.redis.io/v1/caches/727a79865ac848c7900caabad5db1afe/entries \"HTTP/1.1 201 Created\"\n", |
| 401 | + "23:10:07 httpx INFO HTTP Request: POST https://aws-us-east-1.langcache.redis.io/v1/caches/d0a1149ce793462c9a63ba3d1f7fa718/entries/search \"HTTP/1.1 200 OK\"\n", |
| 402 | + "23:10:09 httpx INFO HTTP Request: POST https://api.openai.com/v1/completions \"HTTP/1.1 200 OK\"\n", |
| 403 | + "23:10:09 httpx INFO HTTP Request: POST https://aws-us-east-1.langcache.redis.io/v1/caches/d0a1149ce793462c9a63ba3d1f7fa718/entries \"HTTP/1.1 201 Created\"\n", |
413 | 404 | "Original query:\n", |
414 | 405 | "Prompt: What is the capital of France?\n", |
415 | 406 | "\n", |
416 | 407 | "Result: \n", |
417 | 408 | "\n", |
418 | 409 | "The capital of France is Paris.\n", |
419 | | - "Time: 0.61 seconds\n", |
| 410 | + "Time: 2.02 seconds\n", |
420 | 411 | "\n", |
421 | | - "17:55:47 httpx INFO HTTP Request: POST https://aws-us-east-1.langcache.redis.io/v1/caches/727a79865ac848c7900caabad5db1afe/entries/search \"HTTP/1.1 200 OK\"\n", |
422 | | - "17:55:47 httpx INFO HTTP Request: POST https://api.openai.com/v1/completions \"HTTP/1.1 200 OK\"\n", |
423 | | - "17:55:47 httpx INFO HTTP Request: POST https://aws-us-east-1.langcache.redis.io/v1/caches/727a79865ac848c7900caabad5db1afe/entries \"HTTP/1.1 201 Created\"\n", |
| 412 | + "23:10:09 httpx INFO HTTP Request: POST https://aws-us-east-1.langcache.redis.io/v1/caches/d0a1149ce793462c9a63ba3d1f7fa718/entries/search \"HTTP/1.1 200 OK\"\n", |
424 | 413 | "Similar query:\n", |
425 | 414 | "Prompt: Can you tell me the capital city of France?\n", |
426 | 415 | "\n", |
427 | 416 | "Result: \n", |
428 | 417 | "\n", |
429 | | - "The capital city of France is Paris.\n", |
430 | | - "Time: 0.72 seconds\n", |
| 418 | + "The capital of France is Paris.\n", |
| 419 | + "Time: 0.15 seconds\n", |
431 | 420 | "\n", |
432 | | - "Speed improvement: 0.84x faster\n", |
433 | | - "17:55:48 httpx INFO HTTP Request: DELETE https://aws-us-east-1.langcache.redis.io/v1/caches/727a79865ac848c7900caabad5db1afe/entries \"HTTP/1.1 400 Bad Request\"\n" |
434 | | - ] |
435 | | - }, |
436 | | - { |
437 | | - "ename": "BadRequestErrorResponseContent", |
438 | | - "evalue": "{\"detail\":\"attributes: cannot be blank.\",\"status\":400,\"title\":\"Invalid Request\",\"type\":\"/errors/invalid-data\"}", |
439 | | - "output_type": "error", |
440 | | - "traceback": [ |
441 | | - "\u001B[31m---------------------------------------------------------------------------\u001B[39m", |
442 | | - "\u001B[31mBadRequestErrorResponseContent\u001B[39m Traceback (most recent call last)", |
443 | | - "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[7]\u001B[39m\u001B[32m, line 59\u001B[39m\n\u001B[32m 56\u001B[39m \u001B[38;5;28mprint\u001B[39m(\u001B[33mf\u001B[39m\u001B[33m\"\u001B[39m\u001B[33mSpeed improvement: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mtime1\u001B[38;5;250m \u001B[39m/\u001B[38;5;250m \u001B[39mtime2\u001B[38;5;132;01m:\u001B[39;00m\u001B[33m.2f\u001B[39m\u001B[38;5;132;01m}\u001B[39;00m\u001B[33mx faster\u001B[39m\u001B[33m\"\u001B[39m)\n\u001B[32m 58\u001B[39m \u001B[38;5;66;03m# Clear the semantic cache\u001B[39;00m\n\u001B[32m---> \u001B[39m\u001B[32m59\u001B[39m \u001B[43msemantic_cache\u001B[49m\u001B[43m.\u001B[49m\u001B[43mclear\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 60\u001B[39m \u001B[38;5;28mprint\u001B[39m(\u001B[33m\"\u001B[39m\u001B[33mSemantic cache cleared\u001B[39m\u001B[33m\"\u001B[39m)\n", |
444 | | - "\u001B[36mFile \u001B[39m\u001B[32m~/src/langchain-redis/libs/redis/langchain_redis/cache.py:858\u001B[39m, in \u001B[36mLangCacheSemanticCache.clear\u001B[39m\u001B[34m(self, **kwargs)\u001B[39m\n\u001B[32m 856\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mclear\u001B[39m(\u001B[38;5;28mself\u001B[39m, **kwargs: Any) -> \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[32m 857\u001B[39m \u001B[38;5;250m \u001B[39m\u001B[33;03m\"\"\"Clear all entries via the wrapper's clear API.\"\"\"\u001B[39;00m\n\u001B[32m--> \u001B[39m\u001B[32m858\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mcache\u001B[49m\u001B[43m.\u001B[49m\u001B[43mclear\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n", |
445 | | - "\u001B[36mFile \u001B[39m\u001B[32m~/src/langchain-redis/libs/redis/env/lib/python3.11/site-packages/redisvl/extensions/cache/llm/langcache.py:557\u001B[39m, in \u001B[36mLangCacheSemanticCache.clear\u001B[39m\u001B[34m(self)\u001B[39m\n\u001B[32m 552\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mclear\u001B[39m(\u001B[38;5;28mself\u001B[39m) -> \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[32m 553\u001B[39m \u001B[38;5;250m \u001B[39m\u001B[33;03m\"\"\"Clear the cache of all entries.\u001B[39;00m\n\u001B[32m 554\u001B[39m \n\u001B[32m 555\u001B[39m \u001B[33;03m This is an alias for delete() to match the BaseCache interface.\u001B[39;00m\n\u001B[32m 556\u001B[39m \u001B[33;03m \"\"\"\u001B[39;00m\n\u001B[32m--> \u001B[39m\u001B[32m557\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mdelete\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n", |
446 | | - "\u001B[36mFile \u001B[39m\u001B[32m~/src/langchain-redis/libs/redis/env/lib/python3.11/site-packages/redisvl/extensions/cache/llm/langcache.py:542\u001B[39m, in \u001B[36mLangCacheSemanticCache.delete\u001B[39m\u001B[34m(self)\u001B[39m\n\u001B[32m 536\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mdelete\u001B[39m(\u001B[38;5;28mself\u001B[39m) -> \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[32m 537\u001B[39m \u001B[38;5;250m \u001B[39m\u001B[33;03m\"\"\"Delete the entire cache.\u001B[39;00m\n\u001B[32m 538\u001B[39m \n\u001B[32m 539\u001B[39m \u001B[33;03m This deletes all entries in the cache by calling delete_query\u001B[39;00m\n\u001B[32m 540\u001B[39m \u001B[33;03m with no attributes.\u001B[39;00m\n\u001B[32m 541\u001B[39m \u001B[33;03m \"\"\"\u001B[39;00m\n\u001B[32m--> \u001B[39m\u001B[32m542\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_client\u001B[49m\u001B[43m.\u001B[49m\u001B[43mdelete_query\u001B[49m\u001B[43m(\u001B[49m\u001B[43mattributes\u001B[49m\u001B[43m=\u001B[49m\u001B[43m{\u001B[49m\u001B[43m}\u001B[49m\u001B[43m)\u001B[49m\n", |
447 | | - "\u001B[36mFile \u001B[39m\u001B[32m~/src/langchain-redis/libs/redis/env/lib/python3.11/site-packages/langcache/sdk.py:227\u001B[39m, in \u001B[36mLangCache.delete_query\u001B[39m\u001B[34m(self, attributes, retries, server_url, timeout_ms, http_headers)\u001B[39m\n\u001B[32m 223\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m utils.match_response(http_res, \u001B[33m\"\u001B[39m\u001B[33m400\u001B[39m\u001B[33m\"\u001B[39m, \u001B[33m\"\u001B[39m\u001B[33mapplication/json\u001B[39m\u001B[33m\"\u001B[39m):\n\u001B[32m 224\u001B[39m response_data = unmarshal_json_response(\n\u001B[32m 225\u001B[39m errors.BadRequestErrorResponseContentData, http_res\n\u001B[32m 226\u001B[39m )\n\u001B[32m--> \u001B[39m\u001B[32m227\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m errors.BadRequestErrorResponseContent(response_data, http_res)\n\u001B[32m 228\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m utils.match_response(http_res, \u001B[33m\"\u001B[39m\u001B[33m401\u001B[39m\u001B[33m\"\u001B[39m, \u001B[33m\"\u001B[39m\u001B[33mapplication/json\u001B[39m\u001B[33m\"\u001B[39m):\n\u001B[32m 229\u001B[39m response_data = unmarshal_json_response(\n\u001B[32m 230\u001B[39m errors.AuthenticationErrorResponseContentData, http_res\n\u001B[32m 231\u001B[39m )\n", |
448 | | - "\u001B[31mBadRequestErrorResponseContent\u001B[39m: {\"detail\":\"attributes: cannot be blank.\",\"status\":400,\"title\":\"Invalid Request\",\"type\":\"/errors/invalid-data\"}" |
| 421 | + "(Similar query) Speed improvement: 13.78x faster\n", |
| 422 | + "23:10:09 httpx INFO HTTP Request: POST https://aws-us-east-1.langcache.redis.io/v1/caches/d0a1149ce793462c9a63ba3d1f7fa718/flush \"HTTP/1.1 204 No Content\"\n", |
| 423 | + "Semantic cache cleared\n" |
449 | 424 | ] |
450 | 425 | } |
451 | 426 | ], |
452 | | - "execution_count": 7 |
| 427 | + "execution_count": 11 |
| 428 | + }, |
| 429 | + { |
| 430 | + "metadata": { |
| 431 | + "ExecuteTime": { |
| 432 | + "end_time": "2025-11-22T07:10:09.686945Z", |
| 433 | + "start_time": "2025-11-22T07:10:09.685687Z" |
| 434 | + } |
| 435 | + }, |
| 436 | + "cell_type": "code", |
| 437 | + "source": "", |
| 438 | + "outputs": [], |
| 439 | + "execution_count": null |
453 | 440 | }, |
454 | 441 | { |
455 | 442 | "metadata": {}, |
|
462 | 449 | "source": "### Custom TTL (Time-To-Live)" |
463 | 450 | }, |
464 | 451 | { |
465 | | - "metadata": {}, |
| 452 | + "metadata": { |
| 453 | + "ExecuteTime": { |
| 454 | + "end_time": "2025-11-22T07:10:15.708721Z", |
| 455 | + "start_time": "2025-11-22T07:10:09.689547Z" |
| 456 | + } |
| 457 | + }, |
466 | 458 | "cell_type": "code", |
467 | | - "outputs": [], |
468 | | - "execution_count": null, |
469 | 459 | "source": [ |
470 | 460 | "# Initialize RedisCache with custom TTL\n", |
471 | 461 | "ttl_cache = RedisCache(redis_url=REDIS_URL, ttl=5) # 60 seconds TTL\n", |
|
487 | 477 | " print(f\"Result after TTL: {expired_result[0].text}\")\n", |
488 | 478 | "else:\n", |
489 | 479 | " print(\"Not found (expired)\")" |
490 | | - ] |
| 480 | + ], |
| 481 | + "outputs": [ |
| 482 | + { |
| 483 | + "name": "stdout", |
| 484 | + "output_type": "stream", |
| 485 | + "text": [ |
| 486 | + "Cached result: Cached response\n", |
| 487 | + "Waiting for TTL to expire...\n", |
| 488 | + "Not found (expired)\n" |
| 489 | + ] |
| 490 | + } |
| 491 | + ], |
| 492 | + "execution_count": 12 |
491 | 493 | }, |
492 | 494 | { |
493 | 495 | "metadata": {}, |
494 | 496 | "cell_type": "markdown", |
495 | 497 | "source": "### Customizing RedisSemanticCache" |
496 | 498 | }, |
497 | 499 | { |
498 | | - "metadata": {}, |
| 500 | + "metadata": { |
| 501 | + "ExecuteTime": { |
| 502 | + "end_time": "2025-11-22T07:10:17.430674Z", |
| 503 | + "start_time": "2025-11-22T07:10:15.729854Z" |
| 504 | + } |
| 505 | + }, |
499 | 506 | "cell_type": "code", |
500 | | - "outputs": [], |
501 | | - "execution_count": null, |
502 | 507 | "source": [ |
503 | 508 | "# Initialize RedisSemanticCache with custom settings\n", |
504 | 509 | "custom_semantic_cache = RedisSemanticCache(\n", |
|
523 | 528 | "\n", |
524 | 529 | "# Clean up\n", |
525 | 530 | "custom_semantic_cache.clear()" |
526 | | - ] |
| 531 | + ], |
| 532 | + "outputs": [ |
| 533 | + { |
| 534 | + "name": "stdout", |
| 535 | + "output_type": "stream", |
| 536 | + "text": [ |
| 537 | + "23:10:15 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
| 538 | + "23:10:16 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
| 539 | + "23:10:16 httpx INFO HTTP Request: POST https://api.openai.com/v1/completions \"HTTP/1.1 200 OK\"\n", |
| 540 | + "23:10:16 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
| 541 | + "Original result: \n", |
| 542 | + "\n", |
| 543 | + "The largest planet in our solar system is Jupiter.\n", |
| 544 | + "23:10:17 httpx INFO HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", |
| 545 | + "Similar query result: \n", |
| 546 | + "\n", |
| 547 | + "The largest planet in our solar system is Jupiter.\n" |
| 548 | + ] |
| 549 | + } |
| 550 | + ], |
| 551 | + "execution_count": 13 |
527 | 552 | }, |
528 | 553 | { |
529 | 554 | "metadata": {}, |
|
0 commit comments