Cloudflare lets AI Search index D1 rows without a separate vector store
Most teams that want retrieval-augmented generation start with the same plumbing problem. The data already exists in a database, but the search index expects documents. So someone writes an export job, transforms rows into JSON, pushes them to a vector store, and then writes a second job to keep the index in sync. The pipeline is not intellectually hard, but it is operational surface area: credentials, retries, schema drift, deletion handling, and a second copy of the data that can drift from the source.
Cloudflare’s AI Search now has a shortcut for one version of that problem. On November 12, 2026, the company added D1 databases as a data source for AI Search, in beta. You provide a read-only SQL query. AI Search runs it, indexes each returned row as a separate document, and schedules syncs to keep the index current as rows are added, changed, or removed. The feature is available from the dashboard, the REST API, and the Workers binding.
The pitch is simple: if your application data is already in D1, you can make it searchable without standing up a separate ingestion pipeline. The reality is more nuanced. The query is the corpus, the limits shape the schema, and the sync behavior has costs that are easy to underestimate. This is a useful feature, but it rewards teams that read the documentation before they point it at a production table.
From table rows to search documents
The mechanics are straightforward. You create an AI Search instance with type: "d1", a source that is the D1 database ID, a token_id for a service API token, and a source_params.d1.query that selects the rows you want. The example in the changelog is a query that selects an article ID as id, the title, the content, and a category as meta_category, filtered to published articles.
AI Search reads the result in pages, sorted by id. It treats each row as a document. The title column becomes the document title, the content column becomes the main text, and columns prefixed with meta_ become metadata. Other columns may appear as labeled fields depending on the document template. The id must be non-empty and unique. If a row’s ID changes, AI Search deletes the old document and creates a new one.
That mapping is the whole integration. There is no schema migration, no export file, and no separate vector database to provision. The D1 database stays the source of truth. AI Search maintains an index derived from it. For a small application with a product catalog, a knowledge base, or a support-ticket archive, that is a meaningful reduction in moving parts.
The query is also the boundary. AI Search does not read the whole database; it reads what the query returns. That means you can filter out drafts, soft-deleted rows, internal notes, and tenant data that should not be searchable. You can shape the document with aliases and computed columns. You can join tables if the query supports it. The index is a projection of the database, not a copy of it.
The query is the corpus
The most important design decision is the query. It defines what the model can retrieve, what the search results can expose, and how much the sync costs. A query that selects every row in a large table is easy to write and expensive to maintain. A query that selects only the columns the search experience needs is smaller, cheaper, and safer.
The documentation imposes constraints that push toward simple queries. The query must be a single read operation beginning with SELECT or WITH. It must return a non-empty result with unique, non-empty id values. It cannot use bind parameters, comments, ORDER BY, LIMIT, semicolons, write operations, or administrative commands. AI Search reads the result in pages, sorting by id. Each result column must have a unique name, so aliases are sometimes necessary.
Those constraints are not arbitrary. The service needs to paginate deterministically, and it needs to read the full result to detect deletions. ORDER BY and LIMIT would make the result order application-defined and could hide rows from the sync. Bind parameters would make the query dependent on runtime values that the sync does not have. Comments and semicolons complicate parsing. The restrictions are a contract: the query must be a stable, self-contained projection.
The practical consequence is that the id should be stable and indexed. A stable primary key lets D1 read pages efficiently. A computed ID, such as a hash of the content, can change when the content changes, which causes AI Search to delete and recreate the document. That churn is visible in the index and in the billing. A stable ID also makes deletion detection reliable: if the query stops returning a row, AI Search knows the document should be removed.
The WHERE clause is where the security and quality boundaries live. WHERE published = 1 is a publication filter. WHERE tenant_id = ? would be a tenant filter, but bind parameters are not allowed, so a multi-tenant deployment needs a different approach: separate instances per tenant, a query that hard-codes a tenant, or a view that exposes only the tenant’s rows. That is a design constraint worth thinking about before the first sync.
The limits that shape the design
The feature has a set of hard limits. The query can return at most 100,000 rows. The query text can be at most 10,000 characters. Each rendered document can be at most 64 KiB. There can be at most five meta_ columns, and the metadata per row, including the ID, can be at most 8,000 bytes as JSON. The regular AI Search limit on files per instance also applies, and the lower of the two caps wins: 100,000 on Workers Free, 1 million on Workers Paid, or 500,000 on Paid with hybrid search.
Those numbers are generous for a small catalog and tight for a large one. A 100,000-row cap sounds like a lot until you remember that each row is a document, and a product catalog with variants, translations, and reviews can exceed it quickly. The cap also interacts with the sync: the documentation says the sync indexes rows in id order up to the cap and does not delete items when the cap is reached. If the table grows past the cap, the tail of the result is simply not indexed. That is a silent completeness problem, not an error.
The 64 KiB document limit is another design constraint. A long article, a PDF converted to text, or a JSON blob can exceed it. The document may be truncated, or the row may fail. The right pattern is to split large content into multiple rows with separate IDs, or to store the full content elsewhere and index a summary. The metadata limit pushes filters into meta_ columns, which is the right place for them, but it also means you cannot stuff a large JSON object into metadata and expect it to work.
The 50 MB D1 query result limit is separate from AI Search, but it shapes the same design. Since November 4, 2026, D1 queries that return more than 50 MB fail with an explicit error. Cloudflare says the limit covers the 99.999th percentile of requests. A SELECT * on a wide table can cross 50 MB with far fewer rows than the 100,000-row cap. The fix is keyset pagination, not large offsets, and selecting only the columns the index needs. The AI Search integration reads the full result at least twice, so a query near the limit is twice as likely to fail.
The hidden costs: syncs, reads, and churn
The default sync interval is 24 hours. That is fine for a knowledge base that changes weekly and wrong for a marketplace where inventory changes every minute. The sync adds new rows, re-indexes changed rows, and deletes rows the query no longer returns. Deletion happens only after AI Search has read the full result, which is why the query must be stable and why a failed sync leaves the existing index in place.
The cost model is the part that surprises people. Each sync reads the full query result at least twice with the service API token: once to check the ID values, then again in pages. Those reads count toward D1 rows read. A 100,000-row table therefore costs at least 200,000 row reads per sync, plus the re-indexing work. If the sync runs every 24 hours, that is 200,000 reads per day. If it runs hourly, it is 4.8 million reads per day. The D1 paid plan includes 25 billion rows read per month, so the numbers are not catastrophic at small scale, but they are not free either. A large table with a short sync interval can consume a meaningful share of the allowance.
There is also churn. If the query returns rows in a different order, or if the ID changes, the index has to delete and recreate documents. That costs ingestion tokens and storage. A stable ID and a stable query are not just good hygiene; they are cost controls.
The billing start date is December 1, 2026, postponed from November 1. Each account gets 5 million ingestion tokens, 10 GB-month of storage, 1,000 semantic queries, and 1,000 full-text queries per month. Usage beyond that is billed. The free allowance is enough for a prototype, not for a busy production search experience. Teams should model the ingestion and query costs before they migrate a large corpus.
Security, residency, and deletion
The D1 database must be in the same Cloudflare account as AI Search. The API and Workers binding routes require the token_id of a service API token, and the AI Search Index Engine permission on that token includes D1 Read. That is a sensible least-privilege design: the search service can read the database, not write it.
But the index is a new copy of the data. That has implications. If a row is deleted from D1, the next successful sync removes the document. If the sync fails, the document stays. If the query changes to exclude a row, the next sync removes it. If the query is wrong, the index may contain data that should not be searchable. The query is the access control, and it is only as good as the person who wrote it.
Data residency is another question. D1 and AI Search are Cloudflare products, and the data is stored in Cloudflare’s network. The feature does not change the underlying residency story, but it does create a second derived copy. Teams with regulatory requirements should confirm where the index is stored and how deletion propagates. The beta status matters here: availability and behavior can change, and there may not be an SLA.
The deletion behavior is better than many pipeline-based systems. Because AI Search reads the full result and compares IDs, a row that disappears from the query is removed from the index. That is the right default. The failure mode is a query that silently stops returning rows, for example because a WHERE clause references a column that was renamed. The sync succeeds with fewer rows, and the index loses documents. Monitoring the document count and the sync status is not optional.
When this is the right tool
This feature is a good fit when the data is already in D1, the corpus is under the row cap, the documents are under 64 KiB, and a daily sync is acceptable. A product catalog, a help center, a documentation site, a support-ticket archive, or an internal knowledge base are natural candidates. The team gets a searchable index without a separate ingestion service, and the query doubles as the curation layer.
It is a poor fit when the data changes constantly and the search experience needs near-real-time freshness. A marketplace with live inventory, a chat application with new messages, or a fraud system with streaming events will find the 24-hour default too slow and the full-result sync too expensive. Those workloads need a change-data-capture pipeline or a different index architecture.
It is also a poor fit when the corpus is larger than the row cap or the documents are larger than 64 KiB. Partitioning into multiple instances is possible, but it adds complexity: separate queries, separate syncs, and a routing layer in the application. At that point, the shortcut is no longer a shortcut.
The beta status is a reason to pilot, not a reason to avoid. Start with a small table, a simple query, and a test instance. Measure the sync time, the rows read, the document count, and the query quality. Then decide whether to expand. The feature is most valuable when it removes a pipeline that the team did not want to build. It is least valuable when it hides a pipeline that the team actually needs.
Sources
- Primary: Cloudflare changelog, “AI Search supports D1 databases as a data source (beta)”
- D1 data source docs: AI Search D1 configuration
- D1 limits: Cloudflare D1 limits
- D1 50 MB result cap: Cloudflare changelog, October 30, 2026
- Independent summary: Sulat AI & Tech News