Home / File/ test_base.py — langchain Source File

test_base.py — langchain Source File

Architecture documentation for test_base.py, a python file in the langchain codebase. 4 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  406346ad_0b71_d587_bbfd_22cde9b3187e["test_base.py"]
  3888b2bf_bffe_7c16_770f_a406d400119c["importlib"]
  406346ad_0b71_d587_bbfd_22cde9b3187e --> 3888b2bf_bffe_7c16_770f_a406d400119c
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  406346ad_0b71_d587_bbfd_22cde9b3187e --> 120e2591_3e15_b895_72b6_cb26195e40a6
  bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3["langchain_core.embeddings"]
  406346ad_0b71_d587_bbfd_22cde9b3187e --> bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3
  55c159ee_8be6_d32c_b9ae_f24c02b5a184["langchain_classic.embeddings.base"]
  406346ad_0b71_d587_bbfd_22cde9b3187e --> 55c159ee_8be6_d32c_b9ae_f24c02b5a184
  style 406346ad_0b71_d587_bbfd_22cde9b3187e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test embeddings base module."""

import importlib

import pytest
from langchain_core.embeddings import Embeddings

from langchain_classic.embeddings.base import _SUPPORTED_PROVIDERS, init_embeddings


@pytest.mark.parametrize(
    ("provider", "model"),
    [
        ("openai", "text-embedding-3-large"),
        ("google_vertexai", "text-embedding-gecko@003"),
        ("bedrock", "amazon.titan-embed-text-v1"),
        ("cohere", "embed-english-v2.0"),
    ],
)
async def test_init_embedding_model(provider: str, model: str) -> None:
    package = _SUPPORTED_PROVIDERS[provider]
    try:
        importlib.import_module(package)
    except ImportError:
        pytest.skip(f"Package {package} is not installed")

    model_colon = init_embeddings(f"{provider}:{model}")
    assert isinstance(model_colon, Embeddings)

    model_explicit = init_embeddings(
        model=model,
        provider=provider,
    )
    assert isinstance(model_explicit, Embeddings)

    text = "Hello world"

    embedding_colon = await model_colon.aembed_query(text)
    assert isinstance(embedding_colon, list)
    assert all(isinstance(x, float) for x in embedding_colon)

    embedding_explicit = await model_explicit.aembed_query(text)
    assert isinstance(embedding_explicit, list)
    assert all(isinstance(x, float) for x in embedding_explicit)

Subdomains

Dependencies

  • importlib
  • langchain_classic.embeddings.base
  • langchain_core.embeddings
  • pytest

Frequently Asked Questions

What does test_base.py do?
test_base.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_base.py?
test_base.py defines 1 function(s): test_init_embedding_model.
What does test_base.py depend on?
test_base.py imports 4 module(s): importlib, langchain_classic.embeddings.base, langchain_core.embeddings, pytest.
Where is test_base.py in the architecture?
test_base.py is located at libs/langchain/tests/integration_tests/embeddings/test_base.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/tests/integration_tests/embeddings).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free