Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b816ab9

Browse filesBrowse files
Adds QueryBuilder to MongoDBAtlasDocumentIndex (#1891)
Signed-off-by: Casey Clements <casey.clements@mongodb.com>
1 parent 6a972d1 commit b816ab9
Copy full SHA for b816ab9

File tree

Expand file treeCollapse file tree

10 files changed

+812
-135
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+812
-135
lines changed

‎docarray/index/backends/helper.py

Copy file name to clipboardExpand all lines: docarray/index/backends/helper.py
+38-1Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Tuple, Type, cast
1+
from typing import Any, Dict, List, Tuple, Type, cast, Set
22

33
from docarray import BaseDoc, DocList
44
from docarray.index.abstract import BaseDocIndex
@@ -20,6 +20,43 @@ def inner(self, *args, **kwargs):
2020
return inner
2121

2222

23+
def _collect_query_required_args(method_name: str, required_args: Set[str] = None):
24+
"""
25+
Returns a function that ensures required keyword arguments are provided.
26+
27+
:param method_name: The name of the method for which the required arguments are being checked.
28+
:type method_name: str
29+
:param required_args: A set containing the names of required keyword arguments. Defaults to None.
30+
:type required_args: Optional[Set[str]]
31+
:return: A function that checks for required keyword arguments before executing the specified method.
32+
Raises ValueError if positional arguments are provided.
33+
Raises TypeError if any required keyword argument is missing.
34+
:rtype: Callable
35+
"""
36+
37+
if required_args is None:
38+
required_args = set()
39+
40+
def inner(self, *args, **kwargs):
41+
if args:
42+
raise ValueError(
43+
f"Positional arguments are not supported for "
44+
f"`{type(self)}.{method_name}`. "
45+
f"Use keyword arguments instead."
46+
)
47+
48+
missing_args = required_args - set(kwargs.keys())
49+
if missing_args:
50+
raise ValueError(
51+
f"`{type(self)}.{method_name}` is missing required argument(s): {', '.join(missing_args)}"
52+
)
53+
54+
updated_query = self._queries + [(method_name, kwargs)]
55+
return type(self)(updated_query)
56+
57+
return inner
58+
59+
2360
def _execute_find_and_filter_query(
2461
doc_index: BaseDocIndex, query: List[Tuple[str, Dict]], reverse_order: bool = False
2562
) -> FindResult:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.