Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

RAG Metadata Filtering, Retrieval Boosting and Index Path Control

Filter and rank managed RAG search with metadata schemas, path rules, boosting, reranking, and migration from legacy AutoRAG APIs.

This page summarizes Cloudflare documentation on AI Search (formerly AutoRAG): a fully managed retrieval-augmented generation (RAG) pipeline that handles embeddings, indexing, retrieval, and answer generation after you connect a data source such as R2 or a website. Most teams arrive here when search returns wrong documents, tenants see each other’s data, drafts appear in answers, or they need to move off legacy env.AI.autorag() and /autorag/rags/ endpoints.

AutoRAG is now AI Search! The new name marks a new and bigger mission: to make world-class search infrastructure available to every developer and business.

— Cloudflare, AI Search (formerly AutoRAG) now with More Models To Choose From

AI Search pipeline: what metadata and retrieval control

Section titled “AI Search pipeline: what metadata and retrieval control”

AI Search stores document chunks in a vector index and runs retrieval before generation. Metadata attributes organize indexed content; filtering narrows which chunks are eligible at query time; relevance boosting and reranking adjust order within retrieved candidates. Path filtering controls what enters the index at ingest time—a different layer than query-time filters.

Metadata filtering narrows down search results based on metadata, so only relevant content is retrieved. The filter is applied before retrieval, so you only query the documents that matter.

— Cloudflare, Filtering

Metadata attributes: built-in fields and custom schema

Section titled “Metadata attributes: built-in fields and custom schema”

Built-in attributes are extracted automatically during indexing. Custom fields require a schema on the instance before extraction works.

Attribute Meaning Example
filename File name guide.pdf or docs/getting-started/guide.pdf
folder Prefix or folder path docs/getting-started/
timestamp Last modified time (ms; comparisons round down to seconds) 1735689600000

Custom metadata allows you to define additional fields for filtering search results. You can attach structured metadata to documents and filter queries by attributes such as category, version, or any custom field.

— Cloudflare, Metadata attributes

How to define a custom metadata schema (up to five fields)

Section titled “How to define a custom metadata schema (up to five fields)”

You can define up to five custom metadata fields per instance. Each field has a name and data type (text, number, or boolean). Field names are case-insensitive, cannot be timestamp, folder, or filename, and changing the schema triggers a full re-index.

Constraint Limit
Custom fields 5 per instance
Metadata per vector 10 KiB total (system data + JSON)
Filterable string prefix First 64 UTF-8 bytes of each indexed string

Attach metadata by data source:

Extensionless R2 keys are supported when objects carry a supported Content-Type in metadata (changelog).

context metadata: guide answers without editing files

Section titled “context metadata: guide answers without editing files”

A custom field named context is attached to each chunk and passed to the LLM on /ai-search / chat completions-style requests, which helps when the raw file text is ambiguous.

When you include a custom metadata field named context, AutoRAG attaches that value to each chunk of the file. When you run an /ai-search query, this context is passed to the LLM and can be used as additional input when generating an answer.

— Cloudflare, View custom metadata in responses and guide AI-search with context in AutoRAG

Metadata filtering: query syntax, folders, and multitenancy

Section titled “Metadata filtering: query syntax, folders, and multitenancy”

Filters are JSON objects under ai_search_options.retrieval.filters. Keys are attribute names; values are equality or operator objects ($eq, $gte, $in, and others per Filtering).

Implicit equality:

ai_search_options: {
retrieval: {
filters: { folder: "docs/getting-started/" }
}
}

Custom metadata example from the REST API:

curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/instances/{NAME}/search \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {API_TOKEN}" \
-d '{
"messages": [{ "content": "How do I configure authentication?", "role": "user" }],
"ai_search_options": {
"retrieval": {
"filters": {
"category": "documentation",
"version": { "$gte": 2.0 }
}
}
}
}'

(Source pattern: Custom metadata filtering for AI Search.)

Folder prefix: why plain equality is not enough

Section titled “Folder prefix: why plain equality is not enough”

Exact folder equality matches only objects directly in that folder, not subfolders. For a tree under docs/, use a string range:

filters: { folder: { $gte: "docs/", $lt: "docs0" } }

Using { "folder": "docs/" } only matches files directly in that folder (like guide.pdf), not files in subfolders.

— Cloudflare, Filtering

Per-tenant layouts (for example customer-a/contracts/) pair with a folder filter at query time so each tenant retrieves only their prefix (metadata filtering and multitenancy). When your app already knows allowed files (for example from a permissions database), filter by built-in filename without reindexing (filter by file name).

Metadata filtering for folder and timestamp on indexed content applies to data indexed on or after April 21, 2025; existing instances may need a settings change and Sync index to reindex (changelog).

Path filtering: control what gets indexed (website and R2)

Section titled “Path filtering: control what gets indexed (website and R2)”

Path filtering uses micromatch include and exclude rules at ingest. Skipped items appear in job logs (Exclude match, No include match) under the instance Jobs tab (Path filtering).

Use case Include Exclude
Docs without drafts **/docs/** **/docs/drafts/**
Exclude admin — **/admin/**
English only **/en/** —

By controlling what gets indexed, you can improve the relevance and quality of your search results. You can also use path filtering to split a single data source across multiple AI Search instances for specialized search experiences.

— Cloudflare, AI Search path filtering for website and R2 data sources

Configure filters when creating an instance or under Settings anytime.

Relevance boosting: nudge ranking by metadata

Section titled “Relevance boosting: nudge ranking by metadata”

Boosting re-scores up to 50 candidates after initial vector and/or keyword retrieval and before reranking. It cannot surface chunks that initial search never retrieved.

Boosting can change the order of results within the candidate set, but cannot promote a chunk that the initial search step did not retrieve.

— Cloudflare, Relevance boosting

Up to three boost_by fields per instance or per request (per-request values replace instance defaults). Example:

ai_search_options: {
retrieval: {
boost_by: [
{ field: "timestamp", direction: "desc" },
{ field: "priority", direction: "desc" },
],
},
}

text and boolean fields support only exists and not_exists directions; asc / desc on those types returns an error (Relevance boosting).

Reranking is off by default. When enabled, a cross-encoder reorders retrieved chunks before generation—useful for large or noisy corpora where vector similarity alone mis-orders results (Reranking, hybrid search notes).

Reranking helps improve accuracy, especially for large or noisy datasets where vector similarity alone may not produce the optimal ordering.

— Cloudflare, Rerank for more relevant results

Reranking adds latency and an extra model step. Workers AI reranking bundled with AI Search does not show as separate AI Gateway usage (Reranking). Optional query rewriting (messages format only) adds another LLM call (Query rewriting).

Legacy REST paths under /autorag/rags/ remain supported, but new features land only on /ai-search/namespaces/{namespace}/instances/ endpoints with an OpenAI-style messages array (REST API migration, New AI Search REST API).

Area Legacy Current
Workers access env.AI.autorag("name") env.AI_SEARCH.get("name") or named binding (Workers binding migration)
Search payload query string messages: [{ role, content }]
Filters { type, key, value } ai_search_options.retrieval.filters with $eq, $gte, …
Response chunks data[] chunks[] (field mapping in migration guide)

If you are using the previous AutoRAG API endpoints (/autorag/rags/), we recommend migrating to the new endpoints. The previous AutoRAG API endpoints will continue to be fully supported.

— Cloudflare, Migration from existing AutoRAG API (recommended)

API tokens need AI Search permission instead of legacy AutoRAG permission (REST API migration). Generation models can be overridden per request (Models); third-party embedding and inference models route through AI Gateway with provider keys.

Indexing sync: jobs update the Vectorize index when R2 content changes; use the Jobs tab or Sync index for observability (Faster indexing and new Jobs view). The Metrics tab tracks ingestion, ai-search vs search usage, and top retrievals (New Metrics View).

  • Filtering on a custom field that was never in the instance schema or was added after documents were indexed without re-sync.
  • Expecting folder: "docs/" to include nested paths—use the docs/ … docs0 range pattern instead.
  • Using boost_by with desc on a text field (invalid direction).
  • Assuming boosting or reranking can fix results from content that path filters excluded from the index.
  • Comparing only the first 64 UTF-8 bytes of long string metadata in filters while storing longer values (Filtering).
  • Mixing legacy compound type: "and" filters with new REST payloads during a partial migration.
  1. In the Cloudflare dashboard, open your AI Search instance and confirm Settings → path include/exclude rules match what you intend to index (path filtering changelog).
  2. Run Sync index or wait for a sync job, then open the Jobs tab and confirm skipped paths show expected exclude/include reasons (Path filtering).
  3. Issue a test search (Workers binding or REST search) with ai_search_options.retrieval.filters for a known folder or custom field value and verify only expected chunks return (Filtering).
  4. Compare result order with and without boost_by and reranking on the same query; inspect scoring_details in chat completions if you surface citations (Show source citations).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact passage you are asking about, and we will correct or clarify it.