💡 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
fix(muvera): consume true token rows instead of batch-padded ones (#1177)
Tai Ana1c9b94d0093
diff --git a/src/python/txtai/models/pooling/muvera.py b/src/python/txtai/models/pooling/muvera.pyindex 585a197e..30aed1b2 100644--- a/src/python/txtai/models/pooling/muvera.py+++ b/src/python/txtai/models/pooling/muvera.py@@ -28,6 +28,9 @@ class Muvera:- Python port of the original C++ code: https://github.com/sigridjineth/muvera-py"""+ # Signals LatePooling that this encoder must receive true, unpadded token rows+ unpadded = True+def __init__(self, repetitions=20, hashes=5, projection=16, seed=42):"""Creates a Muvera instance.diff --git a/test/python/testmodels/testpooling.py b/test/python/testmodels/testpooling.pyindex ab9dbb6a..fc40993a 100644--- a/test/python/testmodels/testpooling.py+++ b/test/python/testmodels/testpooling.py@@ -114,6 +114,19 @@ class TestPooling(unittest.TestCase):)self.assertEqual(pooling.encode(["test"], category="data").shape, (1, 160))+ def testMuveraPadding(self):+ """+ Test MUVERA vectors don't change with batch padding+ """++ pooling = PoolingFactory.create({"path": "neuml/colbert-bert-tiny", "device": self.device})+ texts = ["Short text.", "A considerably longer text exercises padding behavior."]++ # The shorter text must encode the same alone as it does batched with a longer text+ for category in ["query", "data"]:+ alone = pooling.encode([texts[0]], category=category)+ batched = pooling.encode(texts, batch=2, category=category)+ self.assertTrue(np.allclose(alone[0], batched[0], atol=1e-4))def testMuveraTorchMatchesNumPy(self):"""Test that the Torch MUVERA implementation produces the same encodings as the NumPy one