Skip to content

Commit

Permalink
feat: allow to limit how many elements retrieve (qdrant) (#14904)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaluma authored Jul 24, 2024
1 parent 34dec27 commit 479d72a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def get_nodes(
self,
node_ids: Optional[List[str]] = None,
filters: Optional[MetadataFilters] = None,
limit: Optional[int] = None,
) -> List[BaseNode]:
"""
Get nodes from the index.
Expand All @@ -316,6 +317,10 @@ def get_nodes(
has_id=node_ids,
)
]
# If we pass a node_ids list,
# we can limit the search to only those nodes
# or less if limit is provided
limit = len(node_ids) if limit is None else min(len(node_ids), limit)

if filters is not None:
filter = self._build_subfilter(filters)
Expand All @@ -337,7 +342,7 @@ def get_nodes(

response = self._client.scroll(
collection_name=self.collection_name,
limit=9999,
limit=limit or 9999,
scroll_filter=filter,
)

Expand All @@ -347,6 +352,7 @@ async def aget_nodes(
self,
node_ids: Optional[List[str]] = None,
filters: Optional[MetadataFilters] = None,
limit: Optional[int] = None,
) -> List[BaseNode]:
"""
Asynchronous method to get nodes from the index.
Expand All @@ -365,6 +371,10 @@ async def aget_nodes(
has_id=node_ids,
)
]
# If we pass a node_ids list,
# we can limit the search to only those nodes
# or less if limit is provided
limit = len(node_ids) if limit is None else min(len(node_ids), limit)

if filters is not None:
filter = self._build_subfilter(filters)
Expand All @@ -377,7 +387,7 @@ async def aget_nodes(

response = await self._aclient.scroll(
collection_name=self.collection_name,
limit=9999,
limit=limit or 9999,
scroll_filter=filter,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-vector-stores-qdrant"
readme = "README.md"
version = "0.2.13"
version = "0.2.14"

[tool.poetry.dependencies]
python = ">=3.9,<3.13"
Expand Down

0 comments on commit 479d72a

Please sign in to comment.