ConsistentFakeSparseEmbeddings Class — langchain Architecture
Architecture documentation for the ConsistentFakeSparseEmbeddings class in common.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e01269d9_4bda_3502_ba27_5bad4874d109["ConsistentFakeSparseEmbeddings"] d2c50637_94ac_9030_8f99_d10858fb4c29["SparseEmbeddings"] e01269d9_4bda_3502_ba27_5bad4874d109 -->|extends| d2c50637_94ac_9030_8f99_d10858fb4c29 b62fe5d9_7b83_0e14_ef50_3645cafa8bc5["common.py"] e01269d9_4bda_3502_ba27_5bad4874d109 -->|defined in| b62fe5d9_7b83_0e14_ef50_3645cafa8bc5 f03b2f6c_27fa_56c7_4cb2_ae73cc7ab8b0["__init__()"] e01269d9_4bda_3502_ba27_5bad4874d109 -->|method| f03b2f6c_27fa_56c7_4cb2_ae73cc7ab8b0 b9e09bee_ce68_fd2b_005f_81e22de97c53["embed_documents()"] e01269d9_4bda_3502_ba27_5bad4874d109 -->|method| b9e09bee_ce68_fd2b_005f_81e22de97c53 5369e966_8af1_33ce_87ff_9b00c71877a5["embed_query()"] e01269d9_4bda_3502_ba27_5bad4874d109 -->|method| 5369e966_8af1_33ce_87ff_9b00c71877a5
Relationship Graph
Source Code
libs/partners/qdrant/tests/integration_tests/common.py lines 61–86
class ConsistentFakeSparseEmbeddings(SparseEmbeddings):
"""Fake sparse embeddings which remembers all the texts seen so far
"to return consistent vectors for the same texts.
"""
def __init__(self, dimensionality: int = 25) -> None:
self.known_texts: list[str] = []
self.dimensionality = dimensionality
def embed_documents(self, texts: list[str]) -> list[SparseVector]:
"""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)
index = self.known_texts.index(text)
indices = [i + index for i in range(self.dimensionality)]
values = [1.0] * (self.dimensionality - 1) + [float(index)]
out_vectors.append(SparseVector(indices=indices, values=values))
return out_vectors
def embed_query(self, text: str) -> SparseVector:
"""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 ConsistentFakeSparseEmbeddings class?
ConsistentFakeSparseEmbeddings is a class in the langchain codebase, defined in libs/partners/qdrant/tests/integration_tests/common.py.
Where is ConsistentFakeSparseEmbeddings defined?
ConsistentFakeSparseEmbeddings is defined in libs/partners/qdrant/tests/integration_tests/common.py at line 61.
What does ConsistentFakeSparseEmbeddings extend?
ConsistentFakeSparseEmbeddings extends SparseEmbeddings.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free