Home / Function/ _sha1_hash_to_uuid() — langchain Function Reference

_sha1_hash_to_uuid() — langchain Function Reference

Architecture documentation for the _sha1_hash_to_uuid() function in cache.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  99053033_7939_d7bd_a0d9_537c144d34a0["_sha1_hash_to_uuid()"]
  43da8c3d_b3f8_9614_dc29_d2a6402cffbd["cache.py"]
  99053033_7939_d7bd_a0d9_537c144d34a0 -->|defined in| 43da8c3d_b3f8_9614_dc29_d2a6402cffbd
  4b1f75e8_3a36_4d2e_f5d9_04dbd0255a60["_make_default_key_encoder()"]
  4b1f75e8_3a36_4d2e_f5d9_04dbd0255a60 -->|calls| 99053033_7939_d7bd_a0d9_537c144d34a0
  style 99053033_7939_d7bd_a0d9_537c144d34a0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/embeddings/cache.py lines 28–40

def _sha1_hash_to_uuid(text: str) -> uuid.UUID:
    """Return a UUID derived from *text* using SHA-1 (deterministic).

    Deterministic and fast, **but not collision-resistant**.

    A malicious attacker could try to create two different texts that hash to the same
    UUID. This may not necessarily be an issue in the context of caching embeddings,
    but new applications should swap this out for a stronger hash function like
    xxHash, BLAKE2 or SHA-256, which are collision-resistant.
    """
    sha1_hex = hashlib.sha1(text.encode("utf-8"), usedforsecurity=False).hexdigest()
    # Embed the hex string in `uuid5` to obtain a valid UUID.
    return uuid.uuid5(NAMESPACE_UUID, sha1_hex)

Domain

Subdomains

Frequently Asked Questions

What does _sha1_hash_to_uuid() do?
_sha1_hash_to_uuid() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/embeddings/cache.py.
Where is _sha1_hash_to_uuid() defined?
_sha1_hash_to_uuid() is defined in libs/langchain/langchain_classic/embeddings/cache.py at line 28.
What calls _sha1_hash_to_uuid()?
_sha1_hash_to_uuid() is called by 1 function(s): _make_default_key_encoder.

Analyze Your Own Codebase

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

Try Supermodel Free