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. 3 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  8d2d543f_1c45_9e2b_a9c4_5a40ee6957af["test_embeddings.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  8d2d543f_1c45_9e2b_a9c4_5a40ee6957af --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  525a7d6f_f455_56e3_854a_c8a7da4a1417["unittest.mock"]
  8d2d543f_1c45_9e2b_a9c4_5a40ee6957af --> 525a7d6f_f455_56e3_854a_c8a7da4a1417
  0297c4ad_9082_68e6_3e5b_3caf4001da4e["langchain_ollama.embeddings"]
  8d2d543f_1c45_9e2b_a9c4_5a40ee6957af --> 0297c4ad_9082_68e6_3e5b_3caf4001da4e
  style 8d2d543f_1c45_9e2b_a9c4_5a40ee6957af fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test embedding model integration."""

from typing import Any
from unittest.mock import Mock, patch

from langchain_ollama.embeddings import OllamaEmbeddings

MODEL_NAME = "llama3.1"


def test_initialization() -> None:
    """Test embedding model initialization."""
    OllamaEmbeddings(model=MODEL_NAME, keep_alive=1)


@patch("langchain_ollama.embeddings.validate_model")
def test_validate_model_on_init(mock_validate_model: Any) -> None:
    """Test that the model is validated on initialization when requested."""
    OllamaEmbeddings(model=MODEL_NAME, validate_model_on_init=True)
    mock_validate_model.assert_called_once()
    mock_validate_model.reset_mock()

    OllamaEmbeddings(model=MODEL_NAME, validate_model_on_init=False)
    mock_validate_model.assert_not_called()
    OllamaEmbeddings(model=MODEL_NAME)
    mock_validate_model.assert_not_called()


@patch("langchain_ollama.embeddings.Client")
def test_embed_documents_passes_options(mock_client_class: Any) -> None:
    """Test that `embed_documents()` passes options, including `num_gpu`."""
    mock_client = Mock()
    mock_client_class.return_value = mock_client
    mock_client.embed.return_value = {"embeddings": [[0.1, 0.2, 0.3]]}

    embeddings = OllamaEmbeddings(model=MODEL_NAME, num_gpu=4, temperature=0.5)
    result = embeddings.embed_documents(["test text"])

    assert result == [[0.1, 0.2, 0.3]]

    # Check that embed was called with correct arguments
    mock_client.embed.assert_called_once()
    call_args = mock_client.embed.call_args

    # Verify the keyword arguments
    assert "options" in call_args.kwargs
    assert "keep_alive" in call_args.kwargs

    # Verify options contain num_gpu and temperature
    options = call_args.kwargs["options"]
    assert options["num_gpu"] == 4
    assert options["temperature"] == 0.5

Subdomains

Dependencies

  • langchain_ollama.embeddings
  • typing
  • 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, RunnableInterface subdomain.
What functions are defined in test_embeddings.py?
test_embeddings.py defines 3 function(s): test_embed_documents_passes_options, test_initialization, test_validate_model_on_init.
What does test_embeddings.py depend on?
test_embeddings.py imports 3 module(s): langchain_ollama.embeddings, typing, unittest.mock.
Where is test_embeddings.py in the architecture?
test_embeddings.py is located at libs/partners/ollama/tests/unit_tests/test_embeddings.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/partners/ollama/tests/unit_tests).

Analyze Your Own Codebase

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

Try Supermodel Free