From 92dc64fb7bec5b95d838a9e6374e8423e5c3fb96 Mon Sep 17 00:00:00 2001 From: LennartSchmidtKern Date: Wed, 23 Jul 2025 09:14:39 +0200 Subject: [PATCH 1/5] model --- submodules/model | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/model b/submodules/model index 1d2cacb..5e23e98 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit 1d2cacb6479e2273f5644f702fec96b734a912b7 +Subproject commit 5e23e9828ba9f57124cc13ddd41f92258b64f412 From 877deaf1fccf3ff7ebaef8ebcc0438e8c8847d0e Mon Sep 17 00:00:00 2001 From: LennartSchmidtKern Date: Wed, 23 Jul 2025 11:37:13 +0200 Subject: [PATCH 2/5] any all list filter --- app.py | 6 ++++-- neural_search/util.py | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 06428ec..8d4b4d9 100644 --- a/app.py +++ b/app.py @@ -80,11 +80,13 @@ def most_similar_by_embedding( include_scores: bool = False, ) -> responses.JSONResponse: """Find the n most similar records with respect to the specified embedding. - Args: + Args: embedding_id (str): Embedding id. record_id (str): The record for which similar records are searched. limit (int): Specifies the maximum amount of returned records. - att_filter(Optional[Dict[str, Any]]]): Specifies the attribute filter for the search as dict objects. + att_filter (Optional[Dict[str, Any]]]): Specifies the attribute filter for the search as dict objects. + Note: Record values can now also be lists (e.g., {"name": ["John", "Alex"]}). + Filters will match if any or all (type "any" or type "all") of the listed values satisfy the condition. threshold: Optional[float]: None = calculated DB threshold, -9999 = no threshold, specified = use value example_filter = [ {"key": "name", "value": ["John", "Doe"]}, -> name IN ("John", "Doe") diff --git a/neural_search/util.py b/neural_search/util.py index 093a763..942aee1 100644 --- a/neural_search/util.py +++ b/neural_search/util.py @@ -151,7 +151,10 @@ def __is_label_filter(key: str) -> bool: def __build_filter(att_filter: List[Dict[str, Any]]) -> Optional[models.Filter]: if not att_filter: return None - must = [__build_filter_item(item) for item in att_filter] + must = [] + for item in att_filter: + cond = __build_filter_item(item) + must.append(cond) return models.Filter(must=must) @@ -178,26 +181,32 @@ def __add_access_management_filter( ) -def __build_filter_item(filter_item: Dict[str, Any]) -> models.FieldCondition: +def __build_filter_item( + filter_item: Dict[str, Any], +) -> models.FieldCondition | models.Filter: key = filter_item["key"] value = filter_item["value"] - typ = filter_item.get("type") + type = filter_item.get("type") - # BETWEEN - if isinstance(value, list) and typ == "between": + if isinstance(value, list) and type == "between": return models.FieldCondition( key=key, range=models.Range(gte=value[0], lte=value[1]), ) - # IN (...) - if isinstance(value, list): + if isinstance(value, list) and type == "all": + conditions = [ + models.FieldCondition(key=key, match=models.MatchValue(value=v)) + for v in value + ] + return models.Filter(must=conditions) + + if isinstance(value, list) and (type == "any" or type is None): return models.FieldCondition( key=key, match=models.MatchAny(any=value), ) - # = single value return models.FieldCondition( key=key, match=models.MatchValue(value=value), From c2991fb53c6b28c3ac1291d1e9c72e946fd0b7b1 Mon Sep 17 00:00:00 2001 From: andhreljaKern Date: Tue, 2 Sep 2025 08:45:34 +0200 Subject: [PATCH 3/5] chore: pr comments --- neural_search/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neural_search/util.py b/neural_search/util.py index 2d434d9..422ddf9 100644 --- a/neural_search/util.py +++ b/neural_search/util.py @@ -186,7 +186,7 @@ def __build_filter_item( ) -> models.FieldCondition | models.Filter: key = filter_item["key"] value = filter_item["value"] - type = filter_item.get("type") + type = filter_item.get("type", "any") if isinstance(value, list) and type == "between": return models.FieldCondition( @@ -201,7 +201,7 @@ def __build_filter_item( ] return models.Filter(must=conditions) - if isinstance(value, list) and (type == "any" or type is None): + if isinstance(value, list) and type == "any": return models.FieldCondition( key=key, match=models.MatchAny(any=value), From 999b7e42483cd0502a40d54d095bace85ec13eb0 Mon Sep 17 00:00:00 2001 From: andhreljaKern Date: Tue, 2 Sep 2025 08:45:48 +0200 Subject: [PATCH 4/5] chore: update submodules --- submodules/model | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/model b/submodules/model index 41f85a2..468d738 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit 41f85a25de0ea90e5ff7c7bdcb6a86ee23ee73e1 +Subproject commit 468d73881f240ab7a26523ab7211fa4e5dc4160a From fa62e6996be0aa1e29d8b670bb797463745e4efb Mon Sep 17 00:00:00 2001 From: andhreljaKern Date: Thu, 4 Sep 2025 15:36:21 +0200 Subject: [PATCH 5/5] chore: update submodules --- submodules/model | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/model b/submodules/model index 468d738..d5300f1 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit 468d73881f240ab7a26523ab7211fa4e5dc4160a +Subproject commit d5300f13c3b2cc6da16f36ffd6349795923b2c64