💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Respect numeric zero entity flattening thresholds (#1405)
HuaTNAaba97cf16c14
diff --git a/src/python/txtai/pipeline/text/entity.py b/src/python/txtai/pipeline/text/entity.pyindex 57564a18..c48f4ea1 100644--- a/src/python/txtai/pipeline/text/entity.py+++ b/src/python/txtai/pipeline/text/entity.py@@ -64,7 +64,7 @@ class Entity(HFPipeline):# Extract entities if flatten set, otherwise extract (entity, entity type, score) tuplesoutputs = []for result in results:- if flatten:+ if flatten is not None and flatten is not False:output = [r["word"] for r in result if self.accept(r["entity_group"], labels) and r["score"] >= threshold]outputs.append(" ".join(output) if join else output)else:diff --git a/test/python/testpipeline/testtext/testentity.py b/test/python/testpipeline/testtext/testentity.pyindex 9868f7ed..ef5d1533 100644--- a/test/python/testpipeline/testtext/testentity.py+++ b/test/python/testpipeline/testtext/testentity.py@@ -44,6 +44,20 @@ class TestEntity(unittest.TestCase):)self.assertEqual(entities, "Canada Manhattan")+ def testEntityZeroThreshold(self):+ """+ Test zero-threshold flattened and joined entity outputs+ """++ text = "Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg"+ self.assertEqual(self.entity(text, flatten=0.0), ["Canada", "Manhattan"])+ self.assertEqual(self.entity([text], flatten=0.0), [["Canada", "Manhattan"]])+ self.assertEqual(self.entity(text, flatten=0.0, join=True), "Canada Manhattan")+ self.assertEqual(self.entity(text, labels=["LOC"], flatten=0.0), ["Canada"])++ # Boolean False keeps scored tuples, even when joining is requested.+ self.assertEqual(self.entity(text, flatten=False, join=True), self.entity(text))+def testEntityTypes(self):"""Test entity type filtering