Orchard Core AI Web Crawlers
Scrape public websites into the AI knowledge base
You are an Orchard Core expert. Generate configuration and code for CrestApps web crawlers: a Web AI data source is a knowledge base target, and one or more web crawlers point at it. Each crawler scrapes one site with a crawl strategy, cleans each page to text, and indexes it with its URL kept for citations.
Guidelines
- Enable
CrestApps.OrchardCore.AI.WebCrawlers; it depends onCrestApps.OrchardCore.AI.DataSources, which comes along. - The Web data source needs a knowledge base index with an embedding deployment that declares
textEmbedding(seeorchardcore-ai-data-sources). It has no connection settings and no field mapping: each page is one document keyed by its URL. - Sitemap is the built-in strategy. A crawler needs a base URL or an explicit sitemap URL.
- Crawl politely: keep Max concurrent requests low, set a meaningful User-Agent, and use include and exclude patterns to stay inside the content you need.
- Only crawl sites you are allowed to scrape; treat scraped text as untrusted input to the model.
- Install the package in the web/startup project.
Setup
- Create a knowledge base index under Search > Indexing with an embedding deployment.
- Under Artificial Intelligence > Data Sources, choose Add Data Source, pick Web, and select the destination index.
- Under Artificial Intelligence > Web Crawlers, choose Add Web Crawler, pick Sitemap, and fill the fields below.
- Use Synchronize now in the row's Actions menu, or wait for the hourly task.
- Attach the Web data source to an AI profile or chat interaction on its Knowledge tab.
A recipe can create the Web data source ("Source": "Web" in the AIDataSource step, see orchardcore-ai-data-sources), then its crawlers with the WebCrawlers step. A crawler is matched by ItemId, then by DisplayText within the same strategy, so running the recipe twice adds nothing. Source must be a registered strategy and AIDataSourceId must name a Web data source, so import data sources first.
{
"steps": [
{
"name": "WebCrawlers",
"Crawlers": [
{
"ItemId": "4wc00000000000000000000001",
"Source": "Sitemap",
"DisplayText": "Help center",
"AIDataSourceId": "4ds00000000000000000000002",
"Enabled": true,
"ReindexIntervalMinutes": 1440,
"Properties": { }
}
]
}
]
}
The Web crawlers deployment step (Artificial Intelligence category) exports every crawler with its strategy settings in Properties. Secrets are never exported, and a recipe that leaves one out keeps the stored one. With AI Chat WebAPI, crawlers are also managed through /api/ai/v1/web-crawlers (see orchardcore-ai-conversations).
Shared crawler fields
| Field | Stored as | Notes |
|---|---|---|
| Name | WebCrawler.DisplayText | Required |
| Target Web data source | WebCrawler.AIDataSourceId | Required; several crawlers may target one data source |
| Enabled | WebCrawler.Enabled | Disabled crawlers are skipped by the hourly task and by a full data source sync |
| Re-index interval (minutes) | WebCrawler.ReindexIntervalMinutes | Empty uses the default (24 hours); honored to the nearest hour |
Sitemap strategy
Stored in SitemapWebCrawlerMetadata on the crawler (WebCrawler.Source is Sitemap):
| Field | Property | Default |
|---|---|---|
| Base URL | BaseUrl | Discovers the sitemap from robots.txt and conventional locations such as /sitemap.xml |
| Sitemap URL | SitemapUrl | Starts discovery here; supports nested sitemap indexes, gzip, plain text, and RSS or Atom feeds |
| Max pages | MaxPages | 500 |
| Max concurrent requests | MaxConcurrentRequests | 4 |
| Request timeout (seconds) | RequestTimeoutSeconds | 30 |
| Include URL patterns | IncludeUrlPatterns | Empty allows every page; otherwise a URL must match at least one |
| Exclude URL patterns | ExcludeUrlPatterns | A URL matching any pattern is skipped; applied after include |
| User-Agent | UserAgent | CrestApps-WebCrawler/1.0 (+https://crestapps.com) |
Patterns are .NET regular expressions, one per line, matched against the full URL. Examples: ^https://example\.com/docs/ keeps only /docs/; /tag/|/author/ drops taxonomy and author pages; \.pdf$ drops PDF links. Invalid expressions and non-absolute URLs are rejected in the editor.
Synchronization
- Synchronize now re-crawls one site, diffs the discovered pages against the recorded crawl state, and queues only new, changed, and removed pages.
- Web Crawler Re-index (
WebCrawlerReindexBackgroundTask,0 * * * *) evaluates enabled crawlers hourly and re-indexes the ones that are due. - Creating, updating, or deleting a crawler queues a full sync of its target Web data source.
- Per-page state (last modified, change frequency, content hash) makes re-crawls incremental, and a transient block that returns no pages leaves the knowledge base untouched instead of wiping it.
Crawlers and crawl state live in the AI YesSql collection through IWebCrawlerStore and IWebCrawlStateStore; migrations create WebCrawlerIndex and WebCrawlStateIndex.
Citations
Pages are indexed with the URL as the reference id, and WebCrawlerReferenceLinkResolver is registered for the Web reference type, so [doc:N] citations link back to the original page.
Defaults
WebCrawlerOptions holds the fallbacks used when a crawler leaves a field empty: DefaultMaxPages (500), DefaultMaxConcurrentRequests (4), DefaultRequestTimeoutSeconds (30), DefaultUserAgent, and DefaultReindexIntervalMinutes (1440). The Orchard module binds no configuration section to it; change it in code:
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.Configure<WebCrawlerOptions>(options =>
{
options.DefaultMaxConcurrentRequests = 2;
options.DefaultUserAgent = "ContosoBot/1.0 (+https://contoso.com/bot)";
});
}
}
Admin list and permissions
Artificial Intelligence > Web Crawlers is an AdminList named AIWebCrawlers with the grid columns Name, Strategy, Modified, and Actions; rows are the WebCrawler shape in SummaryAdmin and SummaryAdminGrid (see orchardcore-admin-lists). The whole area, including Synchronize now, requires ManageWebCrawlers (Manage web crawlers, Administrator by default).
Add a crawl strategy
A strategy is a keyed IWebCrawlerStrategy plus an entry in WebCrawlerStrategyOptions and a display driver for its settings:
public sealed class Startup : StartupBase
{
internal readonly IStringLocalizer S;
public Startup(IStringLocalizer<Startup> stringLocalizer)
{
S = stringLocalizer;
}
public override void ConfigureServices(IServiceCollection services)
{
services.AddKeyedSingleton<IWebCrawlerStrategy, LinkFollowingWebCrawlerStrategy>("LinkFollowing");
services.Configure<WebCrawlerStrategyOptions>(options => options.AddOrUpdate(
"LinkFollowing",
S["Link following"],
S["Discover pages by following links from a start page to a fixed depth."]));
services.AddDisplayDriver<WebCrawler, LinkFollowingWebCrawlerDisplayDriver>();
}
}
| IWebCrawlerStrategy member | Contract |
|---|---|
| Name | The strategy key, stored as WebCrawler.Source |
| ValidateAsync(crawler, result, cancellationToken) | Validate the strategy settings |
| DiscoverAsync(crawler, cancellationToken) | Return the CrawledPageRef list of pages to consider |
| DiscoverDetailedAsync(crawler, cancellationToken) | Optional; report whether discovery was complete (the default treats an empty list as incomplete) |
| FetchAsync(crawler, url, cancellationToken) | Fetch and clean one page, or return null |
The display driver returns null unless crawler.Source is the strategy key and stores its settings with crawler.Put(...). The built-in sitemap strategy is also exposed as an ingestion connector, the same contract file sources use (see orchardcore-ai-file-sources).
Troubleshooting
| Symptom | Check |
|---|---|
| No Web source type in Add Data Source | Enable CrestApps.OrchardCore.AI.WebCrawlers. |
| Provide a base URL or an explicit sitemap URL | Set one of them, as an absolute URL. |
| Few or no pages | The sitemap is not discoverable, include patterns are too narrow, or Max pages is low. |
| Site blocks the crawler | Lower concurrency, set a recognizable User-Agent, and confirm crawling is allowed. |
| Pages never refresh | The crawler is disabled, or its interval has not elapsed; use Synchronize now. |
| Citations have no links | The data source is not of type Web, or the page URL is not the reference id. |