@@ -1197,9 +1197,9 @@ def _read_similarity_output(
11971197 if not has_similarity_score and not has_embeddings :
11981198 docs .append (doc )
11991199 continue
1200-
1200+
12011201 # Extended result (score, embedding)
1202- result_parts = [doc ]
1202+ result_parts : list [ Any ] = [doc ]
12031203
12041204 if has_similarity_score :
12051205 result_parts .append (extras [0 ])
@@ -1495,10 +1495,22 @@ def add_texts(
14951495 """
14961496
14971497 texts = list (texts )
1498+ if ids and len (ids ) != len (texts ):
1499+ raise ValueError (
1500+ f"Length mismatch: 'ids' has { len (ids )} items, "
1501+ f"but 'texts' has { len (texts )} items."
1502+ )
1503+
14981504 processed_ids , original_ids = get_processed_ids (texts , metadatas , ids )
14991505
15001506 if not metadatas :
15011507 metadatas = [{} for _ in texts ]
1508+ else :
1509+ if len (metadatas ) != len (texts ):
1510+ raise ValueError (
1511+ f"Length mismatch: 'metadatas' has { len (metadatas )} items, "
1512+ f"but 'texts' has { len (texts )} items."
1513+ )
15021514
15031515 for i , _id in enumerate (original_ids ):
15041516 if INTERNAL_ID_KEY in metadatas [i ]:
@@ -1541,7 +1553,8 @@ def add_texts(
15411553 # self.mutate_on_duplicate controls how inserts handle existing IDs.
15421554 # If False:
15431555 # uses INSERT_QUERY.
1544- # existing rows having the same ID as the inserted row are not updated.
1556+ # existing rows having the same ID as the inserted row are not
1557+ # updated.
15451558 # with batcherrors=True, duplicate rows are skipped and their IDs
15461559 # are not included in the `add_texts` return value (i.e., not
15471560 # reported as successfully inserted).
@@ -1592,13 +1605,17 @@ def add_texts(
15921605
15931606 for error in cursor .getbatcherrors ():
15941607 error_indices .append (error .offset )
1595- logger .warning ("Could not insert row at offset %s due to error: %s" , error .offset , error .message )
1608+ logger .warning (
1609+ "Could not insert row at offset %s due to error: %s" ,
1610+ error .offset ,
1611+ error .message ,
1612+ )
15961613
15971614 connection .commit ()
15981615 finally :
15991616 # do not change the input dict list
16001617 for i in range (len (original_ids )):
1601- del metadatas [i ][ INTERNAL_ID_KEY ]
1618+ metadatas [i ]. pop ( INTERNAL_ID_KEY , None )
16021619
16031620 inserted_ids = [i for j , i in enumerate (original_ids ) if j not in error_indices ]
16041621 return inserted_ids
@@ -1635,10 +1652,22 @@ async def aadd_texts(
16351652 """
16361653
16371654 texts = list (texts )
1655+ if ids and len (ids ) != len (texts ):
1656+ raise ValueError (
1657+ f"Length mismatch: 'ids' has { len (ids )} items, "
1658+ f"but 'texts' has { len (texts )} items."
1659+ )
1660+
16381661 processed_ids , original_ids = get_processed_ids (texts , metadatas , ids )
16391662
16401663 if not metadatas :
16411664 metadatas = [{} for _ in texts ]
1665+ else :
1666+ if len (metadatas ) != len (texts ):
1667+ raise ValueError (
1668+ f"Length mismatch: 'metadatas' has { len (metadatas )} items, "
1669+ f"but 'texts' has { len (texts )} items."
1670+ )
16421671
16431672 for i , _id in enumerate (original_ids ):
16441673 if INTERNAL_ID_KEY in metadatas [i ]:
@@ -1716,17 +1745,23 @@ async def context(connection: Any) -> List[str]:
17161745 docs ,
17171746 batcherrors = True ,
17181747 )
1719-
1748+
17201749 for error in cursor .getbatcherrors ():
17211750 error_indices .append (error .offset )
1722- logger .warning ("Could not insert row at offset %s due to error: %s" , error .offset , error .message )
1751+ logger .warning (
1752+ "Could not insert row at offset %s due to error: %s" ,
1753+ error .offset ,
1754+ error .message ,
1755+ )
17231756
17241757 await connection .commit ()
17251758 finally :
17261759 for i in range (len (original_ids )):
1727- del metadatas [i ][ INTERNAL_ID_KEY ]
1760+ metadatas [i ]. pop ( INTERNAL_ID_KEY , None )
17281761
1729- inserted_ids = [i for j , i in enumerate (original_ids ) if j not in error_indices ]
1762+ inserted_ids = [
1763+ i for j , i in enumerate (original_ids ) if j not in error_indices
1764+ ]
17301765
17311766 return inserted_ids
17321767
0 commit comments