mirror of https://github.com/hwchase17/langchain
Deterministic Fake Embedding Model (#8706)
Solves #8644 This embedding models output identical random embedding vectors, given the input texts are identical. Useful when used in unittest. @baskaryanpull/8694/head
parent
2928a1a3c9
commit
4e8f11b36a
@ -0,0 +1,16 @@
|
||||
from langchain.embeddings import DeterministicFakeEmbedding
|
||||
|
||||
|
||||
def test_deterministic_fake_embeddings() -> None:
|
||||
"""
|
||||
Test that the deterministic fake embeddings return the same
|
||||
embedding vector for the same text.
|
||||
"""
|
||||
fake = DeterministicFakeEmbedding(size=10)
|
||||
text = "Hello world!"
|
||||
assert fake.embed_query(text) == fake.embed_query(text)
|
||||
assert fake.embed_query(text) != fake.embed_query("Goodbye world!")
|
||||
assert fake.embed_documents([text, text]) == fake.embed_documents([text, text])
|
||||
assert fake.embed_documents([text, text]) != fake.embed_documents(
|
||||
[text, "Goodbye world!"]
|
||||
)
|
Loading…
Reference in New Issue