This section provides a detailed guide to the filter expression syntax, a lightweight query language for filtering data.
Querying the data works as follows
import os, requests
url = "https://api.activeloop.ai/chat/completions"
token = os.environ["ACTIVELOOP_TOKEN"]
headers = {'Authorization': f'Bearer {token}'}
payload = {
"model": "activeloop-l0",
"messages": [
{
"role": "user",
"content": "What is logic?",
}
]
}
response = requests.post(url, headers=headers, json=payload)
# Print the response
print(response.json())When activeloop-l0-retrieval is used there is no reasoning or summary returned. Only top_k results.
Now, we can filter files based on metadata, before running the query.
You can learn more about on various ways you can filter the data via .
payload = {
"model": "activeloop-l0-retrieval",
"messages": [
{
"role": "user",
"content": [
{
"type": "filter",
"top_k": 3
},
{
"type": "text",
"text": "What is logic?" # query
}
]
}
]
}
response = requests.post(url, headers=headers, json=payload)
print(response.json()["choices"]) # top k elementspayload = {
"model": "activeloop-l0",
"messages": [
{
"role": "user",
"content": [
{
"type": "filter",
"filter": "metadata.author == 'hegel'"
},
{
"type": "text",
"text": "What is logic?"
}
]
}
],
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())payload = {
"model": "activeloop-l0",
"messages": [
{
"role": "user",
"content": [
{
"type": "filter",
"filter": "metadata.author != 'hegel'"
},
{
"type": "text",
"text": "What is logic?"
}
]
}
],
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())=, ==
Equals
name = "John"
!=, <>
Not equals
status != "inactive"
>
Greater than
age > 30
>=
Greater than or equal to
price >= 100
The syntax supports the following data types:
Strings: Enclosed in double quotes ("value") or single quotes ('value')
Numbers: Integers or decimals (42, 3.14)
Booleans: true or false
Lists: Enclosed in square brackets, with comma-separated values ([1, 2, 3], ["active", "pending"])
Conditions can be combined using logical operators:
AND: condition1 and condition2
OR: condition1 or condition2
Parentheses can be used to group conditions and control precedence:
For nested data structures, use dot notation to access properties:
The following keywords are reserved and should not be used as field names:
and
or
in
like
is
null
not
true
false
Use parentheses to make complex expressions clearer
Be consistent with string quotes (prefer double quotes)
Use whitespace to improve readability
For complex filters, break expressions into multiple lines
column operator value(age > 30 and status = "active") or role = "admin"user.profile.name = "John"
metadata.tags[0] = "important"// Simple equality check
name = "John"
// Numeric comparison
age > 30
// Boolean value
is_active = true// Using AND
age > 30 and status = "active"
// Using OR
status = "pending" or status = "in_review"
// Combining with parentheses
(age > 30 and status = "active") or role = "admin"// Check if value is in a list
status in ["active", "pending", "in_review"]
// Empty list
tags in []// Names that contain "Smith"
name like "%Smith%"
// Email addresses from a specific domain
email like "%@example.com"
// Starts with a specific prefix
product_code like "ABC%"// Check if a field is null
address is null
// Check if a field is not null
email is not null// Access nested object properties
user.profile.address = "New York"
// Access array elements
metadata.tags[0] = "important"
// Deep nesting
order.items[0].product.name = "Widget"// Complex filter combining multiple conditions
(status in ["active", "pending"] and created_date > "2023-01-01") or
(is_priority = true and (assigned_to = "John" or assigned_to is null))<
Less than
quantity < 5
<=
Less than or equal to
temperature <= 32
in
Value is in a list
status in ["active", "pending"]
like
Pattern matching
name like "%Smith%"
is null
Value is null
address is null
is not null
Value is not null
email is not null