Home / File/ test_in_memory_indexer.py — langchain Source File

test_in_memory_indexer.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 5 imports 2 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  1578647f_9f1f_8da3_8573_48429f67334c["test_in_memory_indexer.py"]
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  1578647f_9f1f_8da3_8573_48429f67334c --> 120e2591_3e15_b895_72b6_cb26195e40a6
  c78398e2_df42_68bb_a4eb_50daaad417de["langchain_tests.integration_tests.indexer"]
  1578647f_9f1f_8da3_8573_48429f67334c --> c78398e2_df42_68bb_a4eb_50daaad417de
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  1578647f_9f1f_8da3_8573_48429f67334c --> 91721f45_4909_e489_8c1f_084f8bd87145
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  1578647f_9f1f_8da3_8573_48429f67334c --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  f1b2b0eb_f384_a14e_5d97_566a3e577cd5["langchain_core.indexing.in_memory"]
  1578647f_9f1f_8da3_8573_48429f67334c --> f1b2b0eb_f384_a14e_5d97_566a3e577cd5
  style 1578647f_9f1f_8da3_8573_48429f67334c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test in memory indexer."""

import pytest
from langchain_tests.integration_tests.indexer import (
    AsyncDocumentIndexTestSuite,
    DocumentIndexerTestSuite,
)
from typing_extensions import override

from langchain_core.documents import Document
from langchain_core.indexing.in_memory import (
    InMemoryDocumentIndex,
)


class TestDocumentIndexerTestSuite(DocumentIndexerTestSuite):
    @pytest.fixture
    @override
    def index(self) -> InMemoryDocumentIndex:
        return InMemoryDocumentIndex()


class TestAsyncDocumentIndexerTestSuite(AsyncDocumentIndexTestSuite):
    # Something funky is going on with mypy and async pytest fixture
    @pytest.fixture
    @override
    async def index(self) -> InMemoryDocumentIndex:
        return InMemoryDocumentIndex()


def test_sync_retriever() -> None:
    index = InMemoryDocumentIndex()
    documents = [
        Document(id="1", page_content="hello world"),
        Document(id="2", page_content="goodbye cat"),
    ]
    index.upsert(documents)
    assert index.invoke("hello") == [documents[0], documents[1]]
    assert index.invoke("cat") == [documents[1], documents[0]]


async def test_async_retriever() -> None:
    index = InMemoryDocumentIndex()
    documents = [
        Document(id="1", page_content="hello world"),
        Document(id="2", page_content="goodbye cat"),
    ]
    await index.aupsert(documents)
    assert (await index.ainvoke("hello")) == [documents[0], documents[1]]
    assert (await index.ainvoke("cat")) == [documents[1], documents[0]]

Subdomains

Dependencies

  • langchain_core.documents
  • langchain_core.indexing.in_memory
  • langchain_tests.integration_tests.indexer
  • pytest
  • typing_extensions

Frequently Asked Questions

What does test_in_memory_indexer.py do?
test_in_memory_indexer.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_in_memory_indexer.py?
test_in_memory_indexer.py defines 2 function(s): test_async_retriever, test_sync_retriever.
What does test_in_memory_indexer.py depend on?
test_in_memory_indexer.py imports 5 module(s): langchain_core.documents, langchain_core.indexing.in_memory, langchain_tests.integration_tests.indexer, pytest, typing_extensions.
Where is test_in_memory_indexer.py in the architecture?
test_in_memory_indexer.py is located at libs/core/tests/unit_tests/indexing/test_in_memory_indexer.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/tests/unit_tests/indexing).

Analyze Your Own Codebase

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

Try Supermodel Free