Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved deeplake.get_nodes() performance #14920

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, List, Optional, cast

from llama_index.core.bridge.pydantic import PrivateAttr
from llama_index.core.schema import BaseNode, MetadataMode
from llama_index.core.schema import BaseNode, MetadataMode, TextNode
from llama_index.core.vector_stores.types import (
BasePydanticVectorStore,
VectorStoreQuery,
Expand Down Expand Up @@ -149,10 +149,10 @@ def get_nodes(
filters: Optional[MetadataFilters] = None,
) -> List[BaseNode]:
"""Get nodes from vector store."""
if not node_ids:
data = self._vectorstore.search(filter=lambda x: True)
if node_ids:
data = self._vectorstore.search(filter={"id": node_ids})
else:
data = self._vectorstore.search(filter=lambda x: x.id.text() in node_ids)
data = self._vectorstore.search(filter={})

nodes = []
for metadata in data["metadata"]:
Expand Down Expand Up @@ -196,7 +196,10 @@ def filter_func(doc):

return found_one

return [x for x in nodes if filter_func(x)]
if filters:
return [x for x in nodes if filter_func(x)]
else:
return nodes

def delete_nodes(
self,
Expand Down Expand Up @@ -294,6 +297,8 @@ def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResul
metadatas = data["metadata"]
nodes = []
for metadata in metadatas:
if "_node_type" not in metadata:
metadata["_node_type"] = TextNode.class_name()
nodes.append(metadata_dict_to_node(metadata))

return VectorStoreQueryResult(nodes=nodes, similarities=similarities, ids=ids)
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-vector-stores-deeplake"
readme = "README.md"
version = "0.1.4"
version = "0.1.5"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
llama-index-core = "^0.10.1"
deeplake = ">=3.9.0"
deeplake = ">=3.9.12"

[tool.poetry.group.dev.dependencies]
ipython = "8.10.0"
Expand Down
Loading