-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented get_nodes() in deeplake vector store (#14388)
- Loading branch information
1 parent
5373d9f
commit 720e4b4
Showing
3 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,17 +21,18 @@ ignore_missing_imports = true | |
python_version = "3.8" | ||
|
||
[tool.poetry] | ||
authors = ["Your Name <[email protected]>"] | ||
authors = ["Activeloop <[email protected]>"] | ||
description = "llama-index vector_stores deeplake integration" | ||
exclude = ["**/BUILD"] | ||
license = "MIT" | ||
name = "llama-index-vector-stores-deeplake" | ||
readme = "README.md" | ||
version = "0.1.2" | ||
version = "0.1.3" | ||
|
||
[tool.poetry.dependencies] | ||
python = ">=3.8.1,<4.0" | ||
llama-index-core = "^0.10.1" | ||
deeplake = ">=3.9.0" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
ipython = "8.10.0" | ||
|
97 changes: 96 additions & 1 deletion
97
...ons/vector_stores/llama-index-vector-stores-deeplake/tests/test_vector_stores_deeplake.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,102 @@ | ||
from llama_index.core.vector_stores.types import BasePydanticVectorStore | ||
from llama_index.core import Document | ||
from llama_index.core.vector_stores.types import ( | ||
BasePydanticVectorStore, | ||
MetadataFilter, | ||
MetadataFilters, | ||
FilterCondition, | ||
FilterOperator, | ||
) | ||
from llama_index.vector_stores.deeplake import DeepLakeVectorStore | ||
|
||
|
||
def test_class(): | ||
names_of_base_classes = [b.__name__ for b in DeepLakeVectorStore.__mro__] | ||
assert BasePydanticVectorStore.__name__ in names_of_base_classes | ||
|
||
|
||
def test_e2e(): | ||
vs = DeepLakeVectorStore(dataset_path="mem://test", overwrite=True) | ||
ids = vs.add( | ||
nodes=[ | ||
Document(text="Doc 1", embedding=[1, 2, 1], metadata={"a": "1", "b": 10}), | ||
Document(text="Doc 2", embedding=[1, 2, 2], metadata={"a": "2", "b": 11}), | ||
Document(text="Doc 3", embedding=[1, 2, 3], metadata={"a": "3", "b": 12}), | ||
] | ||
) | ||
|
||
nodes = vs.get_nodes(node_ids=[ids[0], ids[2]]) | ||
assert [x.text for x in nodes] == ["Doc 1", "Doc 3"] | ||
|
||
nodes = vs.get_nodes(node_ids=["a"]) | ||
assert len(nodes) == 0 | ||
|
||
assert [ | ||
x.text | ||
for x in vs.get_nodes( | ||
filters=MetadataFilters( | ||
filters=[ | ||
MetadataFilter(key="a", value="2"), | ||
] | ||
) | ||
) | ||
] == ["Doc 2"] | ||
|
||
assert [ | ||
x.text | ||
for x in vs.get_nodes( | ||
filters=MetadataFilters( | ||
filters=[ | ||
MetadataFilter(key="a", value="2"), | ||
MetadataFilter(key="a", value="3"), | ||
] | ||
) | ||
) | ||
] == [] | ||
|
||
assert [ | ||
x.text | ||
for x in vs.get_nodes( | ||
filters=MetadataFilters( | ||
condition=FilterCondition.OR, | ||
filters=[ | ||
MetadataFilter(key="a", value="2"), | ||
MetadataFilter(key="a", value="3"), | ||
], | ||
) | ||
) | ||
] == ["Doc 2", "Doc 3"] | ||
|
||
assert [ | ||
x.text | ||
for x in vs.get_nodes( | ||
filters=MetadataFilters( | ||
condition=FilterCondition.OR, | ||
filters=[ | ||
MetadataFilter(key="a", value="2"), | ||
MetadataFilter(key="a", value="3"), | ||
], | ||
) | ||
) | ||
] == ["Doc 2", "Doc 3"] | ||
|
||
assert [ | ||
x.text | ||
for x in vs.get_nodes( | ||
filters=MetadataFilters( | ||
filters=[ | ||
MetadataFilter(key="b", value=10, operator=FilterOperator.GT), | ||
] | ||
) | ||
) | ||
] == ["Doc 2", "Doc 3"] | ||
|
||
assert [ | ||
x.text | ||
for x in vs.get_nodes( | ||
filters=MetadataFilters( | ||
filters=[ | ||
MetadataFilter(key="b", value=11, operator=FilterOperator.LTE), | ||
] | ||
) | ||
) | ||
] == ["Doc 1", "Doc 2"] |