Home / File/ indexer.py — langchain Source File

indexer.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  74356621_dd57_97fa_cf4a_e9392b79a291["indexer.py"]
  614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"]
  74356621_dd57_97fa_cf4a_e9392b79a291 --> 614e7b9f_ed51_0780_749c_ff40b74963fc
  8dfa0cac_d802_3ccd_f710_43a5e70da3a5["uuid"]
  74356621_dd57_97fa_cf4a_e9392b79a291 --> 8dfa0cac_d802_3ccd_f710_43a5e70da3a5
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  74356621_dd57_97fa_cf4a_e9392b79a291 --> cccbe73e_4644_7211_4d55_e8fb133a8014
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  74356621_dd57_97fa_cf4a_e9392b79a291 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  74356621_dd57_97fa_cf4a_e9392b79a291 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  74356621_dd57_97fa_cf4a_e9392b79a291 --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  c1c8dd57_1ebb_bad3_6e65_32e0aa3099ae["langchain_core.indexing.base"]
  74356621_dd57_97fa_cf4a_e9392b79a291 --> c1c8dd57_1ebb_bad3_6e65_32e0aa3099ae
  style 74356621_dd57_97fa_cf4a_e9392b79a291 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test suite to check index implementations.

Standard tests for the `DocumentIndex` abstraction

We don't recommend implementing externally managed `DocumentIndex` abstractions at this
time.
"""

import inspect
import uuid
from abc import ABC, abstractmethod
from collections.abc import AsyncGenerator, Generator

import pytest
from langchain_core.documents import Document
from langchain_core.indexing.base import DocumentIndex


class DocumentIndexerTestSuite(ABC):
    """Test suite for checking the read-write of a document index.

    Implementers should subclass this test suite and provide a fixture that returns an
    empty index for each test.
    """

    @abstractmethod
    @pytest.fixture
    def index(self) -> Generator[DocumentIndex, None, None]:
        """Get the index."""

    def test_upsert_documents_has_no_ids(self, index: DocumentIndex) -> None:
        """Verify that there is no parameter called IDs in upsert."""
        signature = inspect.signature(index.upsert)
        assert "ids" not in signature.parameters

    def test_upsert_no_ids(self, index: DocumentIndex) -> None:
        """Upsert works with documents that do not have IDs.

        At the moment, the ID field in documents is optional.
        """
        documents = [
            Document(page_content="foo", metadata={"id": 1}),
            Document(page_content="bar", metadata={"id": 2}),
        ]
        response = index.upsert(documents)
        ids = sorted(response["succeeded"])

        # Ordering is not guaranteed, need to test carefully
        documents = index.get(ids)
        sorted_documents = sorted(documents, key=lambda x: x.id or "")

        if sorted_documents[0].page_content == "bar":
            assert sorted_documents[0] == Document(
                page_content="bar", metadata={"id": 2}, id=ids[0]
            )
            assert sorted_documents[1] == Document(
                page_content="foo", metadata={"id": 1}, id=ids[1]
            )
        else:
            assert sorted_documents[0] == Document(
// ... (339 more lines)

Subdomains

Dependencies

  • abc
  • collections.abc
  • inspect
  • langchain_core.documents
  • langchain_core.indexing.base
  • pytest
  • uuid

Frequently Asked Questions

What does indexer.py do?
indexer.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What does indexer.py depend on?
indexer.py imports 7 module(s): abc, collections.abc, inspect, langchain_core.documents, langchain_core.indexing.base, pytest, uuid.
Where is indexer.py in the architecture?
indexer.py is located at libs/standard-tests/langchain_tests/integration_tests/indexer.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/standard-tests/langchain_tests/integration_tests).

Analyze Your Own Codebase

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

Try Supermodel Free