Skip to content

Commit

Permalink
core[patch]: Update API reference for fake embeddings (langchain-ai#2…
Browse files Browse the repository at this point in the history
…5313)

Issue: langchain-ai#24856

Using the same template for the fake embeddings in langchain_core as
used in the integrations.
  • Loading branch information
eyurtsev authored and olgamurraft committed Aug 16, 2024
1 parent 4111737 commit 47cdfae
Showing 1 changed file with 52 additions and 8 deletions.
60 changes: 52 additions & 8 deletions libs/core/langchain_core/embeddings/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,36 @@ class FakeEmbeddings(Embeddings, BaseModel):
Do not use this outside of testing, as it is not a real embedding model.
Example:
Instantiate:
.. code-block:: python
from langchain_core.embeddings import FakeEmbeddings
embed = FakeEmbeddings(size=100)
Embed single text:
.. code-block:: python
input_text = "The meaning of life is 42"
vector = embed.embed_query(input_text)
print(vector[:3])
.. code-block:: python
[-0.700234640213188, -0.581266257710429, -1.1328482266445354]
Embed multiple texts:
.. code-block:: 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])
.. code-block:: python
fake_embeddings = FakeEmbeddings(size=100)
fake_embeddings.embed_documents(["hello world", "foo bar"])
2
[-0.5670477847544458, -0.31403828652395727, -0.5840547508955257]
"""

size: int
Expand All @@ -48,14 +70,36 @@ class DeterministicFakeEmbedding(Embeddings, BaseModel):
Do not use this outside of testing, as it is not a real embedding model.
Example:
Instantiate:
.. code-block:: python
from langchain_core.embeddings import DeterministicFakeEmbedding
embed = DeterministicFakeEmbedding(size=100)
Embed single text:
.. code-block:: python
input_text = "The meaning of life is 42"
vector = embed.embed_query(input_text)
print(vector[:3])
.. code-block:: python
[-0.700234640213188, -0.581266257710429, -1.1328482266445354]
Embed multiple texts:
.. code-block:: 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])
.. code-block:: python
fake_embeddings = DeterministicFakeEmbedding(size=100)
fake_embeddings.embed_documents(["hello world", "foo bar"])
2
[-0.5670477847544458, -0.31403828652395727, -0.5840547508955257]
"""

size: int
Expand Down

0 comments on commit 47cdfae

Please sign in to comment.