Home / Function/ test_inmemory_filter_by_document_id() — langchain Function Reference

test_inmemory_filter_by_document_id() — langchain Function Reference

Architecture documentation for the test_inmemory_filter_by_document_id() function in test_in_memory.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  5fcc7932_3738_afa9_3b29_a7d7c6dca292["test_inmemory_filter_by_document_id()"]
  a974d690_d5fa_ba65_671d_ce8278eefe7d["test_in_memory.py"]
  5fcc7932_3738_afa9_3b29_a7d7c6dca292 -->|defined in| a974d690_d5fa_ba65_671d_ce8278eefe7d
  style 5fcc7932_3738_afa9_3b29_a7d7c6dca292 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/vectorstores/test_in_memory.py lines 120–151

async def test_inmemory_filter_by_document_id() -> None:
    """Test filtering by document ID field."""
    embedding = DeterministicFakeEmbedding(size=6)
    store = InMemoryVectorStore(embedding=embedding)

    # Add documents with specific IDs using add_documents
    documents = [
        Document(page_content="first document", id="doc_1"),
        Document(page_content="second document", id="doc_2"),
        Document(page_content="third document", id="doc_3"),
    ]
    store.add_documents(documents)

    # Test filtering by specific document ID
    output = store.similarity_search("document", filter=lambda doc: doc.id == "doc_2")
    assert len(output) == 1
    assert output[0].page_content == "second document"
    assert output[0].id == "doc_2"

    # Test async version
    output = await store.asimilarity_search(
        "document", filter=lambda doc: doc.id in {"doc_1", "doc_3"}
    )
    assert len(output) == 2
    ids = {doc.id for doc in output}
    assert ids == {"doc_1", "doc_3"}

    # Test filtering with non-existent ID
    output = store.similarity_search(
        "document", filter=lambda doc: doc.id == "non_existent"
    )
    assert output == []

Domain

Subdomains

Frequently Asked Questions

What does test_inmemory_filter_by_document_id() do?
test_inmemory_filter_by_document_id() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/vectorstores/test_in_memory.py.
Where is test_inmemory_filter_by_document_id() defined?
test_inmemory_filter_by_document_id() is defined in libs/core/tests/unit_tests/vectorstores/test_in_memory.py at line 120.

Analyze Your Own Codebase

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

Try Supermodel Free