Home / Function/ _calculate_hash() — langchain Function Reference

_calculate_hash() — langchain Function Reference

Architecture documentation for the _calculate_hash() function in api.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  7e7cfd04_d4fe_3b49_495a_ea18e26a1fd0["_calculate_hash()"]
  0a83ef61_4c07_e8b4_648c_4199ec598979["api.py"]
  7e7cfd04_d4fe_3b49_495a_ea18e26a1fd0 -->|defined in| 0a83ef61_4c07_e8b4_648c_4199ec598979
  15e1884a_a842_1f4a_5894_1426029cd476["_hash_string()"]
  15e1884a_a842_1f4a_5894_1426029cd476 -->|calls| 7e7cfd04_d4fe_3b49_495a_ea18e26a1fd0
  26b06c48_3bce_bb30_a328_99416f46d276["_get_document_with_hash()"]
  26b06c48_3bce_bb30_a328_99416f46d276 -->|calls| 7e7cfd04_d4fe_3b49_495a_ea18e26a1fd0
  style 7e7cfd04_d4fe_3b49_495a_ea18e26a1fd0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/indexing/api.py lines 151–166

def _calculate_hash(
    text: str, algorithm: Literal["sha1", "sha256", "sha512", "blake2b"]
) -> str:
    """Return a hexadecimal digest of *text* using *algorithm*."""
    if algorithm == "sha1":
        # Calculate the SHA-1 hash and return it as a UUID.
        digest = hashlib.sha1(text.encode("utf-8"), usedforsecurity=False).hexdigest()
        return str(uuid.uuid5(NAMESPACE_UUID, digest))
    if algorithm == "blake2b":
        return hashlib.blake2b(text.encode("utf-8")).hexdigest()
    if algorithm == "sha256":
        return hashlib.sha256(text.encode("utf-8")).hexdigest()
    if algorithm == "sha512":
        return hashlib.sha512(text.encode("utf-8")).hexdigest()
    msg = f"Unsupported hashing algorithm: {algorithm}"
    raise ValueError(msg)

Subdomains

Frequently Asked Questions

What does _calculate_hash() do?
_calculate_hash() is a function in the langchain codebase, defined in libs/core/langchain_core/indexing/api.py.
Where is _calculate_hash() defined?
_calculate_hash() is defined in libs/core/langchain_core/indexing/api.py at line 151.
What calls _calculate_hash()?
_calculate_hash() is called by 2 function(s): _get_document_with_hash, _hash_string.

Analyze Your Own Codebase

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

Try Supermodel Free