Skip to content
Snippets Groups Projects
Commit c1485309 authored by Ismail Ashraq's avatar Ismail Ashraq
Browse files

semantic splitter tests

parent d3bffff0
No related branches found
No related tags found
No related merge requests found
import pytest
from unittest.mock import Mock
from semantic_router.utils.splitters import semantic_splitter
def test_semantic_splitter_consecutive_similarity_drop():
# Mock the BaseEncoder
mock_encoder = Mock()
mock_encoder.return_value = [[0.5, 0], [0.5, 0], [0.5, 0], [0, 0.5], [0, 0.5]]
docs = ["doc1", "doc2", "doc3", "doc4", "doc5"]
threshold = 0.5
split_method = "consecutive_similarity_drop"
result = semantic_splitter(mock_encoder, docs, threshold, split_method)
assert result == {"split 1": ["doc1", "doc2", "doc3"], "split 2": ["doc4", "doc5"]}
def test_semantic_splitter_cumulative_similarity_drop():
# Mock the BaseEncoder
mock_encoder = Mock()
mock_encoder.side_effect = (
lambda x: [[0.5, 0]] if "doc1" in x or "doc1\ndoc2" in x else [[0, 0.5]]
)
docs = ["doc1", "doc2", "doc3", "doc4", "doc5"]
threshold = 0.5
split_method = "cumulative_similarity_drop"
result = semantic_splitter(mock_encoder, docs, threshold, split_method)
assert result == {"split 1": ["doc1", "doc2"], "split 2": ["doc3", "doc4", "doc5"]}
def test_semantic_splitter_invalid_method():
# Mock the BaseEncoder
mock_encoder = Mock()
docs = ["doc1", "doc2", "doc3", "doc4", "doc5"]
threshold = 0.5
split_method = "invalid_method"
with pytest.raises(ValueError):
semantic_splitter(mock_encoder, docs, threshold, split_method)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment