@@ -185,6 +185,15 @@ def index(self) -> SearchIndex:
185
185
"""
186
186
return self ._index
187
187
188
+ @property
189
+ def aindex (self ) -> Optional [AsyncSearchIndex ]:
190
+ """The underlying AsyncSearchIndex for the cache.
191
+
192
+ Returns:
193
+ AsyncSearchIndex: The async search index.
194
+ """
195
+ return self ._aindex
196
+
188
197
@property
189
198
def distance_threshold (self ) -> float :
190
199
"""The semantic distance threshold for the cache.
@@ -481,6 +490,7 @@ def store(
481
490
vector : Optional [List [float ]] = None ,
482
491
metadata : Optional [Dict [str , Any ]] = None ,
483
492
filters : Optional [Dict [str , Any ]] = None ,
493
+ ttl : Optional [int ] = None ,
484
494
) -> str :
485
495
"""Stores the specified key-value pair in the cache along with metadata.
486
496
@@ -494,6 +504,8 @@ def store(
494
504
alongside the prompt and response. Defaults to None.
495
505
filters (Optional[Dict[str, Any]]): The optional tag to assign to the cache entry.
496
506
Defaults to None.
507
+ ttl (Optional[int]): The optional TTL override to use on this individual cache
508
+ entry. Defaults to the global TTL setting.
497
509
498
510
Returns:
499
511
str: The Redis key for the entries added to the semantic cache.
@@ -513,7 +525,6 @@ def store(
513
525
"""
514
526
# Vectorize prompt if necessary and create cache payload
515
527
vector = vector or self ._vectorize_prompt (prompt )
516
-
517
528
self ._check_vector_dims (vector )
518
529
519
530
# Build cache entry for the cache
@@ -526,9 +537,10 @@ def store(
526
537
)
527
538
528
539
# Load cache entry with TTL
540
+ ttl = ttl or self ._ttl
529
541
keys = self ._index .load (
530
542
data = [cache_entry .to_dict ()],
531
- ttl = self . _ttl ,
543
+ ttl = ttl ,
532
544
id_field = self .entry_id_field_name ,
533
545
)
534
546
return keys [0 ]
@@ -540,6 +552,7 @@ async def astore(
540
552
vector : Optional [List [float ]] = None ,
541
553
metadata : Optional [Dict [str , Any ]] = None ,
542
554
filters : Optional [Dict [str , Any ]] = None ,
555
+ ttl : Optional [int ] = None ,
543
556
) -> str :
544
557
"""Async stores the specified key-value pair in the cache along with metadata.
545
558
@@ -553,6 +566,8 @@ async def astore(
553
566
alongside the prompt and response. Defaults to None.
554
567
filters (Optional[Dict[str, Any]]): The optional tag to assign to the cache entry.
555
568
Defaults to None.
569
+ ttl (Optional[int]): The optional TTL override to use on this individual cache
570
+ entry. Defaults to the global TTL setting.
556
571
557
572
Returns:
558
573
str: The Redis key for the entries added to the semantic cache.
@@ -574,7 +589,6 @@ async def astore(
574
589
575
590
# Vectorize prompt if necessary and create cache payload
576
591
vector = vector or self ._vectorize_prompt (prompt )
577
-
578
592
self ._check_vector_dims (vector )
579
593
580
594
# Build cache entry for the cache
@@ -587,9 +601,10 @@ async def astore(
587
601
)
588
602
589
603
# Load cache entry with TTL
604
+ ttl = ttl or self ._ttl
590
605
keys = await aindex .load (
591
606
data = [cache_entry .to_dict ()],
592
- ttl = self . _ttl ,
607
+ ttl = ttl ,
593
608
id_field = self .entry_id_field_name ,
594
609
)
595
610
return keys [0 ]
0 commit comments