FonsecaFramework.Ai.Knowledge
2026.11.25.5
dotnet add package FonsecaFramework.Ai.Knowledge --version 2026.11.25.5
NuGet\Install-Package FonsecaFramework.Ai.Knowledge -Version 2026.11.25.5
<PackageReference Include="FonsecaFramework.Ai.Knowledge" Version="2026.11.25.5" />
<PackageVersion Include="FonsecaFramework.Ai.Knowledge" Version="2026.11.25.5" />
<PackageReference Include="FonsecaFramework.Ai.Knowledge" />
paket add FonsecaFramework.Ai.Knowledge --version 2026.11.25.5
#r "nuget: FonsecaFramework.Ai.Knowledge, 2026.11.25.5"
#:package FonsecaFramework.Ai.Knowledge@2026.11.25.5
#addin nuget:?package=FonsecaFramework.Ai.Knowledge&version=2026.11.25.5
#tool nuget:?package=FonsecaFramework.Ai.Knowledge&version=2026.11.25.5
FonsecaFramework.Ai.Knowledge
Partition-bound incremental knowledge indexing for .NET 10 and 11, using VectorData 11.
Storage lives in FonsecaFramework.Ai.Knowledge.Storage; there are no separate database packages.
ADO.NET drivers are supplied by the host, not imposed on every installation.
SQL Server, PostgreSQL, SQLite or memory
Register an IEmbeddingGenerator<string, Embedding<float>>, then choose one:
using FonsecaFramework.Ai.Knowledge;
using FonsecaFramework.Ai.Knowledge.Storage;
// Host references Microsoft.Data.SqlClient; connection string comes from configuration.
services.AddFonsecaKnowledgeDatabase(
() => new Microsoft.Data.SqlClient.SqlConnection(connectionString),
KnowledgeDatabaseProvider.SqlServer,
options => options.CollectionName = "library");
// Or: host references Npgsql.
services.AddFonsecaKnowledgeDatabase(
() => new Npgsql.NpgsqlConnection(connectionString),
KnowledgeDatabaseProvider.PostgreSql);
// Or: host references Microsoft.Data.Sqlite. Use a persistent file, not :memory:.
services.AddFonsecaKnowledgeDatabase(
() => new Microsoft.Data.Sqlite.SqliteConnection("Data Source=knowledge.db;Pooling=False"),
KnowledgeDatabaseProvider.Sqlite);
// Or, for tests/demos (not durable):
services.AddFonsecaKnowledgeInMemory();
The factory must return a fresh unopened connection each time. Connections are collection-owned.
Direct construction is supported: new DbKnowledgeCollection(factory, provider, "library") or
new InMemoryKnowledgeCollection("library"), passed to new KnowledgeIndex(collection, embeddings).
Dispose collections only after operations finish. DI owns collections it constructs.
The database must already exist and the host must authorize its use. By default, first access creates two
fonseca_knowledge_* tables and an index on (collection, partition, source_id); SQLite uses WAL.
For externally provisioned databases, pass createSchema: false to the database registration overload
(or the four-argument DbKnowledgeCollection constructor). This executes no schema initialization or
SQLite WAL setup; the host must provision compatible tables and index separately, configure SQLite journal
mode if needed, and grant the runtime account the required data operations. Missing tables fail explicitly.
Index keys are SHA-256 hex identifiers, avoiding SQL Server's index-key size and collation limits;
unmodified names and source metadata are stored as JSON. Embeddings use little-endian float BLOBs
(varbinary(max) / bytea / BLOB). SQL values are parameterized. Batch upserts/deletes are
transactional, and an invalid batch leaves existing rows unchanged. Schema creation is additive;
collection deletion removes only that collection's rows, never tables or other collections.
Back up the database before upgrades; restoring its backup is the recovery path.
Search is exact cosine, O(chunks x dimensions), with a lazily loaded per-collection RAM cache.
It is a dependency-light persistence option, not an ANN engine for unbounded corpora. Revisions detect
writes by other collection instances. Transaction-scoped shared/exclusive collection locks protect
server-provider snapshots without serializable predicate conflicts between unrelated collections;
SQLite uses serializable transactions. SQL Server requires sp_getapplock permission and PostgreSQL
uses advisory locks. Provider errors/timeouts propagate; hosts may retry an entire idempotent operation.
Filters and filtered-retrieval ordering are compiled/evaluated in memory, not pushed into SQL.
Skip, ScoreThreshold, IncludeVectors, and filtered OrderBy are supported; stable ID ties allow paging.
Inputs and results are deep copies. Empty/nonfinite/wrong-dimension vectors fail explicitly.
One embedding dimension/model per collection; changing models requires a new collection/reindex. Built-in stores support cosine similarity only (no ANN index-kind setting). Cancellation is passed to ADO.NET, but Microsoft.Data.Sqlite executes SQL synchronously; tokens are checked at operation boundaries, not a promise to interrupt a running SQLite statement.
Ingest and retrieve
var index = provider.GetRequiredService<KnowledgeIndex>();
await index.UpsertSourceAsync(new KnowledgeSource("guide", "guide.md"), "user:42",
new[] { new ExtractedSegment("The replacement part is ZX-4471.") }, ct);
var results = await index.ForPartitionWithMetadata("user:42")
.SearchResultsAsync("ZX-4471", topK: 5, minScore: 0.3, ct);
// Raw SourceId, SourceName, SourceLink, Locator, Modality, ChunkIndex and Score;
// DisplaySourceName preserves the legacy decorated label.
await index.RemoveSourceAsync("guide", "user:42", ct);
Partitions are an access boundary, not inferred permissions: derive them only from authenticated host state. The index applies and rechecks partition filters. The connection factory is application-level configuration, never a request/model-selected database. Stored text is untrusted reference data. The host owns retention, authorization, database credentials and backups. Removing a source deletes its chunks only in the supplied partition; a collection persists until explicitly deleted.
When no connector-native hybrid search exists, sparse BM25 is lazily rebuilt from all stored chunks
in the searched partition on its first keyword search after startup (paged, no embeddings regenerated).
Subsequent writes through that KnowledgeIndex update postings incrementally. BM25 is not a separate
persistent index. Use one singleton index per writer process; writes through other DbKnowledgeCollection
instances refresh vector snapshots, but existing BM25 postings require a new KnowledgeIndex to rehydrate.
Direct SQL writes are unsupported because they bypass collection revision updates.
minScore is normalized relevance (max of dense relevance and keyword coverage), not an RRF score.
Optional KnowledgeIndexOptions.HybridRelativeScoreFloor = 0.8 additionally discards hybrid results
below 80% of the strongest candidate's relevance. Default null preserves existing behavior. This is
not a probability or a guarantee of semantic relevance; tune it for the embedding model and corpus.
Compatibility matrix
| Component | VectorData | Status |
|---|---|---|
| Built-in memory / SQLite / SQL Server / PostgreSQL collections | 11.0.0 | Supported exact-cosine stores |
| Host-provided connector built against VectorData 11 | 11.x | Must support the knowledge schema and filtered retrieval |
| Semantic Kernel connectors 1.74.0-preview built against VectorData 10 | 10.x | Not binary-compatible; do not resolve against 11 |
KnowledgeChunkRecord.Tags remains a List<string> for source compatibility, but the connector schema
stores scalar TagsJson instead. Third-party existing collections need a schema migration/reindex for
that field; do not reuse an old list-valued Tags schema without migrating it.
Changelog
2026.11.24.2
- Extract knowledge APIs into this package with unchanged namespaces;
FonsecaFramework.Aireferences it transitively and forwards shipped public types. Existing source references remain valid. - Add provider-neutral ADO.NET persistence for SQL Server, PostgreSQL and SQLite, plus memory storage.
- Preserve
Tagswhile using scalar JSON in connector schemas. - Verify restart BM25 rehydration; expose raw citation results and optional relative relevance floor.
No dependency on a consuming application, product-specific models, ML training or document SDKs.
FonsecaFramework.Ai supplies optional agent/embedding integrations;
FonsecaFramework.Ai.Documents references this package for PDF/Office extraction.
Running storage tests
MSTest uses temporary SQLite files and in-memory collections by default. Server-provider cases are
categorized Integration and require FONSECA_KNOWLEDGE_SQLSERVER / FONSECA_KNOWLEDGE_POSTGRES
environment variables containing connection strings to isolated non-production databases. Without
them the relevant cases are inconclusive, not passing. Tests create unique collections and remove
their rows afterward; the test database itself must already exist and is host-owned.
From the repository root, with the .NET 11 SDK and .NET 10/11 runtimes installed:
dotnet test .\FonsecaFramework.Tests\FonsecaFramework.Tests.csproj --filter "FullyQualifiedName~KnowledgeStorageTests"
| 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. net11.0 is compatible. |
-
net10.0
- Microsoft.Agents.AI (>= 1.28.0)
- Microsoft.Extensions.AI (>= 11.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 11.0.0)
- Microsoft.Extensions.VectorData.Abstractions (>= 11.0.1)
-
net11.0
- Microsoft.Agents.AI (>= 1.28.0)
- Microsoft.Extensions.AI (>= 11.0.1)
- Microsoft.Extensions.VectorData.Abstractions (>= 11.0.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on FonsecaFramework.Ai.Knowledge:
| Package | Downloads |
|---|---|
|
FonsecaFramework.Ai
FonsecaFramework.Ai is a .NET library that provides practical AI and machine learning utilities, including AutoML model building, RAG vector search, sentiment/discourse analysis, and OpenAI-compatible chat client integration. |
|
|
FonsecaFramework.Ai.Documents
Optional document extractors for FonsecaFramework.Ai knowledge indexing: PDF (PdfPig), Word, Excel and PowerPoint (Open XML SDK), with page, sheet and slide locators. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.11.25.5 | 0 | 11/26/2026 |
| 2026.11.25.4 | 0 | 11/26/2026 |
| 2026.11.25.1 | 0 | 11/25/2026 |
| 2026.11.24.2 | 60 | 11/24/2026 |