ConsistentFakeEmbeddings Class — langchain Architecture
Architecture documentation for the ConsistentFakeEmbeddings class in fake_embeddings.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD d3609afb_32d8_29f5_39d7_a97fc460c871["ConsistentFakeEmbeddings"] dca08b34_f922_a3fa_4752_e72b03b86d89["FakeEmbeddings"] d3609afb_32d8_29f5_39d7_a97fc460c871 -->|extends| dca08b34_f922_a3fa_4752_e72b03b86d89 b656da5c_781f_2669_c8cd_83d309b3feb8["fake_embeddings.py"] d3609afb_32d8_29f5_39d7_a97fc460c871 -->|defined in| b656da5c_781f_2669_c8cd_83d309b3feb8 b45a6e68_5f94_600e_aac0_4c435ce833f9["__init__()"] d3609afb_32d8_29f5_39d7_a97fc460c871 -->|method| b45a6e68_5f94_600e_aac0_4c435ce833f9 83a52020_7802_533b_0bc5_92c500327050["embed_documents()"] d3609afb_32d8_29f5_39d7_a97fc460c871 -->|method| 83a52020_7802_533b_0bc5_92c500327050 424b48f2_1163_8b09_3d82_077893289663["embed_query()"] d3609afb_32d8_29f5_39d7_a97fc460c871 -->|method| 424b48f2_1163_8b09_3d82_077893289663
Relationship Graph
Source Code
libs/langchain_v1/tests/integration_tests/cache/fake_embeddings.py lines 39–68
class ConsistentFakeEmbeddings(FakeEmbeddings):
"""Consistent fake embeddings.
Fake embeddings which remember all the texts seen so far to return consistent
vectors for the same texts.
"""
def __init__(self, dimensionality: int = 10) -> None:
self.known_texts: list[str] = []
self.dimensionality = dimensionality
def embed_documents(self, texts: list[str]) -> list[list[float]]:
"""Return consistent embeddings for each text seen so far."""
out_vectors = []
for text in texts:
if text not in self.known_texts:
self.known_texts.append(text)
vector = [1.0] * (self.dimensionality - 1) + [
float(self.known_texts.index(text)),
]
out_vectors.append(vector)
return out_vectors
def embed_query(self, text: str) -> list[float]:
"""Return consistent embeddings.
Return consistent embeddings for the text, if seen before, or a constant
one if the text is unknown.
"""
return self.embed_documents([text])[0]
Extends
Source
Frequently Asked Questions
What is the ConsistentFakeEmbeddings class?
ConsistentFakeEmbeddings is a class in the langchain codebase, defined in libs/langchain_v1/tests/integration_tests/cache/fake_embeddings.py.
Where is ConsistentFakeEmbeddings defined?
ConsistentFakeEmbeddings is defined in libs/langchain_v1/tests/integration_tests/cache/fake_embeddings.py at line 39.
What does ConsistentFakeEmbeddings extend?
ConsistentFakeEmbeddings extends FakeEmbeddings.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free