Home / File/ fake.py — langchain Source File

fake.py — langchain Source File

Architecture documentation for fake.py, a python file in the langchain codebase. 6 imports, 0 dependents.

File python CoreAbstractions Serialization 6 imports 1 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  11efe23b_60e7_3caa_e6e9_4e2ebbca866c["fake.py"]
  69e1d8cc_6173_dcd0_bfdf_2132d8e1ce56["contextlib"]
  11efe23b_60e7_3caa_e6e9_4e2ebbca866c --> 69e1d8cc_6173_dcd0_bfdf_2132d8e1ce56
  ca3eea8c_ddf5_4ba7_a40c_5ed2287c91fa["hashlib"]
  11efe23b_60e7_3caa_e6e9_4e2ebbca866c --> ca3eea8c_ddf5_4ba7_a40c_5ed2287c91fa
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  11efe23b_60e7_3caa_e6e9_4e2ebbca866c --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  11efe23b_60e7_3caa_e6e9_4e2ebbca866c --> 91721f45_4909_e489_8c1f_084f8bd87145
  bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3["langchain_core.embeddings"]
  11efe23b_60e7_3caa_e6e9_4e2ebbca866c --> bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3
  cd17727f_b882_7f06_aadc_71fbf75bebb0["numpy"]
  11efe23b_60e7_3caa_e6e9_4e2ebbca866c --> cd17727f_b882_7f06_aadc_71fbf75bebb0
  style 11efe23b_60e7_3caa_e6e9_4e2ebbca866c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Module contains a few fake embedding models for testing purposes."""

# Please do not add additional fake embedding model implementations here.
import contextlib
import hashlib

from pydantic import BaseModel
from typing_extensions import override

from langchain_core.embeddings import Embeddings

with contextlib.suppress(ImportError):
    import numpy as np


class FakeEmbeddings(Embeddings, BaseModel):
    """Fake embedding model for unit testing purposes.

    This embedding model creates embeddings by sampling from a normal distribution.

    !!! danger "Toy model"
        Do not use this outside of testing, as it is not a real embedding model.

    Instantiate:
        ```python
        from langchain_core.embeddings import FakeEmbeddings

        embed = FakeEmbeddings(size=100)
        ```

    Embed single text:
        ```python
        input_text = "The meaning of life is 42"
        vector = embed.embed_query(input_text)
        print(vector[:3])
        ```
        ```python
        [-0.700234640213188, -0.581266257710429, -1.1328482266445354]
        ```

    Embed multiple texts:
        ```python
        input_texts = ["Document 1...", "Document 2..."]
        vectors = embed.embed_documents(input_texts)
        print(len(vectors))
        # The first 3 coordinates for the first vector
        print(vectors[0][:3])
        ```
        ```python
        2
        [-0.5670477847544458, -0.31403828652395727, -0.5840547508955257]
        ```
    """

    size: int
    """The size of the embedding vector."""

    def _get_embedding(self) -> list[float]:
        return list(np.random.default_rng().normal(size=self.size))

// ... (70 more lines)

Subdomains

Functions

Dependencies

  • contextlib
  • hashlib
  • langchain_core.embeddings
  • numpy
  • pydantic
  • typing_extensions

Frequently Asked Questions

What does fake.py do?
fake.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in fake.py?
fake.py defines 1 function(s): numpy.
What does fake.py depend on?
fake.py imports 6 module(s): contextlib, hashlib, langchain_core.embeddings, numpy, pydantic, typing_extensions.
Where is fake.py in the architecture?
fake.py is located at libs/core/langchain_core/embeddings/fake.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/langchain_core/embeddings).

Analyze Your Own Codebase

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

Try Supermodel Free