4040 _namespace_to_text ,
4141 _row_to_item ,
4242 _row_to_search_item ,
43+ get_key_with_hash_tag ,
4344)
4445
4546from .token_unescaper import TokenUnescaper
@@ -245,7 +246,8 @@ def _batch_get_ops(
245246
246247 if ttl_minutes is not None :
247248 ttl_seconds = int (ttl_minutes * 60 )
248- pipeline = self ._redis .pipeline ()
249+ # In cluster mode, we must use transaction=False
250+ pipeline = self ._redis .pipeline (transaction = not self .cluster_mode )
249251
250252 for keys in refresh_keys_by_idx .values ():
251253 for key in keys :
@@ -291,7 +293,7 @@ def _batch_put_ops(
291293 doc_ids [(namespace , op .key )] = generated_doc_id
292294 # Track TTL for this document if specified
293295 if hasattr (op , "ttl" ) and op .ttl is not None :
294- main_key = f" { STORE_PREFIX } { REDIS_KEY_SEPARATOR } { generated_doc_id } "
296+ main_key = get_key_with_hash_tag ( STORE_PREFIX , REDIS_KEY_SEPARATOR , generated_doc_id , self . cluster_mode )
295297 ttl_tracking [main_key ] = ([], op .ttl )
296298
297299 # Load store docs with explicit keys
@@ -305,7 +307,7 @@ def _batch_put_ops(
305307 doc .pop ("expires_at" , None )
306308
307309 store_docs .append (doc )
308- redis_key = f" { STORE_PREFIX } { REDIS_KEY_SEPARATOR } { doc_id } "
310+ redis_key = get_key_with_hash_tag ( STORE_PREFIX , REDIS_KEY_SEPARATOR , doc_id , self . cluster_mode )
309311 store_keys .append (redis_key )
310312
311313 if store_docs :
@@ -335,11 +337,11 @@ def _batch_put_ops(
335337 "updated_at" : datetime .now (timezone .utc ).timestamp (),
336338 }
337339 )
338- vector_key = f" { STORE_VECTOR_PREFIX } { REDIS_KEY_SEPARATOR } { doc_id } "
340+ vector_key = get_key_with_hash_tag ( STORE_VECTOR_PREFIX , REDIS_KEY_SEPARATOR , doc_id , self . cluster_mode )
339341 vector_keys .append (vector_key )
340342
341343 # Add this vector key to the related keys list for TTL
342- main_key = f" { STORE_PREFIX } { REDIS_KEY_SEPARATOR } { doc_id } "
344+ main_key = get_key_with_hash_tag ( STORE_PREFIX , REDIS_KEY_SEPARATOR , doc_id , self . cluster_mode )
343345 if main_key in ttl_tracking :
344346 ttl_tracking [main_key ][0 ].append (vector_key )
345347
@@ -381,7 +383,8 @@ def _batch_search_ops(
381383 vector_results = self .vector_index .query (vector_query )
382384
383385 # Get matching store docs in pipeline
384- pipe = self ._redis .pipeline ()
386+ # In cluster mode, we must use transaction=False
387+ pipe = self ._redis .pipeline (transaction = not self .cluster_mode )
385388 result_map = {} # Map store key to vector result with distances
386389
387390 for doc in vector_results :
@@ -391,7 +394,9 @@ def _batch_search_ops(
391394 else getattr (doc , "id" , None )
392395 )
393396 if doc_id :
394- store_key = f"{ STORE_PREFIX } { REDIS_KEY_SEPARATOR } { doc_id .split (':' )[1 ]} " # Convert vector:ID to store:ID
397+ # Convert vector:ID to store:ID
398+ doc_uuid = doc_id .split (':' )[1 ]
399+ store_key = get_key_with_hash_tag (STORE_PREFIX , REDIS_KEY_SEPARATOR , doc_uuid , self .cluster_mode )
395400 result_map [store_key ] = doc
396401 pipe .json ().get (store_key )
397402
@@ -436,9 +441,7 @@ def _batch_search_ops(
436441 refresh_keys .append (store_key )
437442 # Also find associated vector keys with same ID
438443 doc_id = store_key .split (":" )[- 1 ]
439- vector_key = (
440- f"{ STORE_VECTOR_PREFIX } { REDIS_KEY_SEPARATOR } { doc_id } "
441- )
444+ vector_key = get_key_with_hash_tag (STORE_VECTOR_PREFIX , REDIS_KEY_SEPARATOR , doc_id , self .cluster_mode )
442445 refresh_keys .append (vector_key )
443446
444447 items .append (
@@ -458,7 +461,8 @@ def _batch_search_ops(
458461
459462 if ttl_minutes is not None :
460463 ttl_seconds = int (ttl_minutes * 60 )
461- pipeline = self ._redis .pipeline ()
464+ # In cluster mode, we must use transaction=False
465+ pipeline = self ._redis .pipeline (transaction = not self .cluster_mode )
462466 for key in refresh_keys :
463467 # Only refresh TTL if the key exists and has a TTL
464468 ttl = self ._redis .ttl (key )
@@ -500,9 +504,7 @@ def _batch_search_ops(
500504 refresh_keys .append (doc .id )
501505 # Also find associated vector keys with same ID
502506 doc_id = doc .id .split (":" )[- 1 ]
503- vector_key = (
504- f"{ STORE_VECTOR_PREFIX } { REDIS_KEY_SEPARATOR } { doc_id } "
505- )
507+ vector_key = get_key_with_hash_tag (STORE_VECTOR_PREFIX , REDIS_KEY_SEPARATOR , doc_id , self .cluster_mode )
506508 refresh_keys .append (vector_key )
507509
508510 items .append (_row_to_search_item (_decode_ns (data ["prefix" ]), data ))
@@ -518,7 +520,8 @@ def _batch_search_ops(
518520
519521 if ttl_minutes is not None :
520522 ttl_seconds = int (ttl_minutes * 60 )
521- pipeline = self ._redis .pipeline ()
523+ # In cluster mode, we must use transaction=False
524+ pipeline = self ._redis .pipeline (transaction = not self .cluster_mode )
522525 for key in refresh_keys :
523526 # Only refresh TTL if the key exists and has a TTL
524527 ttl = self ._redis .ttl (key )
0 commit comments