Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Handle None input in Tokenizer, closes #607

davidmezzetti6e14cfef4106
diff --git a/src/python/txtai/pipeline/data/tokenizer.py b/src/python/txtai/pipeline/data/tokenizer.py
index 4c5b35ac..c7a401aa 100644
--- a/src/python/txtai/pipeline/data/tokenizer.py
+++ b/src/python/txtai/pipeline/data/tokenizer.py
@@ -88,6 +88,10 @@ class Tokenizer(Pipeline):
list of tokens
"""
+ # Check for None and skip processing
+ if text is None:
+ return None
+
# Lowercase
text = text.lower() if self.lowercase else text
diff --git a/test/python/testpipeline/testtokenizer.py b/test/python/testpipeline/testtokenizer.py
index 57819a1f..e27e473d 100644
--- a/test/python/testpipeline/testtokenizer.py
+++ b/test/python/testpipeline/testtokenizer.py
@@ -21,6 +21,15 @@ class TestTokenizer(unittest.TestCase):
self.assertEqual(Tokenizer.tokenize("Y this is a test!"), ["test"])
self.assertEqual(Tokenizer.tokenize("abc123 ABC 123"), ["abc123", "abc"])
+ def testEmptyTokenize(self):
+ """
+ Test handling empty and None inputs
+ """
+
+ # Test that parser can handle empty or None strings
+ self.assertEqual(Tokenizer.tokenize(""), [])
+ self.assertEqual(Tokenizer.tokenize(None), None)
+
def testStandardTokenize(self):
"""
Test standard tokenization