mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-05 22:53:30 +00:00
Fixing DeepLake Overwrite Flag (#4683)
# Fix DeepLake Overwrite Flag Issue Fixes Issue #4682: essentially, setting overwrite to False in the DeepLake constructor still triggers an overwrite, because the logic is just checking for the presence of "overwrite" in kwargs. The fix is simple--just add some checks to inspect if "overwrite" in kwargs AND kwargs["overwrite"]==True. Added a new test in tests/integration_tests/vectorstores/test_deeplake.py to reflect the desired behavior. Co-authored-by: Anirudh Suresh <ani@Anirudhs-MBP.cable.rcn.com> Co-authored-by: Anirudh Suresh <ani@Anirudhs-MacBook-Pro.local> Co-authored-by: Dev 2049 <dev.dev2049@gmail.com>
This commit is contained in:
parent
8bb32d77d0
commit
03ac39368f
@ -120,10 +120,12 @@ class DeepLake(VectorStore):
|
|||||||
self.dataset_path = dataset_path
|
self.dataset_path = dataset_path
|
||||||
creds_args = {"creds": kwargs["creds"]} if "creds" in kwargs else {}
|
creds_args = {"creds": kwargs["creds"]} if "creds" in kwargs else {}
|
||||||
|
|
||||||
if (
|
if deeplake.exists(dataset_path, token=token, **creds_args) and not kwargs.get(
|
||||||
deeplake.exists(dataset_path, token=token, **creds_args)
|
"overwrite", False
|
||||||
and "overwrite" not in kwargs
|
|
||||||
):
|
):
|
||||||
|
if "overwrite" in kwargs:
|
||||||
|
del kwargs["overwrite"]
|
||||||
|
|
||||||
self.ds = deeplake.load(
|
self.ds = deeplake.load(
|
||||||
dataset_path,
|
dataset_path,
|
||||||
token=token,
|
token=token,
|
||||||
|
@ -83,6 +83,53 @@ def test_deeplakewith_persistence() -> None:
|
|||||||
# Or on program exit
|
# Or on program exit
|
||||||
|
|
||||||
|
|
||||||
|
def test_deeplake_overwrite_flag() -> None:
|
||||||
|
"""Test overwrite behavior"""
|
||||||
|
dataset_path = "./tests/persist_dir"
|
||||||
|
if deeplake.exists(dataset_path):
|
||||||
|
deeplake.delete(dataset_path)
|
||||||
|
|
||||||
|
texts = ["foo", "bar", "baz"]
|
||||||
|
docsearch = DeepLake.from_texts(
|
||||||
|
dataset_path=dataset_path,
|
||||||
|
texts=texts,
|
||||||
|
embedding=FakeEmbeddings(),
|
||||||
|
)
|
||||||
|
output = docsearch.similarity_search("foo", k=1)
|
||||||
|
assert output == [Document(page_content="foo")]
|
||||||
|
|
||||||
|
docsearch.persist()
|
||||||
|
|
||||||
|
# Get a new VectorStore from the persisted directory, with no overwrite (implicit)
|
||||||
|
docsearch = DeepLake(
|
||||||
|
dataset_path=dataset_path,
|
||||||
|
embedding_function=FakeEmbeddings(),
|
||||||
|
)
|
||||||
|
output = docsearch.similarity_search("foo", k=1)
|
||||||
|
# assert page still present
|
||||||
|
assert output == [Document(page_content="foo")]
|
||||||
|
|
||||||
|
# Get a new VectorStore from the persisted directory, with no overwrite (explicit)
|
||||||
|
docsearch = DeepLake(
|
||||||
|
dataset_path=dataset_path,
|
||||||
|
embedding_function=FakeEmbeddings(),
|
||||||
|
overwrite=False,
|
||||||
|
)
|
||||||
|
output = docsearch.similarity_search("foo", k=1)
|
||||||
|
# assert page still present
|
||||||
|
assert output == [Document(page_content="foo")]
|
||||||
|
|
||||||
|
# Get a new VectorStore from the persisted directory, with overwrite
|
||||||
|
docsearch = DeepLake(
|
||||||
|
dataset_path=dataset_path,
|
||||||
|
embedding_function=FakeEmbeddings(),
|
||||||
|
overwrite=True,
|
||||||
|
)
|
||||||
|
output = docsearch.similarity_search("foo", k=1)
|
||||||
|
# assert page no longer present
|
||||||
|
assert output == []
|
||||||
|
|
||||||
|
|
||||||
def test_similarity_search(deeplake_datastore: DeepLake, distance_metric: str) -> None:
|
def test_similarity_search(deeplake_datastore: DeepLake, distance_metric: str) -> None:
|
||||||
"""Test similarity search."""
|
"""Test similarity search."""
|
||||||
output = deeplake_datastore.similarity_search(
|
output = deeplake_datastore.similarity_search(
|
||||||
|
Loading…
Reference in New Issue
Block a user