mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
12f868b292
Technically a duplicate fix to #1619 but with unit tests and a small documentation update - Propagate `filter` arg in Chroma `similarity_search` to delegated call to `similarity_search_with_score` - Add `filter` arg to `similarity_search_by_vector` - Clarify doc strings on FakeEmbeddings
23 lines
797 B
Python
23 lines
797 B
Python
"""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]]:
|
|
"""Return simple embeddings.
|
|
Embeddings encode each text as its index."""
|
|
return [[float(1.0)] * 9 + [float(i)] for i in range(len(texts))]
|
|
|
|
def embed_query(self, text: str) -> List[float]:
|
|
"""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."""
|
|
return [float(1.0)] * 9 + [float(0.0)]
|