Skip to content

Commit 897b601

Browse files
Add text list attribute for sharepoint integration tags (#101)
* model * any all list filter * chore: pr comments * chore: update submodules * chore: update submodules --------- Co-authored-by: andhreljaKern <[email protected]>
1 parent cb0b3e7 commit 897b601

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ def most_similar_by_embedding(
8080
include_scores: bool = False,
8181
) -> responses.JSONResponse:
8282
"""Find the n most similar records with respect to the specified embedding.
83-
Args:
83+
Args:
8484
embedding_id (str): Embedding id.
8585
record_id (str): The record for which similar records are searched.
8686
limit (int): Specifies the maximum amount of returned records.
87-
att_filter(Optional[Dict[str, Any]]]): Specifies the attribute filter for the search as dict objects.
87+
att_filter (Optional[Dict[str, Any]]]): Specifies the attribute filter for the search as dict objects.
88+
Note: Record values can now also be lists (e.g., {"name": ["John", "Alex"]}).
89+
Filters will match if any or all (type "any" or type "all") of the listed values satisfy the condition.
8890
threshold: Optional[float]: None = calculated DB threshold, -9999 = no threshold, specified = use value
8991
example_filter = [
9092
{"key": "name", "value": ["John", "Doe"]}, -> name IN ("John", "Doe")

neural_search/util.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ def __is_label_filter(key: str) -> bool:
151151
def __build_filter(att_filter: List[Dict[str, Any]]) -> Optional[models.Filter]:
152152
if not att_filter:
153153
return None
154-
must = [__build_filter_item(item) for item in att_filter]
154+
must = []
155+
for item in att_filter:
156+
cond = __build_filter_item(item)
157+
must.append(cond)
155158
return models.Filter(must=must)
156159

157160

@@ -178,26 +181,32 @@ def __add_access_management_filter(
178181
)
179182

180183

181-
def __build_filter_item(filter_item: Dict[str, Any]) -> models.FieldCondition:
184+
def __build_filter_item(
185+
filter_item: Dict[str, Any],
186+
) -> models.FieldCondition | models.Filter:
182187
key = filter_item["key"]
183188
value = filter_item["value"]
184-
typ = filter_item.get("type")
189+
type = filter_item.get("type", "any")
185190

186-
# BETWEEN
187-
if isinstance(value, list) and typ == "between":
191+
if isinstance(value, list) and type == "between":
188192
return models.FieldCondition(
189193
key=key,
190194
range=models.Range(gte=value[0], lte=value[1]),
191195
)
192196

193-
# IN (...)
194-
if isinstance(value, list):
197+
if isinstance(value, list) and type == "all":
198+
conditions = [
199+
models.FieldCondition(key=key, match=models.MatchValue(value=v))
200+
for v in value
201+
]
202+
return models.Filter(must=conditions)
203+
204+
if isinstance(value, list) and type == "any":
195205
return models.FieldCondition(
196206
key=key,
197207
match=models.MatchAny(any=value),
198208
)
199209

200-
# = single value
201210
return models.FieldCondition(
202211
key=key,
203212
match=models.MatchValue(value=value),

0 commit comments

Comments
 (0)