File tree Expand file tree Collapse file tree 3 files changed +3
-39
lines changed
sdks/python/apache_beam/ml/rag/embeddings Expand file tree Collapse file tree 3 files changed +3
-39
lines changed Original file line number Diff line number Diff line change 3131from apache_beam .testing .test_pipeline import TestPipeline
3232from apache_beam .testing .util import assert_that
3333from apache_beam .testing .util import equal_to
34+ from apache_beam .ml .rag .embeddings .test_utils import chunk_approximately_equals
3435
3536# pylint: disable=unused-import
3637try :
4041 SENTENCE_TRANSFORMERS_AVAILABLE = False
4142
4243
43- def chunk_approximately_equals (expected , actual ):
44- """Compare embeddings allowing for numerical differences."""
45- if not isinstance (expected , Chunk ) or not isinstance (actual , Chunk ):
46- return False
47-
48- return (
49- expected .id == actual .id and expected .metadata == actual .metadata and
50- expected .content == actual .content and
51- len (expected .embedding .dense_embedding ) == len (
52- actual .embedding .dense_embedding ) and
53- all (isinstance (x , float ) for x in actual .embedding .dense_embedding ))
54-
55-
5644@pytest .mark .uses_transformers
5745@unittest .skipIf (
5846 not SENTENCE_TRANSFORMERS_AVAILABLE , "sentence-transformers not available" )
Original file line number Diff line number Diff line change 1313# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414# See the License for the specific language governing permissions and
1515# limitations under the License.
16-
1716import os
1817import shutil
1918import tempfile
2827from apache_beam .testing .util import assert_that
2928from apache_beam .testing .util import equal_to
3029from apache_beam .ml .rag .embeddings .open_ai import OpenAITextEmbeddings
31-
32- def chunk_approximately_equals (expected , actual ):
33- """Compare embeddings allowing for numerical differences."""
34- if not isinstance (expected , Chunk ) or not isinstance (actual , Chunk ):
35- return False
36-
37- return (
38- expected .id == actual .id and expected .metadata == actual .metadata and
39- expected .content == actual .content and
40- len (expected .embedding .dense_embedding ) == len (
41- actual .embedding .dense_embedding ) and
42- all (isinstance (x , float ) for x in actual .embedding .dense_embedding ))
30+ from apache_beam .ml .rag .embeddings .test_utils import chunk_approximately_equals
4331
4432
4533class OpenAITextEmbeddingsTest (unittest .TestCase ):
Original file line number Diff line number Diff line change 2828from apache_beam .testing .test_pipeline import TestPipeline
2929from apache_beam .testing .util import assert_that
3030from apache_beam .testing .util import equal_to
31+ from apache_beam .ml .rag .embeddings .test_utils import chunk_approximately_equals
3132
3233# pylint: disable=ungrouped-imports
3334try :
3839 VERTEX_AI_AVAILABLE = False
3940
4041
41- def chunk_approximately_equals (expected , actual ):
42- """Compare embeddings allowing for numerical differences."""
43- if not isinstance (expected , Chunk ) or not isinstance (actual , Chunk ):
44- return False
45-
46- return (
47- expected .id == actual .id and expected .metadata == actual .metadata and
48- expected .content == actual .content and
49- len (expected .embedding .dense_embedding ) == len (
50- actual .embedding .dense_embedding ) and
51- all (isinstance (x , float ) for x in actual .embedding .dense_embedding ))
52-
53-
5442@unittest .skipIf (
5543 not VERTEX_AI_AVAILABLE , "Vertex AI dependencies not available" )
5644class VertexAITextEmbeddingsTest (unittest .TestCase ):
You can’t perform that action at this time.
0 commit comments