Home / Function/ test_chroma_with_persistence() — langchain Function Reference

test_chroma_with_persistence() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/partners/chroma/tests/integration_tests/test_vectorstores.py lines 282–325

def test_chroma_with_persistence() -> None:
    """Test end to end construction and search, with persistence."""
    with tempfile.TemporaryDirectory() as chroma_persist_dir:
        collection_name = "test_collection"
        texts = ["foo", "bar", "baz"]
        ids = [f"id_{i}" for i in range(len(texts))]

        docsearch = Chroma.from_texts(
            collection_name=collection_name,
            texts=texts,
            embedding=FakeEmbeddings(),
            persist_directory=chroma_persist_dir,
            ids=ids,
        )

        try:
            output = docsearch.similarity_search("foo", k=1)
            assert output == [Document(page_content="foo", id="id_0")]

            assert Path(chroma_persist_dir).exists()

            # Get a new VectorStore from the persisted directory
            docsearch = Chroma(
                collection_name=collection_name,
                embedding_function=FakeEmbeddings(),
                persist_directory=chroma_persist_dir,
            )
            output = docsearch.similarity_search("foo", k=1)
            assert output == [Document(page_content="foo", id="id_0")]

            # Clean up
            docsearch.delete_collection()

            # Persist doesn't need to be called again
            # Data will be automatically persisted on object deletion
            # Or on program exit

        finally:
            # Need to stop the chrom system database and segment manager
            # to be able to delete the files after testing
            client = docsearch._client
            assert isinstance(client, chromadb.ClientCreator)
            assert isinstance(client._server, RustBindingsAPI)
            client._server.stop()

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free