CrestApps.Core File Sources
A File AI data source (AIDataSourceSourceTypes.File) is an inert bucket with no folder, credential or field mapping. A file source (FileSource record) picks a connector, configures it, and points at the File data source it fills. Several file sources can feed one knowledge base, each on its own schedule. Web crawlers (crestapps-core-web-crawlers) are the same shape for websites.
FileSource (FileSystem) -+
FileSource (Ftp) -+-> File AI data source -> knowledge-base index (typed objects)
FileSource (Sftp) -+
Each file becomes separately retrievable objects (document, article, text, figure, chart, table) with a page number and a link to its article and document. Data source concepts are in crestapps-core-data-sources; readers and figure processing are in crestapps-core-document-processing.
Registration
using CrestApps.Core.AI.Documents;
using CrestApps.Core.AI.Documents.Endpoints;
using CrestApps.Core.AI.FileSources;
using CrestApps.Core.AI.Ftp;
using CrestApps.Core.AI.Sftp;
using CrestApps.Core.Data.YesSql;
builder.Services.AddCrestAppsCore(crestApps => crestApps
.AddAISuite(ai => ai
.AddOpenAI()
.AddDocumentProcessing(documentProcessing => documentProcessing // optional: chat uploads, Office readers
.AddYesSqlStores()
.AddPdf()
.AddReferenceDownloads()))
.AddIndexingServices(indexing => indexing
.AddYesSqlStores()
.AddPostgreSQL(
builder.Configuration.GetSection("CrestApps:PostgreSQL"),
postgreSQL => postgreSQL.AddAIDataSources())));
// After AddDocumentProcessing, so the HTML reader registered here wins .html.
builder.Services
.AddCoreFileSources(builder.Configuration)
.AddCoreFileSystemConnector()
.AddCoreFtpIngestionConnector() // CrestApps.Core.AI.Ftp (FluentFTP)
.AddCoreSftpIngestionConnector(); // CrestApps.Core.AI.Sftp (SSH.NET)
builder.Services.AddCoreFileSourceStoresYesSql(); // or AddCoreFileSourceStoresEntityCore()
var app = builder.Build();
app.AddDownloadKnowledgeFigureEndpoint();
AddCoreFileSources()registers the ingestion path (AddCoreAIDocumentIngestionwith the plain-text reader, figure processing and backfill), the shared run service (AddCoreAIIngestionRuntime()),IFileSourceScheduler,FileSourceBackgroundService, the catalog handlers, the HTML reader for.html,.htmandtext/html, and the Files entry inAIDataSourceSourceOptions.AddCoreFileSources(IConfiguration)also bindsFileSourceOptionsandFileSystemConnectorOptions.- Only registered connectors are offered. A host that never references the FTP or SFTP package offers a folder and nothing else.
- Store calls register
IFileSourceStore,IIngestionItemStateStoreandIKnowledgeObjectStore. YesSql hosts create the tables withCreateFileSourceIndexSchemaAsync,CreateIngestionItemStateIndexSchemaAsyncandCreateKnowledgeObjectIndexSchemaAsync(namespaceCrestApps.Core.Data.YesSql.Indexes.*). AddCoreAIDocumentReferenceDownloads()(orAddReferenceDownloads()) adds theFilecitation link resolver.AddDownloadKnowledgeFigureEndpoint()servesai/knowledge/{dataSourceId}/figures/{canonicalId}, authorized withAIKnowledgeOperations.ViewFiguresagainst theAIDataSource; register anAuthorizationHandler<OperationAuthorizationRequirement, AIDataSource>. Both live inCrestApps.Core.AI.Documents.- PDFs need a PDF reader:
AddPdf()on the document-processing builder, orservices.AddCoreAIPdfIngestion()fromCrestApps.Core.AI.Ingestion.Pdf. Office files needAddOpenXml().
Configuration
{
"CrestApps": {
"AI": {
"FileSources": {
"MaxItemsPerRun": 200,
"MaxConcurrentFetches": 2,
"RunCheckIntervalMinutes": 15,
"DefaultRunIntervalMinutes": 1440,
"FileSystem": {
"AllowedRoots": [ "App_Data/file-sources" ]
}
}
}
}
}
FileSystemConnectorOptions.AllowedRootsis empty by default, which means no folder may be read. Registering the connector grants nothing.- Roots are absolute or relative to
FileSystemConnectorOptions.BasePath, which the configuration callback sets to the content root. ..is refused outright in a root and in an item id, containment is compared by path segment, and an item id is re-checked at fetch time.- A file source with no
RootPathreads the single allowed root; with several roots it must name one. - Name a developer's own folder in user secrets, for example
dotnet user-secrets set "CrestApps:AI:FileSources:FileSystem:AllowedRoots:0" "D:\docs", or the environment variableCrestApps__AI__FileSources__FileSystem__AllowedRoots__0.
Creating Records in Code
using CrestApps.Core;
using CrestApps.Core.AI.FileSources.Connectors;
using CrestApps.Core.AI.Ingestion;
using CrestApps.Core.AI.Models;
var dataSource = new AIDataSource
{
DisplayText = "Datasheets",
Source = AIDataSourceSourceTypes.File,
AIKnowledgeBaseIndexProfileName = "datasheets-kb",
};
await dataSourceCatalog.CreateAsync(dataSource, cancellationToken);
var fileSource = new FileSource
{
DisplayText = "Datasheet folder",
Source = FileSystemIngestionConnector.ConnectorName, // "FileSystem", "Ftp" or "Sftp"
AIDataSourceId = dataSource.ItemId,
ReindexIntervalMinutes = 60,
};
fileSource.Put(new FileSystemFileSourceMetadata
{
RootPath = "App_Data/file-sources/datasheets",
Recursive = true,
});
fileSource.Put(new FileSourceMetadata
{
FigureMode = FigureProcessingMode.Auto,
VisionDeploymentName = "gpt-4o", // null means use the application's vision deployment
MaxFigureDescriptionsPerDocument = 25,
MaxItemsPerRun = 500,
Language = "en",
});
await fileSourceStore.CreateAsync(fileSource, cancellationToken);
- FTP and SFTP records store a
RemoteFileSourceMetadatafolder (RootPathdefault/,Recursive,MaxItems) plusFtpConnectionMetadataorSftpConnectionMetadatawith secrets protected byFtpResourceConstants.DataProtectionPurposeorSftpResourceConstants.DataProtectionPurpose(seecrestapps-core-mcp-file-resources). - SFTP connections need
HostKeyFingerprint(SHA256:..., several comma-separated); without it, or when the server's key differs, the run fails. FTP connections with a user name needEncryptionModeExplicitorImplicitunless the host setsFtpOptions.AllowUnencrypted, andValidateAnyCertificateneedsFtpOptions.AllowAnyCertificate. - Ingestion reads remote files through
BoundedRemoteDownloadand skips a file larger than the connection'sMaxFileBytes(100 MB when not set). - Creating or updating a record from JSON (
NewAsync/UpdateAsyncwith aJsonNode, recipes, deployment imports, APIs) merges the incomingPropertiesover the stored ones: omitted entries and fields keep their stored values, keys match without regard to case, and an entry sent asnullis removed. Admin editors that write metadata withPutbehave as before. - Saving validates the connector settings, refuses a data source that is not
Fileor no longer exists, and refuses a vision deployment that does not accept image input. FileSourceMetadataalso hasUtilityDeploymentName. A deployment deleted later falls back to the application's own.
Running
| Service | Does |
|---|---|
| IIngestionRunService.RunAsync(source) | one run of one record; returns and stores a FileSourceRunSummary |
| IFileSourceScheduler.RunDueAsync() | runs every due source; returns FileSourceSchedulerResult(Considered, Ran, Failed) |
| IFileSourceScheduler.GetDueAsync(now) / IsDue(source, now) | lets a host spread work over its own workers |
| FileSourceBackgroundService | timer that calls RunDueAsync every RunCheckIntervalMinutes |
The scheduler is scoped and creates no scope. A host with its own scheduler (Orchard Core background tasks, a cron job) resolves it inside its own scope and should remove FileSourceBackgroundService, or sources run twice. Commit the store afterwards (IStoreCommitter.CommitAsync), as the background jobs do; otherwise objects, item state and summaries are discarded with the scope. Due-ness is read from the stored summary, so restarts do not rerun everything.
FileSourceRunSummary stores Status (Running, Succeeded, PartiallyCompleted, Failed), StartedUtc, CompletedUtc, DiscoveryCompleted, DiscoveryCursor, ItemsDiscovered, ItemsIndexed, ItemsSkipped, ItemsDeleted, ItemsFailed, FiguresDiscovered, FiguresPendingDescription and Error. Read it with source.TryGet<FileSourceRunSummary>(out var summary).
What Gets Removed
- A partial listing never deletes anything. Removals happen only when the connector returns
IngestionDiscoveryResult.IsComplete = true. - A run reads at most
MaxItemsPerRunitems. When there are more, the connector returns aDiscoveryCursorand the next run resumes; a resumed run is never complete. - Each item carries an opaque change token (compared verbatim). An unchanged token is skipped; an item with no token is re-read every run.
- A document's identity comes from its bytes. Moving a file keeps its document, and a changed file replaces the document it produced unless another item of the same record still produces it.
- Reset state clears per-item state (
IngestionItemState) so the next run re-reads everything; it does not delete stored knowledge.
Figures found during a run are stored as PendingDescription and transcribed later by the figure backfill job, using the record's vision deployment.
Custom Connectors
Implement IIngestionConnector (namespace CrestApps.Core.AI.Indexing) and register it with AddCoreIngestionConnector<TConnector>(name, descriptor => ...). The record's Source must equal name. See references/connector-examples.md for a complete connector.
Upgrading from 1.x and 2.0 previews
- 1.x had no file sources. Preview builds used
CrestApps.Core.AI.Indexers; it is nowCrestApps.Core.AI.FileSourceswithAddCoreFileSources(),FileSourceOptions,FileSourceRunStatusand theFileSource*stored shapes. - Move configuration to
CrestApps:AI:FileSourcesand bind it withAddCoreFileSources(builder.Configuration). The 2.0 changelog saysCrestApps:Indexersis still read as a fallback, but the current source falls back to a section literally namedCrestApps:File sources, so do not rely on the old name. - Use
FileSystemConnectorOptions.AllowedRootsunder theFileSystemsub-section. The olderFileSourceOptions.AllowedLocalRoots(CrestApps:AI:FileSources:AllowedLocalRoots) is still merged into the allowed roots, so move entries rather than keeping both. - The
Ingesteddata source type is nowFile. File sources are their ownFileSourcerecords, no longer web crawler records. Hosts with stored preview records move them across. - Docs and changelog mention
IFileSourceRunService; the shipped interface isIIngestionRunServiceinCrestApps.Core.AI.Ingestion. - FTP and SFTP connectors moved to
CrestApps.Core.AI.FtpandCrestApps.Core.AI.Sftp. Connector names stored on records are stillFtpandSftp. - SFTP sources need a stored host key fingerprint, and FTP sources with credentials need
ExplicitorImplicitencryption (or the matchingFtpOptionsswitch); otherwise runs fail. - A recipe or API payload that carried
Propertiesnow takes effect (before, only top-level fields were copied, so FTP and SFTP sources came in without a connection).