# Filtering Query

### Simple Query&#x20;

Querying the data works as follows

```python
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())
```

### Retrieving top K elements without Reasoning

When `activeloop-l0-retrieval` is used there is no reasoning or summary returned. Only `top_k` results.

```python
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 elements
```

### Getting answer from Hegel

Now, we can filter files based on metadata, before running the query.&#x20;

```python
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())
```

### Getting answer from other authors

```python
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())
```

You can learn more about on various ways you can filter the data via [Query Syntax](https://docs.activeloop.ai/user-guide/filtering-query/query-syntax).


---

# 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.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.
