View module source on GitHub

IncomingQuery

class IncomingQuery()

Represents an incoming query with its components.

Attributes:

NameTypeDescription
querystrThe query string.
operatorstrThe operator used in the query.
exactMatchboolIndicates whether the query requires an exact match.

__init__

def __init__(query: str, operator: str, exactMatch: bool)

Initialize an IncomingQuery object.

Arguments:

NameTypeDescription
querystrThe query string.
operatorstrThe operator used in the query.
exactMatchboolIndicates whether the query requires an exact match.

QueryObject

class QueryObject()

Represents a query object with its components.

Attributes:

NameTypeDescription
idstrThe ID of the query object.
queryRuleGroupTypeThe query object.

parse_incoming_query

def parse_incoming_query(incoming_query: str) -> List[RuleType]

Parses an incoming query string into a list of RuleType objects.

Arguments:

NameTypeDescription
incomingQuerystrThe incoming query string.

Returns:

NameDescription
List[[RuleType](/sdk/python/references/models/prompt)]A list of RuleType objects.

evaluate_rule_group

def evaluate_rule_group(rule_group: RuleGroupType,
                        incoming_query_rules: List[RuleType]) -> bool

Evaluates a rule group against incoming query rules.

Arguments:

NameTypeDescription
ruleGroupRuleGroupTypeThe rule group to evaluate.
incomingQueryRulesList[RuleType]The incoming query rules.

Returns:

NameDescription
boolTrue if the rule group matches, False otherwise.

check_operator_match

def check_operator_match(field_rule: RuleType,
                         field_incoming_rule: RuleType) -> bool

Checks if the operator between two rules matches.

Arguments:

NameTypeDescription
fieldRuleRuleTypeThe rule with the operator.
fieldIncomingRuleRuleTypeThe incoming rule.

Returns:

NameDescription
boolTrue if the operator matches, False otherwise.

condition_met

def condition_met(field_rule: RuleType, field_incoming_rule: RuleType) -> bool

Checks if the condition between two rules is met.

Arguments:

NameTypeDescription
fieldRuleRuleTypeThe rule with the condition.
fieldIncomingRuleRuleTypeThe incoming rule.

Returns:

NameDescription
boolTrue if the condition is met, False otherwise.

find_best_match

def find_best_match(objects: List[QueryObject],
                    incoming_query: IncomingQuery) -> Optional[QueryObject]

Finds the best match for the incoming query among the list of objects.

Arguments:

NameTypeDescription
objectsList[QueryObject]The list of objects to search through.
incomingQueryIncomingQueryThe incoming query to match against.

Returns:

NameDescription
Optional[[QueryObject](/sdk/python/references/filter_objects)]The best match for the incoming query, or None if no match is found.

find_all_matches

def find_all_matches(objects: List[QueryObject],
                     incoming_query: IncomingQuery) -> List[QueryObject]

Finds all matches for the incoming query among the list of objects.

Arguments:

NameTypeDescription
objectsList[QueryObject]The list of objects to search through.
incoming_queryIncomingQueryThe incoming query to match against.

Returns:

NameDescription
List[[QueryObject](/sdk/python/references/filter_objects)]A list of all matches for the incoming query.