mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-16 15:04:13 +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:
@@ -83,6 +83,53 @@ def test_deeplakewith_persistence() -> None:
|
||||
# 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:
|
||||
"""Test similarity search."""
|
||||
output = deeplake_datastore.similarity_search(
|
||||
|
Reference in New Issue
Block a user