Home / File/ test_in_memory.py — langchain Source File

test_in_memory.py — langchain Source File

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

File python LangChainCore ApiManagement 8 imports 10 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  a974d690_d5fa_ba65_671d_ce8278eefe7d["test_in_memory.py"]
  927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"]
  a974d690_d5fa_ba65_671d_ce8278eefe7d --> 927570d8_11a6_5c17_0f0d_80baae0c733e
  23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"]
  a974d690_d5fa_ba65_671d_ce8278eefe7d --> 23cb242e_1754_041d_200a_553fcb8abe1b
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  a974d690_d5fa_ba65_671d_ce8278eefe7d --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  0f7c8fad_78b2_07eb_8d9d_ced3ed7b4704["langchain_tests.integration_tests.vectorstores"]
  a974d690_d5fa_ba65_671d_ce8278eefe7d --> 0f7c8fad_78b2_07eb_8d9d_ced3ed7b4704
  6a98b0a5_5607_0043_2e22_a46a464c2d62["langchain_core.documents"]
  a974d690_d5fa_ba65_671d_ce8278eefe7d --> 6a98b0a5_5607_0043_2e22_a46a464c2d62
  3f73953f_71af_633b_896c_061915a37f5c["langchain_core.embeddings.fake"]
  a974d690_d5fa_ba65_671d_ce8278eefe7d --> 3f73953f_71af_633b_896c_061915a37f5c
  f75e66a0_314a_f961_16d7_464ee959064b["langchain_core.vectorstores"]
  a974d690_d5fa_ba65_671d_ce8278eefe7d --> f75e66a0_314a_f961_16d7_464ee959064b
  69f4826f_a374_a0f6_8f3b_40edeea0bd45["tests.unit_tests.stubs"]
  a974d690_d5fa_ba65_671d_ce8278eefe7d --> 69f4826f_a374_a0f6_8f3b_40edeea0bd45
  style a974d690_d5fa_ba65_671d_ce8278eefe7d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from pathlib import Path
from unittest.mock import AsyncMock, Mock

import pytest
from langchain_tests.integration_tests.vectorstores import VectorStoreIntegrationTests

from langchain_core.documents import Document
from langchain_core.embeddings.fake import DeterministicFakeEmbedding
from langchain_core.vectorstores import InMemoryVectorStore
from tests.unit_tests.stubs import _any_id_document


class TestInMemoryStandard(VectorStoreIntegrationTests):
    @pytest.fixture
    def vectorstore(self) -> InMemoryVectorStore:
        return InMemoryVectorStore(embedding=self.get_embeddings())


async def test_inmemory_similarity_search() -> None:
    """Test end to end similarity search."""
    store = await InMemoryVectorStore.afrom_texts(
        ["foo", "bar", "baz"], DeterministicFakeEmbedding(size=3)
    )

    # Check sync version
    output = store.similarity_search("foo", k=1)
    assert output == [_any_id_document(page_content="foo")]

    # Check async version
    output = await store.asimilarity_search("bar", k=2)
    assert output == [
        _any_id_document(page_content="bar"),
        _any_id_document(page_content="foo"),
    ]


async def test_inmemory_similarity_search_with_score() -> None:
    """Test end to end similarity search with score."""
    store = await InMemoryVectorStore.afrom_texts(
        ["foo", "bar", "baz"], DeterministicFakeEmbedding(size=3)
    )

    output = store.similarity_search_with_score("foo", k=1)
    assert output[0][0].page_content == "foo"

    output = await store.asimilarity_search_with_score("bar", k=2)
    assert output[0][1] > output[1][1]


async def test_add_by_ids() -> None:
    """Test add texts with ids."""
    vectorstore = InMemoryVectorStore(embedding=DeterministicFakeEmbedding(size=6))

    # Check sync version
    ids1 = vectorstore.add_texts(["foo", "bar", "baz"], ids=["1", "2", "3"])
    assert ids1 == ["1", "2", "3"]
    assert sorted(vectorstore.store.keys()) == ["1", "2", "3"]

    # Check async version
    ids2 = await vectorstore.aadd_texts(["foo", "bar", "baz"], ids=["4", "5", "6"])
// ... (163 more lines)

Domain

Subdomains

Dependencies

  • langchain_core.documents
  • langchain_core.embeddings.fake
  • langchain_core.vectorstores
  • langchain_tests.integration_tests.vectorstores
  • pathlib
  • pytest
  • tests.unit_tests.stubs
  • unittest.mock

Frequently Asked Questions

What does test_in_memory.py do?
test_in_memory.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in test_in_memory.py?
test_in_memory.py defines 10 function(s): test_add_by_ids, test_inmemory_call_embeddings_async, test_inmemory_dump_load, test_inmemory_filter, test_inmemory_filter_by_document_id, test_inmemory_get_by_ids, test_inmemory_mmr, test_inmemory_similarity_search, test_inmemory_similarity_search_with_score, test_inmemory_upsert.
What does test_in_memory.py depend on?
test_in_memory.py imports 8 module(s): langchain_core.documents, langchain_core.embeddings.fake, langchain_core.vectorstores, langchain_tests.integration_tests.vectorstores, pathlib, pytest, tests.unit_tests.stubs, unittest.mock.
Where is test_in_memory.py in the architecture?
test_in_memory.py is located at libs/core/tests/unit_tests/vectorstores/test_in_memory.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/core/tests/unit_tests/vectorstores).

Analyze Your Own Codebase

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

Try Supermodel Free