mirror of
https://github.com/hwchase17/langchain.git
synced 2026-01-16 08:07:23 +00:00
`math_utils.py` is in the root code folder. This creates the `langchain.math_utils: Math Utils` group on the API Reference navigation ToC, on the same level with `Chains` and `Agents` which is not correct. Refactoring: - created the `utils/` folder - moved `math_utils.py` to `utils/math.py` - moved `utils.py` to `utils/utils.py` - split `utils.py` into `utils.py, env.py, strings.py` - added module description @baskaryan
18 lines
625 B
Python
18 lines
625 B
Python
"""Unit tests for document transformers."""
|
|
from langchain.document_transformers.embeddings_redundant_filter import (
|
|
_filter_similar_embeddings,
|
|
)
|
|
from langchain.utils.math import cosine_similarity
|
|
|
|
|
|
def test__filter_similar_embeddings() -> None:
|
|
threshold = 0.79
|
|
embedded_docs = [[1.0, 2.0], [1.0, 2.0], [2.0, 1.0], [2.0, 0.5], [0.0, 0.0]]
|
|
expected = [1, 3, 4]
|
|
actual = _filter_similar_embeddings(embedded_docs, cosine_similarity, threshold)
|
|
assert expected == actual
|
|
|
|
|
|
def test__filter_similar_embeddings_empty() -> None:
|
|
assert len(_filter_similar_embeddings([], cosine_similarity, 0.0)) == 0
|