CrestApps.Core Azure AI Search
Use Azure AI Search as the knowledge-base backend for AI documents, AI data sources and AI memory. For the data source model see crestapps-core-data-sources.
Registration
builder.Services.AddCrestAppsCore(crestApps => crestApps
.AddAISuite(ai => ai.AddAzureOpenAI())
.AddIndexingServices(indexing => indexing
.AddYesSqlStores()
.AddAzureAISearch(
builder.Configuration.GetSection("CrestApps:AzureAISearch"),
azureAISearch => azureAISearch
.AddAIDocuments()
.AddAIDataSources()
.AddAIMemory())));
| Call | Package | Adds |
|---|---|---|
| AddCoreAzureAISearchServices(section) | CrestApps.Core.Azure.AISearch | AzureAISearchConnectionOptions, IAzureAISearchClientFactory, a singleton SearchIndexClient, keyed IDataSourceContentManager, IDataSourceDocumentReader, IODataFilterTranslator, ISearchIndexManager, ISearchDocumentManager |
| AddAzureAISearchODataFilterTranslator() | CrestApps.Core.Azure.AISearch | only the keyed translator, for hosts that bring their own clients |
| AddAIDocuments() / AddCoreAzureAISearchAIDocumentSource() | CrestApps.Core.AI.Azure.AISearch | AIDocuments index-profile source, profile handler, keyed IVectorSearchService |
| AddAIDataSources() / AddCoreAzureAISearchAIDataSource() | CrestApps.Core.AI.Azure.AISearch | DataSource index-profile source, keyed AzureAISearchAIDataSourceSourceHandler, and AddCoreAIDataSourceRag() |
| AddAIMemory() / AddCoreAzureAISearchAIMemorySource() | CrestApps.Core.AI.Azure.AISearch | AIMemory index-profile source, profile handler, keyed IMemoryVectorSearchService |
Every keyed service uses AISearchConstants.ProviderName ("AzureAISearch").
Configuration
{
"CrestApps": {
"AzureAISearch": {
"Endpoint": "https://my-search.search.windows.net",
"AuthenticationType": "Default",
"IdentityClientId": "",
"IndexPrefix": ""
}
}
}
AzureAISearchConnectionOptions: Endpoint, AuthenticationType (Default uses DefaultAzureCredential and is the fallback for empty or unknown values, ApiKey, ManagedIdentity), ApiKey, IdentityClientId (user-assigned identity) and IndexPrefix. The older IndexesPrefix is still honored when IndexPrefix is empty. Prefer managed identity in Azure, and keep any admin key out of source control. Vector search needs the Basic tier or higher.
Filters and Typed Columns
- The translator prefixes source fields with
filters/(category eq 'support'becomesfilters/category eq 'support'). Azure AI Search only filters on fields the schema declares filterable, so the knowledge base index must declare thefilterscomplex field and each sub-field you filter on. contentType,rootId,parentIdandpagemap to top-level columns, andcontentType eq nullis a null test.AzureAISearchIndexManager.TryAddFieldsAsyncadds the typed columns to an existing index on the next sync.
External Azure AI Search Sources
An AIDataSource with Source = AIDataSourceSourceTypes.AzureAISearch reads a remote index configured on the data source itself: Endpoint, AuthenticationType, IndexName, IdentityClientId, and an ApiKey protected with AIDataSourceProtectionConstants.SourceSecretPurpose. This is separate from the backend options above. Notify the sync pipeline with IAIDataSourceChangeNotifier when the remote index changes.
Supplying Your Own Client
A host that already holds a SearchIndexClient, such as a multi-tenant host with one client per tenant, passes a Func<IServiceProvider, SearchIndexClient> instead of a configuration section:
using CrestApps.Core.Azure.AISearch;
using CrestApps.Core.AI.Azure.AISearch;
using CrestApps.Core.Infrastructure;
// Every core service with the host's client. No IAzureAISearchClientFactory or SearchIndexClient is registered.
builder.Services.AddCoreAzureAISearchServices(sp => sp.GetRequiredService<TenantSearchClients>().IndexClient);
// AI search services alone, without the index profile sources or handlers.
builder.Services
.AddAzureAISearchVectorSearchService(
sp => sp.GetRequiredService<TenantSearchClients>().IndexClient,
new DocumentIndexColumnNames { FileName = "file_name" })
.AddAzureAISearchMemoryVectorSearchService(sp => sp.GetRequiredService<TenantSearchClients>().IndexClient)
.AddAzureAISearchAIDataSourceSourceHandler();
| Method | Registers |
|---|---|
| AddCoreAzureAISearchServices(Func<IServiceProvider, SearchIndexClient>) | content manager, document reader, filter translator, index and document managers with the supplied client |
| AddAzureAISearchDataSourceContentManager(clientFactory) / AddAzureAISearchDataSourceDocumentReader(clientFactory) | one service each |
| AddAzureAISearchVectorSearchService(clientFactory, DocumentIndexColumnNames columnNames = null) | keyed IVectorSearchService for AI documents |
| AddAzureAISearchMemoryVectorSearchService(clientFactory) | keyed IMemoryVectorSearchService |
| AddAzureAISearchAIDataSourceSourceHandler() or (Func<IServiceProvider, IAzureAISearchClientFactory>) | the external-source handler, with the default or a supplied client factory |
- The factory runs each time a scoped service is created, so return a client the host already holds.
- Search services are added only when none is registered for the key, so a host can register its own first and still call
AddAIDocuments()orAddAIMemory(). The source handler usesAddKeyedScoped, so the last registration wins. It connects with the credentials stored on each data source, which is why it takes anIAzureAISearchClientFactory. DocumentIndexColumnNames(inCrestApps.Core.Infrastructure) names the fields of the host's AI documents index; each defaults toDocumentIndexConstants.ColumnNames.
Escaping Filter Values
Build any filter from untrusted values with ODataFilter (CrestApps.Core.Azure.AISearch); every filter the provider builds goes through it:
ODataFilter.Quote("O'Brien"); // 'O''Brien'
ODataFilter.Equal("userId", userId); // userId eq '...'
ODataFilter.AnyEqual("referenceId", ["a", "b"]); // referenceId eq 'a' or referenceId eq 'b'
ODataFilter.Escape("O'Brien"); // O''Brien
Quote(null) returns the OData null literal. Field names are written as is, so pass only names your code controls.
Troubleshooting
| Symptom | Check |
|---|---|
| Index profile creation reports the provider is not configured | Endpoint missing from the bound section |
| 403 or credential errors | AuthenticationType, role assignments for the managed identity, or the admin key |
| Filter request fails | declare filters and the filtered sub-fields as filterable |
| Filter ignored with a warning | no keyed translator; call AddAzureAISearchODataFilterTranslator() |
Upgrading Within 2.0 Previews
- The section-based registrations now call the client-factory overloads with the factory's client, so their behavior is unchanged.
- Security fix: the AI document and AI memory searches did not escape the reference and user identifiers in their filters; a crafted identifier could widen the filter to other references or users. Both are escaped now. Escape your own filter values with
ODataFilter.
Upgrading from 1.x
- Existing indexes keep working; the typed columns are added in place and missing
contentTypereads astext. - Hosts that create their own
SearchIndexClientcan register onlyAddAzureAISearchODataFilterTranslator(). - Embeddings resolve through the
embeddingdeployment slot or the index profile'sEmbeddingDeploymentName; deploymentPurposeis gone.