# Knowledge Base Metadata

Metadata is additional information attached to your Knowledge Base files that you can filter on when searching, similar to filtering columns in a spreadsheet.

{% @arcade/embed url="<https://app.arcade.software/share/y41OGVJZuh8LHtOtcWlz>" flowId="y41OGVJZuh8LHtOtcWlz" %}

## Types of Metadata

### Standard Metadata

Automatically inherited from the source (file name, source URL, upload date, etc.). Standard metadata is read-only. To update it, make changes at the source and re-sync.

### Custom Metadata

Tag Knowledge Base files with your own key-value pairs to organize and filter content by dimensions like **Region**, **Product**, **Audience**, or **Content Type**.

{% hint style="success" %}
Custom metadata lets you filter Knowledge Base files directly in Workflow steps, with no need to import into a Grid just to tag and filter content.
{% endhint %}

## Adding Metadata

### Custom Metadata (UI)

1. Click any file in your Knowledge Base to open its details
2. In the **Custom Metadata** section, click **Add**
3. Enter a **Key** (e.g., "country") and **Value** (e.g., "France")
4. Click **Save Changes**

### CSV / Google Sheets

When uploading a CSV or Google Sheet, all columns are stored as metadata. You can choose which columns are searchable. The rest are still returned as metadata but can only be used for filtering.

### Other Methods

* **API** - Use the [Knowledge Bases API "Update" endpoint](https://docs.airops.com/context/memory-stores-api#supported-api-calls)
* **Workflow** - Use the ["Knowledge Base Write" Step](https://docs.airops.com/actions/workflow-concepts/workflow-steps/memory-steps/memory-write)

## Filtering with Metadata

Use metadata filters in your Workflow Knowledge Base steps to scope your search results.

**Example:** If you have case studies tagged with a `country` key, add a filter in your **Search Knowledge Base** or **Get Knowledge Base File** step where `country` equals `"Spain"` to retrieve only Spanish case studies.

{% hint style="info" %}
**Dynamic Filtering:** Use workflow inputs for flexible filtering. Set your filter to `country` equals `{{input.region}}`, then pass different region values at runtime.
{% endhint %}

For detailed filtering examples, see the [Knowledge Base Search Step documentation](https://docs.airops.com/actions/workflow-concepts/workflow-steps/memory-steps/memory-search#filter-the-memory-store-optional).

### Filter Operators (Code Editor)

For complex filters, use MongoDB query operators:

| Operator           | Description                          |
| ------------------ | ------------------------------------ |
| **$eq**            | Equal to                             |
| **$ne**            | Not equal to                         |
| **$gt** / **$gte** | Greater than / Greater than or equal |
| **$lt** / **$lte** | Less than / Less than or equal       |
| **$in** / **$nin** | In array / Not in array              |

{% hint style="info" %}
For list metadata like `"genres": ["thriller", "mystery"]`, the search matches any value in the list.
{% endhint %}

### Filtering via API

You can also filter using the [Knowledge Bases API "Search" endpoint](https://docs.airops.com/context/memory-stores-api#supported-api-calls).

{% @arcade/embed url="<https://app.arcade.software/share/1qOMDldFNqFWJ15cm6Wb>" flowId="1qOMDldFNqFWJ15cm6Wb" %}

## Best Practices

* **Use consistent keys** - Standardize key names (always "country", not sometimes "region") and value formats (always "United States", not "US" or "USA")
* **Plan your strategy** - Decide what dimensions you need to filter by before tagging content
* **Custom metadata vs. Grids** - Use custom metadata for file-level tagging; use Grids for row-level tagging of structured data
