Home / Function/ test_chroma_update_document() — langchain Function Reference

test_chroma_update_document() — langchain Function Reference

Architecture documentation for the test_chroma_update_document() function in test_vectorstores.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  1c364bb2_9b50_663c_fc97_fb37846e1ce5["test_chroma_update_document()"]
  289e5a4f_8e2e_ddb6_af2e_804f91dabdb8["test_vectorstores.py"]
  1c364bb2_9b50_663c_fc97_fb37846e1ce5 -->|defined in| 289e5a4f_8e2e_ddb6_af2e_804f91dabdb8
  style 1c364bb2_9b50_663c_fc97_fb37846e1ce5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/chroma/tests/integration_tests/test_vectorstores.py lines 421–472

def test_chroma_update_document() -> None:
    """Test the update_document function in the Chroma class.

    Uses an external document id.
    """
    # Make a consistent embedding
    embedding = ConsistentFakeEmbeddings()

    # Initial document content and id
    initial_content = "foo"
    document_id = "doc1"

    # Create an instance of Document with initial content and metadata
    original_doc = Document(page_content=initial_content, metadata={"page": "0"})

    # Initialize a Chroma instance with the original document
    docsearch = Chroma.from_documents(
        collection_name="test_collection",
        documents=[original_doc],
        embedding=embedding,
        ids=[document_id],
    )
    old_embedding = docsearch._collection.peek()["embeddings"][  # type: ignore[index]
        docsearch._collection.peek()["ids"].index(document_id)
    ]

    # Define updated content for the document
    updated_content = "updated foo"

    # Create a new Document instance with the updated content and the same id
    updated_doc = Document(page_content=updated_content, metadata={"page": "0"})

    # Update the document in the Chroma instance
    docsearch.update_document(document_id=document_id, document=updated_doc)

    # Perform a similarity search with the updated content
    output = docsearch.similarity_search(updated_content, k=1)

    # Assert that the new embedding is correct
    new_embedding = docsearch._collection.peek()["embeddings"][  # type: ignore[index]
        docsearch._collection.peek()["ids"].index(document_id)
    ]

    docsearch.delete_collection()

    # Assert that the updated document is returned by the search
    assert output == [
        Document(page_content=updated_content, metadata={"page": "0"}, id=document_id),
    ]

    assert list(new_embedding) == list(embedding.embed_documents([updated_content])[0])
    assert list(new_embedding) != list(old_embedding)

Domain

Subdomains

Frequently Asked Questions

What does test_chroma_update_document() do?
test_chroma_update_document() is a function in the langchain codebase, defined in libs/partners/chroma/tests/integration_tests/test_vectorstores.py.
Where is test_chroma_update_document() defined?
test_chroma_update_document() is defined in libs/partners/chroma/tests/integration_tests/test_vectorstores.py at line 421.

Analyze Your Own Codebase

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

Try Supermodel Free