Blog
`insecureHash` function in langchainjs source code.

`insecureHash` function in langchainjs source code.

In this article, we will review insecureHash function in langchainjs source code. we will look at: 

  1. insecureHash function definition

  2. Where is insecureHash invoked?

insecureHash function definition

you will find the below code in langchainjs/langchain-core/src/utils/js-sha1hash.ts

export const insecureHash = (message) => {
  return new Sha1(true).update(message)["hex"]();
};

sha1 function is defined in the same file at line 24:

function Sha1(sharedMemory) {
  if (sharedMemory) {
    blocks[0] =
      blocks[16] =
      blocks[1] =
      blocks[2] =
      blocks[3] =
      blocks[4] =

Learn more about sha1.

Where is insecureHash invoked?

I found that insecureHash is imported in a file named cache_backed.ts as shown below:

import { insecureHash } from "@langchain/core/utils/hash";

At line 155 in cache_backed.ts, you will find that insecureHash is invoked as shown below:

 const encoderBackedStore = new EncoderBackedStore<
      string,
      number[],
      Uint8Array
    >({
      store: documentEmbeddingStore,
      keyEncoder: (key) => (options?.namespace ?? "") + insecureHash(key),

There are 14 references to insecureHash function in the langchainjs codebase.

About me

Hey, my name is Ramu Narasinga. I study codebase architecture in large open-source projects.

Email: ramu.narasinga@gmail.com

Build Shadcn CLI from scratch.

References:

  1. https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/embeddings/cache_backed.ts#L1

  2. https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/embeddings/cache_backed.ts#L155

  3. https://github.com/langchain-ai/langchainjs/blob/main/langchain-core/src/utils/js-sha1/hash.ts#L415

  4. https://github.com/langchain-ai/langchainjs/blob/main/langchain-core/src/utils/js-sha1/hash.ts#L24

We use cookies
We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.

Learn more