EmbeddingsUnitTests Class — langchain Architecture
Architecture documentation for the EmbeddingsUnitTests class in embeddings.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9eb1f026_8568_b7aa_2028_9c6b8a5f914d["EmbeddingsUnitTests"] 7f874e7e_e3e0_e72d_7d8c_b0f10e3f8e26["EmbeddingsTests"] 9eb1f026_8568_b7aa_2028_9c6b8a5f914d -->|extends| 7f874e7e_e3e0_e72d_7d8c_b0f10e3f8e26 75153c72_f8a2_b8c5_e857_e6d54f651c18["embeddings.py"] 9eb1f026_8568_b7aa_2028_9c6b8a5f914d -->|defined in| 75153c72_f8a2_b8c5_e857_e6d54f651c18 3395d66f_5c3f_4cd8_3075_785395ced511["test_init()"] 9eb1f026_8568_b7aa_2028_9c6b8a5f914d -->|method| 3395d66f_5c3f_4cd8_3075_785395ced511 42136e0b_4cc9_5986_5094_0fea32531ebf["init_from_env_params()"] 9eb1f026_8568_b7aa_2028_9c6b8a5f914d -->|method| 42136e0b_4cc9_5986_5094_0fea32531ebf 7b41c4ce_7317_0b7b_c521_a2b37ceb175b["test_init_from_env()"] 9eb1f026_8568_b7aa_2028_9c6b8a5f914d -->|method| 7b41c4ce_7317_0b7b_c521_a2b37ceb175b
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/unit_tests/embeddings.py lines 34–137
class EmbeddingsUnitTests(EmbeddingsTests):
"""Base class for embeddings unit tests.
Test subclasses must implement the `embeddings_class` property to specify the
embeddings model to be tested. You can also override the
`embedding_model_params` property to specify initialization parameters.
```python
from typing import Type
from langchain_tests.unit_tests import EmbeddingsUnitTests
from my_package.embeddings import MyEmbeddingsModel
class TestMyEmbeddingsModelUnit(EmbeddingsUnitTests):
@property
def embeddings_class(self) -> Type[MyEmbeddingsModel]:
# Return the embeddings model class to test here
return MyEmbeddingsModel
@property
def embedding_model_params(self) -> dict:
# Return initialization parameters for the model.
return {"model": "model-001"}
```
!!! note
API references for individual test methods include troubleshooting tips.
Testing initialization from environment variables
Overriding the `init_from_env_params` property will enable additional tests
for initialization from environment variables. See below for details.
??? note "`init_from_env_params`"
This property is used in unit tests to test initialization from
environment variables. It should return a tuple of three dictionaries
that specify the environment variables, additional initialization args,
and expected instance attributes to check.
Defaults to empty dicts. If not overridden, the test is skipped.
```python
@property
def init_from_env_params(self) -> Tuple[dict, dict, dict]:
return (
{
"MY_API_KEY": "api_key",
},
{
"model": "model-001",
},
{
"my_api_key": "api_key",
},
)
```
"""
def test_init(self) -> None:
"""Test model initialization.
??? note "Troubleshooting"
If this test fails, ensure that `embedding_model_params` is specified
and the model can be initialized from those params.
"""
model = self.embeddings_class(**self.embedding_model_params)
assert model is not None
@property
def init_from_env_params(
self,
) -> tuple[dict[str, str], dict[str, Any], dict[str, Any]]:
"""Init from env params.
This property is used in unit tests to test initialization from environment
variables. It should return a tuple of three dictionaries that specify the
environment variables, additional initialization args, and expected instance
attributes to check.
"""
return {}, {}, {}
Extends
Source
Frequently Asked Questions
What is the EmbeddingsUnitTests class?
EmbeddingsUnitTests is a class in the langchain codebase, defined in libs/standard-tests/langchain_tests/unit_tests/embeddings.py.
Where is EmbeddingsUnitTests defined?
EmbeddingsUnitTests is defined in libs/standard-tests/langchain_tests/unit_tests/embeddings.py at line 34.
What does EmbeddingsUnitTests extend?
EmbeddingsUnitTests extends EmbeddingsTests.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free