Skip to content

Add text list attribute for sharepoint integration tags #101

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

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
25 changes: 17 additions & 8 deletions neural_search/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think filter_item.get("type","any") is easier to understand than checking for none later in the code


# 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),
Expand Down