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 empty token list with word vectorization, closes #861

davidmezzettie2e81cd2e36a
diff --git a/src/python/txtai/vectors/words.py b/src/python/txtai/vectors/words.py
index cc14b970..99496579 100644
--- a/src/python/txtai/vectors/words.py
+++ b/src/python/txtai/vectors/words.py
@@ -125,9 +125,10 @@ class WordVectors(Vectors):
# Iterate over each data element, tokenize (if necessary) and build an aggregated embeddings vector
embeddings = []
for tokens in data:
- # Convert to tokens if necessary
+ # Convert to tokens, if necessary. If tokenized list is empty, use input string.
if isinstance(tokens, str):
- tokens = Tokenizer.tokenize(tokens)
+ tokenlist = Tokenizer.tokenize(tokens)
+ tokens = tokenlist if tokenlist else [tokens]
# Generate weights for each vector using a scoring method
weights = self.scoring.weights(tokens) if self.scoring else None