Smart Rules and Dynamic Parameters
UniqueQL to Qdrant Filter Documentation
Introduction
UniqueQL is a specialized query language used for building complex filters to query data within Unique. This documentation provides a guide on using UniqueQL, with an emphasis on enhancing queries through the use of predefined variables and dynamic values. Various examples are included to demonstrate these techniques in practice.
These filters can be applied in smartrules within a Space and also in queries for modules created using the SDK.
For more details, you can refer to the following documentation:
Video
Variables and Setup
SmartRuleVariables
The SmartRuleVariables
object contains predefined variables that can be used within UniqueQL queries. These variables are divided into two categories: userMetadata
and toolParameters
.
userMetadata
: This data is derived from the information in Groups and Users. More details can be found in the Groups and Users documentation.toolParameters
: These are derived from the tool selection made during the module choice process. The parameters are determined by the model based on the chosen module and are then passed as arguments in thetoolParameter
parameter.
const SmartRuleVariables = {
userMetadata: {
location: 'NY',
favCheese: 'Cheddar',
IdoExist: 'funny bunny',
},
toolParameters: {
location: 'Switzerland',
favCheese: 'Gruyere',
numberOfCows: 100,
someBoolean: true,
},
};
Enriching Queries with Variables
The enrichSmartRulesWithVariables
function is used to replace placeholders in UniqueQL queries with actual values from SmartRuleVariables
.
Example: Numbers
Query:
{
path: ['cows'],
operator: Operator.EQUALS,
value: '<toolParameters.numberOfCows>',
}
Result:
{
path: ['cows'],
operator: Operator.EQUALS,
value: 100,
}
Explanation:
The placeholder <toolParameters.numberOfCows>
is replaced with 100
.
Example: Booleans
Query:
Result:
Explanation:
The placeholder <toolParameters.someBoolean>
is replaced with true
.
Example: Time Manipulation
Future Time:
Query:
Result:
Explanation:
The placeholder <T+1000>
is replaced with the current time plus 1000 milliseconds.
Past Time:
Query:
Result:
Explanation:
The placeholder <T-1000>
is replaced with the current time minus 1000 milliseconds.
Example: User Metadata
Query:
Result:
Explanation:
The placeholder <userMetadata.location>
is replaced with NY
.
Example: Tool Parameters
Query:
Result:
Explanation:
The placeholder <toolParameters.location>
is replaced with Switzerland
.
Example: IN Operator
Query:
Result:
Explanation:
The placeholders <toolParameters.location>
and <userMetadata.location>
are replaced with Switzerland
and NY
, respectively.
Example: Nested AND Operator
Query:
Result:
Explanation:
The placeholders <userMetadata.location>
are replaced with NY
in both conditions.
Example: Fallback Mechanisms
Fallback to Existing:
Query:
Result:
Explanation:
The placeholder <userMetadata.IdoNotExist>
does not exist, so it falls back to <userMetadata.IdoExist>
, which is funny bunny
.
Fallback to Static Value:
Query:
Result:
Explanation:
None of the placeholders exist, so it falls back to the static value SomeValue
.
How to add metadata
Content Metadata
Content metadata cab be added/updated using the ingestion API. An example cURL for updating metadata of an existing file looks as follows.
See Ingestion API for further details on Ingestion API.
User/Group Metadata
The metadata of a user or group can be updated by using the cURL call as follows.
Setup your Assistant
Use with SDK and Toolkit
Conclusion
UniqueQL provides a flexible mechanism to construct complex queries by leveraging dynamic variables and placeholders. By using the enrichSmartRulesWithVariables
function, you can easily replace placeholders with actual values from predefined variables, enabling dynamic and context-aware query construction. The examples provided in this documentation should help you understand and utilize these techniques effectively.
Author | @Andreas Hauri |
---|
© 2024 Unique AG. All rights reserved. Privacy Policy – Terms of Service