2023-02-03 06:05:47 +00:00
|
|
|
"""Fake Embedding class for testing purposes."""
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from langchain.embeddings.base import Embeddings
|
|
|
|
|
|
|
|
fake_texts = ["foo", "bar", "baz"]
|
|
|
|
|
|
|
|
|
|
|
|
class FakeEmbeddings(Embeddings):
|
|
|
|
"""Fake embeddings functionality for testing."""
|
|
|
|
|
|
|
|
def embed_documents(self, texts: List[str]) -> List[List[float]]:
|
2023-03-23 02:40:10 +00:00
|
|
|
"""Return simple embeddings.
|
|
|
|
Embeddings encode each text as its index."""
|
2023-02-17 23:18:09 +00:00
|
|
|
return [[float(1.0)] * 9 + [float(i)] for i in range(len(texts))]
|
2023-02-03 06:05:47 +00:00
|
|
|
|
|
|
|
def embed_query(self, text: str) -> List[float]:
|
2023-03-23 02:40:10 +00:00
|
|
|
"""Return constant query embeddings.
|
|
|
|
Embeddings are identical to embed_documents(texts)[0].
|
|
|
|
Distance to each text will be that text's index,
|
|
|
|
as it was passed to embed_documents."""
|
2023-02-17 23:18:09 +00:00
|
|
|
return [float(1.0)] * 9 + [float(0.0)]
|