GovUK.Dfe.AI.Agents.AISearch
0.0.1-prerelease.316
Prefix Reserved
dotnet add package GovUK.Dfe.AI.Agents.AISearch --version 0.0.1-prerelease.316
NuGet\Install-Package GovUK.Dfe.AI.Agents.AISearch -Version 0.0.1-prerelease.316
<PackageReference Include="GovUK.Dfe.AI.Agents.AISearch" Version="0.0.1-prerelease.316" />
<PackageVersion Include="GovUK.Dfe.AI.Agents.AISearch" Version="0.0.1-prerelease.316" />
<PackageReference Include="GovUK.Dfe.AI.Agents.AISearch" />
paket add GovUK.Dfe.AI.Agents.AISearch --version 0.0.1-prerelease.316
#r "nuget: GovUK.Dfe.AI.Agents.AISearch, 0.0.1-prerelease.316"
#:package GovUK.Dfe.AI.Agents.AISearch@0.0.1-prerelease.316
#addin nuget:?package=GovUK.Dfe.AI.Agents.AISearch&version=0.0.1-prerelease.316&prerelease
#tool nuget:?package=GovUK.Dfe.AI.Agents.AISearch&version=0.0.1-prerelease.316&prerelease
GovUK.Dfe.AI.Agents.AISearch
Gives your GovUK.Dfe.AI.Agents
agents evidence from Azure AI Search. Results are numbered, so agents must cite them as [Evidence n].
Set up
dotnet add package GovUK.Dfe.AI.Agents.AISearch
"AiAgents": {
"AISearch": {
"Endpoint": "https://<search>.search.windows.net",
"Indexes": [ { "Name": "ofsted_index", "ContentFields": [ "title", "content" ] } ]
}
}
builder.Services.AddAgents(builder.Configuration, agents => agents
.AddAgents(BriefingAgents.All)
.AddAISearch());
Give the app's identity the Search Index Data Reader role. To use a different identity for search, add
AISearch:Authentication, or set one in code with agents.UseAISearchCredential(credential).
Search without agents
An app that only needs search results, e.g. a search page, can add search on its own. It needs no Foundry settings and no agents:
builder.Services.AddAISearch(builder.Configuration, new ManagedIdentityCredential());
It reads the same AiAgents:AISearch section. Pass a credential, or leave it out and set a complete
AiAgents:AISearch:Authentication block (TenantId, ClientId, ClientSecret). If you later add agents with
agents.AddAISearch(), search is still registered only once.
Use
Inject IContextRetriever, search, and pass the result as evidence:
var evidence = await search.GetContextAsync("ofsted_index", $"Ofsted inspection {urn}", size: 10,
filter: $"urn eq {urn}", cancellationToken: ct);
var result = await agents.RunAsync(BriefingAgents.Ofsted, "Summarise the latest inspection.", evidence, ct);
Pass the result itself, not evidence.Text, so its citation sources come with it.
- Filter every search to the record you mean, e.g. one school. Relevance alone also returns similarly named ones.
- Filters are escaped for you: write them as interpolated strings, and every
{value}is escaped, so a value can't change what the filter matches. A plain or concatenated string won't compile. If you already have an escaped filter (e.g. fromSearchFilter.Create), pass it withODataFilter.Raw(filter). - Set
ContentFieldson each index. Otherwise every string field, including ids and URLs, is sent to the model. - Weak matches are dropped: results scoring below half the top score are removed. Change this with
AISearch:MinimumRelevanceFilter(default0.5). - Large results: evidence is capped at
AISearch:MaxEvidenceCharacters(default 190,000, just under core's 200,000). Whole results are kept, most relevant first, and the rest are left out with a note, so no result is cut mid-way and citations still match. Raise both limits together for a larger model. To fetch less, lowersize.
Citations
Agents cite results as [Evidence n]. Each one reaches your app as something a reader can use, with no settings:
| The result has | Rated Good [Evidence 1]. becomes |
|---|---|
| A field holding a full web address | Rated Good [<a href="https://reports.ofsted.gov.uk/...">Copthorne School – Key Stage 2…</a>]. |
| No web address | Rated Good [Copthorne School – Key Stage 2…]. |
- The text is the start of the result itself, on one line and cut at about 80 characters. Square brackets set each citation apart from the answer's own text.
- The link is the first field whose whole value is a full
httpsorhttpaddress. That field isn't sent to the model, so it can't write links itself. WithContentFieldsset, only those fields come back, so include the address field to get links. - No citations for an agent with
RequiredCitations = false: they aren't asked for, and any the model writes are removed. - After the checks: citations change only once the answer passes, so each refers to real evidence.
Validateand run observers still see[Evidence n]. - Your app shows HTML: render the answer as HTML, or as Markdown that allows inline HTML. It's safe: the citation links are the only HTML in an answer, as any the model writes is shown as text.
- Works for
RunAsync,RunStreamingAsyncandRunParallelAsync(return the search result fromresolveEvidence). Evidence joined from several searches keeps[Evidence n], as their numbers would clash.
Better matches: semantic and hybrid search
Keyword search misses documents that use different words, e.g. "safeguarding concerns" and "child protection issues". Set either or both of these on an index:
"Indexes": [ {
"Name": "ofsted_index",
"ContentFields": [ "title", "content" ],
"SemanticConfiguration": "default",
"VectorFields": [ "contentVector" ]
} ]
| Setting | Search type | The index needs |
|---|---|---|
| Neither | Keyword | Nothing extra |
SemanticConfiguration |
Keyword, re-ranked by meaning | A semantic configuration, and the semantic ranker enabled (Basic tier or higher) |
VectorFields |
Hybrid: keyword plus vector | A vectorizer, so the service embeds the query (your app needs no embedding model) |
| Both | Hybrid, re-ranked by meaning (best results) | Both of the above |
Your filter is applied before the vector search, so hybrid results still match only the record you asked about.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Azure.Search.Documents (>= 12.0.0)
- GovUK.Dfe.AI.Agents (>= 0.0.1-prerelease.316)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.0.1-prerelease.316 | 36 | 10/9/2026 |
| 0.0.1-prerelease.289 | 40 | 10/9/2026 |
| 0.0.1-prerelease.263 | 37 | 10/9/2026 |
| 0.0.1-prerelease.238 | 35 | 10/9/2026 |
| 0.0.1-prerelease.214 | 36 | 10/9/2026 |
| 0.0.1-prerelease.191 | 30 | 10/9/2026 |
| 0.0.1-prerelease.169 | 35 | 10/9/2026 |
| 0.0.1-prerelease.148 | 37 | 10/9/2026 |
| 0.0.1-prerelease.128 | 43 | 10/9/2026 |
| 0.0.1-prerelease.109 | 43 | 10/7/2026 |
| 0.0.1-prerelease.91 | 43 | 10/7/2026 |
| 0.0.1-prerelease.74 | 47 | 10/6/2026 |
| 0.0.1-prerelease.58 | 54 | 10/5/2026 |
| 0.0.1-prerelease.44 | 50 | 10/5/2026 |
| 0.0.1-prerelease.31 | 49 | 10/5/2026 |
| 0.0.1-prerelease.20 | 61 | 10/2/2026 |
| 0.0.1-prerelease.10 | 54 | 10/2/2026 |