Commit Graph

208 Commits

Author SHA1 Message Date
Marco Minerva a0f1755c85 Add CancellationToken support to async methods #9
Introduce support for `CancellationToken` across various methods to allow for task cancellation and improve responsiveness.
- Update `DecodeAsync` method in `DocxContentDecoder.cs`, `PdfContentDecoder.cs`, `TextContentDecoder.cs`, and `IContentDecoder.cs` to include an optional `CancellationToken` parameter.
- Modify endpoint handlers in `Program.cs` to accept and pass `CancellationToken` parameters.
- Update methods in `ChatService.cs` to include `CancellationToken` parameters.
- Update methods in `DocumentService.cs` to include `CancellationToken` parameters.
- Update methods in `VectorSearchService.cs` to include `CancellationToken` parameters.
These changes ensure that long-running operations can be canceled if needed, improving the application's ability to handle cancellation requests gracefully.
2025-02-10 16:20:35 +01:00
Marco Minerva d0fce6ffd2 Simplify /api/ask-streaming response and update README
The response format for the `/api/ask-streaming` endpoint has been simplified by removing multiple individual elements that contained parts of the answer.

The README.md file was updated to correct the terminology from "tag" to "property" for the *streamState* attribute.
2025-02-07 12:08:03 +01:00
Marco Minerva eeb13e9096 Merge pull request #8 from marcominerva/token_usage
Token usage
2025-02-07 12:04:13 +01:00
Marco Minerva 9312bf35cb Add new endpoints and update README with details
Updated README.md to document new `/api/documents`, `/api/ask`, and `/api/ask-streaming` endpoints, including features like conversation history, token usage, and response streaming. Enhanced Program.cs by adding new endpoints for asking questions and streaming responses, with additional metadata. Updated `documentsApiGroup` to include new document management endpoints.
2025-02-07 12:02:48 +01:00
Marco Minerva f02a1c9b69 Refactor document operations into DocumentService
Refactored Program.cs to use AddAzureSql with new options. Added VectorSearchService and DocumentService as scoped services. Updated documentsApiGroup to use DocumentService for document operations and added a delete document endpoint. Moved document-related methods from VectorSearchService to new DocumentService for better separation of concerns.
2025-02-07 11:30:14 +01:00
Marco Minerva cdd0199e8f Refactor services and update token handling
- Replace `TotalTokenCount` with `EmbeddingTokenCount` in `ImportDocumentResponse`.
- Add `OriginalQuestion` and `ReformulatedQuestion` fields to `QuestionResponse` and a new constructor.
- Add a new constructor to `TokenUsageResponse` to initialize `Question`.
- Add `TextChunkerService` to service collection in `Program.cs`.
- Clarify prompt and update token counting in `ChatService`.
- Differentiate token counting in `TokenizerService` with `CountChatCompletionTokens` and `CountEmbeddingTokens`.
- Update `VectorSearchService` to use `TextChunkerService` and new token counting methods.
- Introduce `TextChunkerService` for text splitting and tokenization.
2025-02-07 10:24:16 +01:00
Marco Minerva fd6c63c9c4 Update Microsoft.SemanticKernel to 1.36.0
Updated the Microsoft.SemanticKernel package version from 1.35.0 to 1.36.0 in the SqlDatabaseVectorSearch.csproj file.
2025-02-05 18:00:37 +01:00
Marco Minerva 8e06979993 Refactor response types and enhance token usage handling 2025-01-30 12:56:33 +01:00
Marco Minerva dd58c547d0 Merge pull request #7 from marcominerva/content_decoders
Add Content decoders
2025-01-29 10:03:40 +01:00
Marco Minerva b8aace05a5 Update Microsoft.SemanticKernel to v1.35.0
Upgraded Microsoft.SemanticKernel package from version 1.34.0 to 1.35.0 in SqlDatabaseVectorSearch.csproj. This update includes new features, bug fixes, and other improvements provided in the latest version.
2025-01-29 10:00:25 +01:00
Marco Minerva af9158873f Add support for DOCX and TXT files, update error handling
Updated README.md to reflect support for PDF, DOCX, and TXT files.
Removed commented-out code in DocxContentDecoder.cs.
Added TextContentDecoder service in Program.cs and updated exception handling middleware.
Updated document upload endpoint description in Program.cs.
Modified VectorSearchService to throw NotSupportedException for unsupported content types.
Added TextContentDecoder class in TextContentDecoder.cs.
2025-01-29 09:58:22 +01:00
Marco Minerva 110e21e1e0 Add content decoding for PDF and DOCX files
- Added `using` statements in `Program.cs` for new content decoding.
- Registered new content decoder services in `builder.Services`.
- Modified `documentsApiGroup.MapPost` to pass `file.ContentType`.
- Refactored `VectorSearchService` to use `IServiceProvider` and handle content types.
- Added `DocumentFormat.OpenXml` package reference.
- Created `DocxContentDecoder` and `PdfContentDecoder` classes.
- Created `IContentDecoder` interface.
2025-01-29 09:43:22 +01:00
Marco Minerva f15f387510 Update VectorSearchService and appsettings.json
- Clarified comment in `ChatService.cs`.
- Added `TokenizerService` and `ILogger` parameters to `VectorSearchService` constructor.
- Updated paragraph splitting to use `tokenizerService.CountTokens`.
- Added logging for token count of each paragraph in `VectorSearchService`.
- Updated `ModelId` comment in `appsettings.json` to include "gpt-4o-mini".
- Changed `MaxTokensPerParagraph` in `appsettings.json` from 1024 to 1000.
2025-01-28 16:09:34 +01:00
Marco Minerva d53330934e Merge pull request #4 from marcominerva/streaming
Add support for response streaming
2025-01-28 11:36:05 +01:00
Marco Minerva 0de2db4b5e Update SqlDatabaseVectorSearch.png binary file 2025-01-28 11:34:23 +01:00
Marco Minerva 86f161697a Remove delay in /api/ask-streaming endpoint response
Eliminated the 50ms delay in the asynchronous streaming response
logic of the /api/ask-streaming endpoint by removing the line
`await Task.Delay(50);`. This change improves the response time
by removing unnecessary latency after each delta in the response
stream.
2025-01-28 11:24:51 +01:00
Marco Minerva 1ef2d384ec Add streaming support and improve JSON serialization
- Updated `Response` record class to allow nullable `Question` and `Answer` properties; moved `StreamState` enum to a new file.
- Added `JsonStringEnumConverter` in `Program.cs` for better enum serialization.
- Corrected terminology in document upload endpoint description.
- Introduced `/api/ask-streaming` endpoint for streaming question responses.
- Added `AskStreamingAsync` method in `VectorSearchService` for handling streaming logic.
- Created `StreamState.cs` to define `StreamState` enum with `Start`, `Append`, and `End` values.
2025-01-28 11:00:45 +01:00
Marco Minerva 44c6193674 Add streaming and refactor chat/question handling
Updated `Response` record in `Response.cs` to include an optional `StreamState` property, which can be `Start`, `Append`, or `End`. Added a new `StreamState` enum to `Response.cs`.

In `ChatService.cs`, added new methods `AskQuestionAsync` and `AskStreamingAsync` to handle asking questions and streaming responses, respectively. Refactored `CreateChatAsync` to return a `ChatHistory` object.

In `VectorSearchService.cs`, added a new `AskQuestionAsync` method to handle questions using `ChatService`. Updated `CreateContextAsync` to return a tuple with the reformulated question and chunks. Removed the previous implementation of `AskQuestionAsync` and replaced it with the new method utilizing `ChatService`.
2025-01-28 10:14:47 +01:00
Marco Minerva 14bc1c131f Update Microsoft.SemanticKernel to v1.34.0
Upgraded the Microsoft.SemanticKernel package from version 1.33.0 to 1.34.0 in the SqlDatabaseVectorSearch.csproj file. This update may include bug fixes, new features, or other improvements.
2025-01-23 09:04:13 +01:00
Marco Minerva 1406e98304 Update SQL server service method in ApplicationDbContext
Replaced AddAzureSql with AddSqlServer in ApplicationDbContext.
Configured vector search and set query tracking to NoTracking.
2025-01-16 17:14:54 +01:00
Marco Minerva b581b3786c Switch to Azure SQL and update EFCore package
Modified Program.cs to use AddAzureSql for ApplicationDbContext with UseVectorSearch and NoTracking options. Updated EFCore.SqlServer.VectorSearch package to version 9.0.0-preview.2 in SqlDatabaseVectorSearch.csproj.
2025-01-16 15:16:56 +01:00
Marco Minerva 9342b8d1e9 Add HTTP client config, update settings, and add package
- Added HTTP client defaults configuration in Program.cs.
- Adjusted OpenAPI configuration order in Program.cs.
- Changed MaxTokensPerParagraph in AppSettings.cs to 1000.
- Added Microsoft.Extensions.Http.Resilience package in SqlDatabaseVectorSearch.csproj.
- Reordered and added ModelId properties in appsettings.json.
2025-01-16 15:06:31 +01:00
Marco Minerva 6dbecfbc63 Update OpenAPI setup and package versions
Updated `Program.cs` to always execute OpenAPI setup, including `app.MapOpenApi()` and `app.UseSwaggerUI`, and added `options.RemoveServerList()` to `builder.Services.AddOpenApi`. Simplified `app.UseSwaggerUI` call.

In `SqlDatabaseVectorSearch.csproj`, updated `Microsoft.ML.Tokenizers` to `1.0.1`, `Microsoft.ML.Tokenizers.Data.Cl100kBase` and `Microsoft.ML.Tokenizers.Data.O200kBase` to `1.0.1`, `MinimalHelpers.OpenApi` to `2.1.3`, and `TinyHelpers.AspNetCore` to `4.0.15`.
2025-01-16 14:38:33 +01:00
Marco Minerva 3902481735 Update package versions in SqlDatabaseVectorSearch.csproj
- Updated EFCore.SqlServer.VectorSearch from 0.2.0 to 9.0.0-preview.1
- Updated Microsoft.AspNetCore.OpenApi from 9.0.0 to 9.0.1
- Updated Microsoft.EntityFrameworkCore.SqlServer from [8.0.11,9.0.0) to 9.0.1
- Updated Microsoft.Extensions.Caching.Hybrid from 9.0.0-preview.9.24556.5 to 9.1.0-preview.1.25064.3
2025-01-15 11:17:14 +01:00
Marco Minerva 9700051942 Add appSettings field and CreateQuestionAsync method
The `ChatService` class now includes a private readonly field `appSettings`, initialized via the constructor. A new method `CreateQuestionAsync` has been added to handle question creation asynchronously, leveraging chat history. Additionally, a comment has been updated for clarity regarding chunk limitations.
2025-01-10 11:15:18 +01:00
Marco Minerva b5c7ea57c3 Add TokenizerService and update settings for token limits
Updated Program.cs to use ConfigureAndGet for settings and added TokenizerService singleton. Modified ChatService to include TokenizerService and updated prompt logic for token limits. Added TokenizerService class using TiktokenTokenizer. Updated AppSettings and AzureOpenAISettings with new token and model settings. Updated SqlDatabaseVectorSearch.csproj with new package references and version bump. Updated appsettings.json with new settings.
2025-01-10 11:08:59 +01:00
Marco Minerva 80071e263e Update comments and package version
Enhanced comments in ChatService for token counting clarity.
Updated Microsoft.SemanticKernel to 1.33.0 in SqlDatabaseVectorSearch.csproj.
Added possible values comment for ModelId in appsettings.json.
2025-01-10 10:43:14 +01:00
Marco Minerva e0d4ee63ce Update package versions in SqlDatabaseVectorSearch.csproj
Updated Swashbuckle.AspNetCore.SwaggerUI from 7.1.0 to 7.2.0.
Updated TinyHelpers.AspNetCore from 4.0.5 to 4.0.6.
2024-12-11 10:02:12 +01:00
Marco Minerva 69db8891b5 Update package versions in SqlDatabaseVectorSearch.csproj
Upgraded Swashbuckle.AspNetCore.SwaggerUI from 7.1.0 to 7.2.0.
Upgraded TinyHelpers.AspNetCore from 4.0.5 to 4.0.6.
These updates may include bug fixes, performance improvements,
or new features.
2024-12-11 10:00:05 +01:00
Marco Minerva 54b50e9759 Update MinimalHelpers.OpenApi to version 2.1.2
Upgraded the MinimalHelpers.OpenApi package from version 2.0.17 to 2.1.2 to incorporate the latest features and bug fixes.
2024-12-10 11:58:30 +01:00
Marco Minerva 62d596ea98 Refactor caching and OpenAPI integration
Updated Program.cs to replace Swagger with OpenApi and MemoryCache with HybridCache. Refactored ChatService.cs to use HybridCache asynchronously. Removed MessageLimit from AppSettings.cs and appsettings.json. Updated SqlDatabaseVectorSearch.csproj to include HybridCache package and update dependencies.
2024-12-10 11:53:58 +01:00
Marco Minerva 67c600e9d4 Remove MessageLimit and MessageExpiration properties
The `AppSettings` class in `AppSettings.cs` has been modified to
remove the `MessageLimit` and `MessageExpiration` properties.
Correspondingly, the `appsettings.json` file has been updated
to remove the `MessageLimit` and `MessageExpiration` settings
under the `AppSettings` section to maintain consistency.
2024-12-10 11:44:20 +01:00
Marco Minerva 7e632892c7 Refactor caching and update dependencies
Updated Program.cs to use HybridCache and improved Swagger setup.
Refactored ChatService to simplify chat history management.
Updated SqlDatabaseVectorSearch.csproj to target net9.0 and
updated package references.
2024-12-10 11:38:59 +01:00
Marco Minerva 0575482bff Add EnableRetryOnFailure to SQL Server config
Added EnableRetryOnFailure option to the AddSqlServer method in Program.cs. This change configures the SQL Server connection to automatically retry on failure, improving the application's resilience to transient faults.
2024-12-05 18:00:01 +01:00
Marco Minerva 7989a1570f Add EnableRetryOnFailure to SQL Server configuration
Enhanced ApplicationDbContext configuration by adding EnableRetryOnFailure to improve resilience against transient SQL Server failures. Existing configurations for UseVectorSearch and NoTracking remain unchanged.
2024-12-05 17:57:41 +01:00
Marco Minerva 810b25c233 Update TinyHelpers.AspNetCore to version 4.0.5
Updated the TinyHelpers.AspNetCore package from version 4.0.4 to 4.0.5 to incorporate the latest fixes and improvements.
2024-12-04 15:35:36 +01:00
Marco Minerva 3caae928ba Update TinyHelpers.AspNetCore to version 4.0.5
Updated the TinyHelpers.AspNetCore package from version 4.0.4 to 4.0.5 to incorporate the latest fixes and improvements.
2024-12-04 15:33:51 +01:00
Marco Minerva f5d5fe151f Update TinyHelpers.AspNetCore package versions
Updated TinyHelpers.AspNetCore from 4.0.2 to 4.0.4 and
TinyHelpers.AspNetCore.Swashbuckle from 4.0.3 to 4.0.5 in
SqlDatabaseVectorSearch.csproj.
2024-12-04 10:59:56 +01:00
Marco Minerva 32d7a4da9b Update version range formatting in csproj file
Adjusted the version range specification for the `Microsoft.EntityFrameworkCore.SqlServer` package in `SqlDatabaseVectorSearch.csproj` by removing the space between the version numbers and the comma. This change improves the readability and uniformity of the code without altering the functional behavior of the version constraint.
2024-12-04 10:59:27 +01:00
Marco Minerva f4362f1e92 Update package versions and add new package reference
Updated Microsoft.SemanticKernel from 1.30.0 to 1.31.0.
Updated Swashbuckle.AspNetCore from 7.0.0 to 7.1.0.
Updated TinyHelpers.AspNetCore from 3.1.19 to 4.0.4.
Added TinyHelpers.AspNetCore.Swashbuckle version 4.0.5.
2024-12-04 10:57:56 +01:00
Marco Minerva a358567c0e Update package versions and add new package reference
Updated Microsoft.SemanticKernel from 1.30.0 to 1.31.0.
Updated Swashbuckle.AspNetCore from 7.0.0 to 7.1.0.
Updated TinyHelpers.AspNetCore from 3.1.19 to 4.0.2.
Added TinyHelpers.AspNetCore.Swashbuckle version 4.0.3.
2024-12-04 10:55:14 +01:00
Marco Minerva 9a7ea2f5b0 Update .editorconfig, VectorSearchService, and .csproj
- Updated .editorconfig with new C# style preferences.
- Modified using directives in VectorSearchService.cs.
- Changed tuple element order in VectorSearchService.cs foreach loop.
- Updated SqlDatabaseVectorSearch.csproj to target .NET 9.0.
- Updated package references and removed TinyHelpers package.

Update .editorconfig, fix VectorSearchService, upgrade packages

Updated .editorconfig with new C# style preferences. Removed `TinyHelpers.Extensions` using directive and corrected variable order in `VectorSearchService.cs`. Upgraded target framework to `net9.0` and updated several package references in `SqlDatabaseVectorSearch.csproj`.
2024-11-21 17:57:10 +01:00
Marco Minerva 232be6f083 Update code style, prompt, and dependencies
.editorconfig: Add new code style preferences.
ChatService.cs: Add formatted question to prompt string.
VectorSearchService.cs: Remove TinyHelpers.Extensions using directive.
VectorSearchService.cs: Use paragraphs.Index() in foreach loop.
SqlDatabaseVectorSearch.csproj: Update target framework to net9.0.
SqlDatabaseVectorSearch.csproj: Update package references, remove TinyHelpers.
2024-11-21 17:46:50 +01:00
Marco Minerva bcd085e49d Update README, adjust prompt formatting, add new package
Updated README.md to include a note on Vector support in Azure SQL Database/Managed Instance (EAP) and corrected "Dimension" to "Dimensions". Adjusted prompt formatting in ChatService.cs by replacing "---" with "=====" and improved text chunk appending. Added new package reference for `Microsoft.ML.Tokenizers.Data.Cl100kBase` in SqlDatabaseVectorSearch.csproj.
2024-11-07 10:03:58 +01:00
Marco Minerva b9bcb5c9fd Update README and refine prompt logic in ChatService
Updated README.md to include a note on Vector support in Azure SQL Database and corrected "Dimension" to "Dimensions". Modified ChatService.cs to append separator "---" only once at the end of the prompt.
2024-11-07 09:40:20 +01:00
Marco Minerva 084177346f Change ChatService to singleton, update package version
- Changed ChatService registration in Program.cs from scoped to singleton.
- Modified ChatHistory initialization in ChatService.cs by removing unnecessary line breaks.
- Renamed loop variable in ChatService.cs from 'result' to 'text' for better readability.
- Updated Microsoft.SemanticKernel package version from 1.26.0 to 1.27.0 in SqlDatabaseVectorSearch.csproj.
2024-11-06 17:26:09 +01:00
Marco Minerva 5b43031251 Add TokenizerService and update settings configuration
Updated Program.cs to use ConfigureAndGet method for settings,
changed ChatService to singleton, and added TokenizerService
singleton. Modified ChatService to use TokenizerService for
token counting. Updated AppSettings and AzureOpenAISettings
with new properties. Added new package references in
SqlDatabaseVectorSearch.csproj. Updated appsettings.json with
new properties. Added TokenizerService class for token counting.
2024-11-06 17:20:05 +01:00
Marco Minerva c18a6b4e03 Reorder method calls for Embedding property
Swapped the order of `IsRequired` and `HasColumnType("vector(1536)")` method calls for the `Embedding` property in the `ApplicationDbContext` class. This change improves readability and adheres to a preferred coding convention without altering functionality.
2024-11-05 17:18:48 +01:00
Marco Minerva dc0b557010 Update Microsoft.SemanticKernel to v1.26.0
Upgraded the Microsoft.SemanticKernel package from version 1.25.0 to 1.26.0 to incorporate the latest features and bug fixes.
2024-11-05 17:07:15 +01:00
Marco Minerva bb3e794a29 Update README: clarify EFCore usage and SQL note
The README.md file has been updated to specify that Vectors are saved and retrieved using the `EFCore.SqlServer.VectorSearch` library with Entity Framework Core. Additionally, the note about using straight SQL has been moved to a separate section and rephrased for better clarity.
2024-11-05 11:25:45 +01:00