`insecureHash` function in langchainjs source code.
In this article, we will review insecureHash
function in langchainjs source code. we will look at:
-
insecureHash
function definition -
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
References:
-
https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/embeddings/cache_backed.ts#L1
-
https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/embeddings/cache_backed.ts#L155
-
https://github.com/langchain-ai/langchainjs/blob/main/langchain-core/src/utils/js-sha1/hash.ts#L415
-
https://github.com/langchain-ai/langchainjs/blob/main/langchain-core/src/utils/js-sha1/hash.ts#L24