chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Sparse Sentence Transformers module tests
|
||||
"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from txtai.vectors import SparseVectorsFactory
|
||||
from txtai.util import SparseArray
|
||||
|
||||
|
||||
class TestSparseSTVectors(unittest.TestCase):
|
||||
"""
|
||||
SparseSTVectors tests
|
||||
"""
|
||||
|
||||
def testIndex(self):
|
||||
"""
|
||||
Test indexing with sentence-transformers vectors
|
||||
"""
|
||||
|
||||
model = SparseVectorsFactory.create({"method": "sentence-transformers", "path": "sparse-encoder-testing/splade-bert-tiny-nq"})
|
||||
ids, dimension, batches, stream = model.index([(0, "test", None)])
|
||||
|
||||
self.assertEqual(len(ids), 1)
|
||||
self.assertEqual(dimension, 30522)
|
||||
self.assertEqual(batches, 1)
|
||||
self.assertIsNotNone(os.path.exists(stream))
|
||||
|
||||
# Test shape of serialized embeddings
|
||||
with open(stream, "rb") as queue:
|
||||
self.assertEqual(SparseArray().load(queue).shape, (1, 30522))
|
||||
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Sparse Vectors module tests
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from txtai.vectors import SparseVectors, SparseVectorsFactory
|
||||
|
||||
|
||||
class TestSparseVectors(unittest.TestCase):
|
||||
"""
|
||||
Sparse Vectors tests.
|
||||
"""
|
||||
|
||||
def testCustom(self):
|
||||
"""
|
||||
Test custom sparse vectors instance
|
||||
"""
|
||||
|
||||
self.assertIsNotNone(
|
||||
SparseVectorsFactory.create({"method": "txtai.vectors.SparseSTVectors", "path": "sparse-encoder-testing/splade-bert-tiny-nq"})
|
||||
)
|
||||
|
||||
def testDefaultNormalize(self):
|
||||
"""
|
||||
Test defaultnormalize method
|
||||
"""
|
||||
|
||||
vectors = SparseVectors(None, None, None)
|
||||
self.assertFalse(vectors.defaultnormalize())
|
||||
|
||||
def testNotSupported(self):
|
||||
"""
|
||||
Test exceptions for unsupported methods
|
||||
"""
|
||||
|
||||
vectors = SparseVectors(None, None, None)
|
||||
|
||||
self.assertRaises(ValueError, vectors.truncate, None)
|
||||
self.assertRaises(ValueError, vectors.quantize, None)
|
||||
|
||||
def testNotFound(self):
|
||||
"""
|
||||
Test unresolvable vector backend
|
||||
"""
|
||||
|
||||
with self.assertRaises(ImportError):
|
||||
SparseVectorsFactory.create({"method": "notfound.vectors"})
|
||||
Reference in New Issue
Block a user