💡 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
Support pooling_mode with models trained with recent Sentence Transformers, closes #1292
davidmezzettif87574de4c01
diff --git a/src/python/txtai/models/pooling/factory.py b/src/python/txtai/models/pooling/factory.pyindex 6b2a32dd..2bfa8e1b 100644--- a/src/python/txtai/models/pooling/factory.py+++ b/src/python/txtai/models/pooling/factory.py@@ -85,16 +85,20 @@ class PoolingFactory:# Load 1_Pooling/config.json fileconfig = PoolingFactory.load(path, "1_Pooling/config.json")+ # Models trained with Sentence Transformers v5.4+ use `pooling_mode` parameter+ # Support both the new and legacy parameters+ mode = config.get("pooling_mode")+# Set to CLS pooling if it's enabled and mean pooling is disabled- if config and config.get("pooling_mode_cls_token") and not config.get("pooling_mode_mean_tokens"):+ if config and config.get("pooling_mode_cls_token", mode == "cls") and not config.get("pooling_mode_mean_tokens", mode == "mean"):method = "clspooling"# Set to last token pooling if it's enabled and mean pooling is disabled- if config and config.get("pooling_mode_lasttoken") and not config.get("pooling_mode_mean_tokens"):+ if config and config.get("pooling_mode_lasttoken", mode == "lasttoken") and not config.get("pooling_mode_mean_tokens", mode == "mean"):method = "lastpooling"# Set to max pooling if it's enabled and mean pooling is disabled- if config and config.get("pooling_mode_max_tokens") and not config.get("pooling_mode_mean_tokens"):+ if config and config.get("pooling_mode_max_tokens", mode == "max") and not config.get("pooling_mode_mean_tokens", mode == "mean"):method = "maxpooling"# Check for late interaction pooling