Home / File/ test_embeddings.py — langchain Source File

test_embeddings.py — langchain Source File

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

File python CoreAbstractions MessageSchema 5 imports 8 functions

Entity Profile

Dependency Diagram

graph LR
  9e68ab8a_4928_00f4_2cee_146af74f4fea["test_embeddings.py"]
  525a7d6f_f455_56e3_854a_c8a7da4a1417["unittest.mock"]
  9e68ab8a_4928_00f4_2cee_146af74f4fea --> 525a7d6f_f455_56e3_854a_c8a7da4a1417
  1803c8c1_a347_1256_1454_9f04c3553d93["httpx"]
  9e68ab8a_4928_00f4_2cee_146af74f4fea --> 1803c8c1_a347_1256_1454_9f04c3553d93
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  9e68ab8a_4928_00f4_2cee_146af74f4fea --> 120e2591_3e15_b895_72b6_cb26195e40a6
  30db3e5b_4549_fdf8_eed3_1cfd8cacbe56["tenacity"]
  9e68ab8a_4928_00f4_2cee_146af74f4fea --> 30db3e5b_4549_fdf8_eed3_1cfd8cacbe56
  7ee113fe_bef7_37b4_1846_b866af39d1c0["langchain_mistralai"]
  9e68ab8a_4928_00f4_2cee_146af74f4fea --> 7ee113fe_bef7_37b4_1846_b866af39d1c0
  style 9e68ab8a_4928_00f4_2cee_146af74f4fea fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test MistralAI Embedding."""

from unittest.mock import patch

import httpx
import pytest
import tenacity

from langchain_mistralai import MistralAIEmbeddings


def test_mistralai_embedding_documents() -> None:
    """Test MistralAI embeddings for documents."""
    documents = ["foo bar", "test document"]
    embedding = MistralAIEmbeddings()
    output = embedding.embed_documents(documents)
    assert len(output) == 2
    assert len(output[0]) == 1024


def test_mistralai_embedding_query() -> None:
    """Test MistralAI embeddings for query."""
    document = "foo bar"
    embedding = MistralAIEmbeddings()
    output = embedding.embed_query(document)
    assert len(output) == 1024


async def test_mistralai_embedding_documents_async() -> None:
    """Test MistralAI embeddings for documents."""
    documents = ["foo bar", "test document"]
    embedding = MistralAIEmbeddings()
    output = await embedding.aembed_documents(documents)
    assert len(output) == 2
    assert len(output[0]) == 1024


async def test_mistralai_embedding_documents_tenacity_error_async() -> None:
    """Test MistralAI embeddings for documents."""
    documents = ["foo bar", "test document"]
    embedding = MistralAIEmbeddings(max_retries=0)
    mock_response = httpx.Response(
        status_code=400,
        request=httpx.Request("POST", url=embedding.async_client.base_url),
    )
    with (
        patch.object(embedding.async_client, "post", return_value=mock_response),
        pytest.raises(tenacity.RetryError),
    ):
        await embedding.aembed_documents(documents)


async def test_mistralai_embedding_documents_http_error_async() -> None:
    """Test MistralAI embeddings for documents."""
    documents = ["foo bar", "test document"]
    embedding = MistralAIEmbeddings(max_retries=None)
    mock_response = httpx.Response(
        status_code=400,
        request=httpx.Request("POST", url=embedding.async_client.base_url),
    )
    with (
        patch.object(embedding.async_client, "post", return_value=mock_response),
        pytest.raises(httpx.HTTPStatusError),
    ):
        await embedding.aembed_documents(documents)


async def test_mistralai_embedding_query_async() -> None:
    """Test MistralAI embeddings for query."""
    document = "foo bar"
    embedding = MistralAIEmbeddings()
    output = await embedding.aembed_query(document)
    assert len(output) == 1024


def test_mistralai_embedding_documents_long() -> None:
    """Test MistralAI embeddings for documents."""
    documents = ["foo bar " * 1000, "test document " * 1000] * 5
    embedding = MistralAIEmbeddings()
    output = embedding.embed_documents(documents)
    assert len(output) == 10
    assert len(output[0]) == 1024


def test_mistralai_embed_query_character() -> None:
    """Test MistralAI embeddings for query."""
    document = "😳"
    embedding = MistralAIEmbeddings()
    output = embedding.embed_query(document)
    assert len(output) == 1024

Subdomains

Dependencies

  • httpx
  • langchain_mistralai
  • pytest
  • tenacity
  • unittest.mock

Frequently Asked Questions

What does test_embeddings.py do?
test_embeddings.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_embeddings.py?
test_embeddings.py defines 8 function(s): test_mistralai_embed_query_character, test_mistralai_embedding_documents, test_mistralai_embedding_documents_async, test_mistralai_embedding_documents_http_error_async, test_mistralai_embedding_documents_long, test_mistralai_embedding_documents_tenacity_error_async, test_mistralai_embedding_query, test_mistralai_embedding_query_async.
What does test_embeddings.py depend on?
test_embeddings.py imports 5 module(s): httpx, langchain_mistralai, pytest, tenacity, unittest.mock.
Where is test_embeddings.py in the architecture?
test_embeddings.py is located at libs/partners/mistralai/tests/integration_tests/test_embeddings.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/partners/mistralai/tests/integration_tests).

Analyze Your Own Codebase

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

Try Supermodel Free