test_caching.py — langchain Source File
Architecture documentation for test_caching.py, a python file in the langchain codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2["test_caching.py"] be45a0bb_0276_f8f1_f985_55cddb92c224["contextlib"] 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 --> be45a0bb_0276_f8f1_f985_55cddb92c224 c6bd1194_66ec_96b5_6f2d_9d539df99ba4["hashlib"] 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 --> c6bd1194_66ec_96b5_6f2d_9d539df99ba4 3b5ab66f_4fcb_ca7c_bc35_2244b5f521fc["importlib"] 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 --> 3b5ab66f_4fcb_ca7c_bc35_2244b5f521fc f3365e3c_fb7a_bb9a_bc79_059b06cb7024["warnings"] 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 --> f3365e3c_fb7a_bb9a_bc79_059b06cb7024 f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"] 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba 918b8514_ba55_6df2_7254_4598ec160e33["langchain_core.embeddings"] 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 --> 918b8514_ba55_6df2_7254_4598ec160e33 f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"] 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 --> f85fae70_1011_eaec_151c_4083140ae9e5 23b339f6_cc24_038f_da0a_a0bad4101f7b["langchain_classic.embeddings"] 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 --> 23b339f6_cc24_038f_da0a_a0bad4101f7b 095b96f1_cb8c_a51f_a3a3_19ae2071ab88["langchain_classic.storage.in_memory"] 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 --> 095b96f1_cb8c_a51f_a3a3_19ae2071ab88 style 6b1a1e58_d1bc_2756_cc7d_9c01f64a73a2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Embeddings tests."""
import contextlib
import hashlib
import importlib
import warnings
import pytest
from langchain_core.embeddings import Embeddings
from typing_extensions import override
from langchain_classic.embeddings import CacheBackedEmbeddings
from langchain_classic.storage.in_memory import InMemoryStore
class MockEmbeddings(Embeddings):
@override
def embed_documents(self, texts: list[str]) -> list[list[float]]:
# Simulate embedding documents
embeddings: list[list[float]] = []
for text in texts:
if text == "RAISE_EXCEPTION":
msg = "Simulated embedding failure"
raise ValueError(msg)
embeddings.append([len(text), len(text) + 1])
return embeddings
@override
def embed_query(self, text: str) -> list[float]:
# Simulate embedding a query
return [5.0, 6.0]
@pytest.fixture
def cache_embeddings() -> CacheBackedEmbeddings:
"""Create a cache backed embeddings."""
store = InMemoryStore()
embeddings = MockEmbeddings()
return CacheBackedEmbeddings.from_bytes_store(
embeddings,
store,
namespace="test_namespace",
)
@pytest.fixture
def cache_embeddings_batch() -> CacheBackedEmbeddings:
"""Create a cache backed embeddings with a batch_size of 3."""
store = InMemoryStore()
embeddings = MockEmbeddings()
return CacheBackedEmbeddings.from_bytes_store(
embeddings,
store,
namespace="test_namespace",
batch_size=3,
)
@pytest.fixture
def cache_embeddings_with_query() -> CacheBackedEmbeddings:
// ... (194 more lines)
Domain
Subdomains
Functions
- cache_embeddings()
- cache_embeddings_batch()
- cache_embeddings_with_query()
- test_aembed_documents()
- test_aembed_documents_batch()
- test_aembed_query()
- test_aembed_query_cached()
- test_blake2b_encoder()
- test_custom_encoder()
- test_embed_cached_query()
- test_embed_documents()
- test_embed_documents_batch()
- test_embed_query()
- test_sha1_warning_emitted_once()
- test_sha256_encoder()
- test_sha512_encoder()
Classes
Dependencies
- contextlib
- hashlib
- importlib
- langchain_classic.embeddings
- langchain_classic.storage.in_memory
- langchain_core.embeddings
- pytest
- typing_extensions
- warnings
Source
Frequently Asked Questions
What does test_caching.py do?
test_caching.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in test_caching.py?
test_caching.py defines 16 function(s): cache_embeddings, cache_embeddings_batch, cache_embeddings_with_query, test_aembed_documents, test_aembed_documents_batch, test_aembed_query, test_aembed_query_cached, test_blake2b_encoder, test_custom_encoder, test_embed_cached_query, and 6 more.
What does test_caching.py depend on?
test_caching.py imports 9 module(s): contextlib, hashlib, importlib, langchain_classic.embeddings, langchain_classic.storage.in_memory, langchain_core.embeddings, pytest, typing_extensions, and 1 more.
Where is test_caching.py in the architecture?
test_caching.py is located at libs/langchain/tests/unit_tests/embeddings/test_caching.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/langchain/tests/unit_tests/embeddings).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free