# Query Syntax

## Basic Syntax

A filter expression consists of one or more conditions that can be combined using logical operators. Each condition typically follows this pattern:

```sql
column operator value
```

## Supported Operators

| Operator      | Description              | Example                           |
| ------------- | ------------------------ | --------------------------------- |
| `=`, `==`     | Equals                   | `name = "John"`                   |
| `!=`, `<>`    | Not equals               | `status != "inactive"`            |
| `>`           | Greater than             | `age > 30`                        |
| `>=`          | Greater than or equal to | `price >= 100`                    |
| `<`           | 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`               |

## Data Types

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"]`)

## Logical Operators

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:

```javascript
(age > 30 and status = "active") or role = "admin"
```

## Accessing Nested Properties

For nested data structures, use dot notation to access properties:

```javascript
user.profile.name = "John"
metadata.tags[0] = "important"
```

## Examples

### Basic Comparisons

```javascript
// Simple equality check
name = "John"

// Numeric comparison
age > 30

// Boolean value
is_active = true
```

### Combining Conditions

```javascript
// 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"
```

### Working with Lists

```javascript
// Check if value is in a list
status in ["active", "pending", "in_review"]

// Empty list
tags in []
```

### Pattern Matching

```javascript
// 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%"
```

### Null Checks

```javascript
// Check if a field is null
address is null

// Check if a field is not null
email is not null
```

### Nested Properties

```javascript
// 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 Filters

```javascript
// 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))
```

## Reserved Keywords

The following keywords are reserved and should not be used as field names:

* `and`
* `or`
* `in`
* `like`
* `is`
* `null`
* `not`
* `true`
* `false`

## Best Practices

1. Use parentheses to make complex expressions clearer
2. Be consistent with string quotes (prefer double quotes)
3. Use whitespace to improve readability
4. For complex filters, break expressions into multiple lines


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.activeloop.ai/user-guide/filtering-query/query-syntax.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
