DeepLake Backwards compatibility fix (#13388)

- **Description:** during search with DeepLake some people are facing
backwards compatibility issues, this PR fixes it by making search
accessible for the older datasets

---------

Co-authored-by: adolkhan <adilkhan.sarsen@alumni.nu.edu.kz>
This commit is contained in:
Adilkhan Sarsen 2023-11-20 11:46:01 +06:00 committed by GitHub
parent 190952fe76
commit 10418ab0c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -413,7 +413,7 @@ class DeepLake(VectorStore):
distance_metric=distance_metric,
filter=filter,
exec_option=exec_option,
return_tensors=["embedding", "metadata", "text", "id"],
return_tensors=["embedding", "metadata", "text", self._id_tensor_name],
deep_memory=deep_memory,
)

View File

@ -259,3 +259,25 @@ def test_add_texts(deeplake_datastore: DeepLake) -> None:
texts=texts,
metada=metadatas,
)
def test_ids_backwards_compatibility() -> None:
"""Test that ids are backwards compatible."""
db = DeepLake(
dataset_path="mem://test_path",
embedding_function=FakeEmbeddings(),
tensor_params=[
{"name": "ids", "htype": "text"},
{"name": "text", "htype": "text"},
{"name": "embedding", "htype": "embedding"},
{"name": "metadata", "htype": "json"},
],
)
db.vectorstore.add(
ids=["1", "2", "3"],
text=["foo", "bar", "baz"],
embedding=FakeEmbeddings().embed_documents(["foo", "bar", "baz"]),
metadata=[{"page": str(i)} for i in range(3)],
)
output = db.similarity_search("foo", k=1)
assert len(output) == 1