Implement Chat With Documents (In-Memory RAG) ...
- Add XAiDocumentModels (IngestResult, AskRequest, Answer, AnswerChunk, Source, SessionInfo, RAGDescriptor DTOs); - Add AskWithContextAsync and AskWithContextAsEnumerable (Context Actions) to IXAiServiceBase and XAIServiceBase; - Add GetContextHistory and BuildContextBlock Helpers for Building RAG Chat History without Persisting; - Rewrite ChatWithDocumentsController with Ingest, Ask, AskStream (SSE), Get Session and Delete Session Endpoints; - Add XInMemoryVectorStoreCleanupService (BackgroundService) for Removing Expired Sessions Periodically; - Add AddXAiChatWithDocuments DI Extension, Register Cleanup HostedService and use it in Startup; - Add RAGDescriptor Property to XAiApiConfiguration and its Section to appsettings.Development.json; - Add ChatWithDocuments System Prompt to Prompts in appsettings.Development.json; - Add IsValid Extension Method for XAiDocumentAskRequest; - Optimize XInMemoryVectorStore.Search (Query Embedding Converted once) and Refactor Formatting; - Remove Unused Usings in XAIServiceBase and IXAiServiceBase; - ...
This commit is contained in:
+142
-124
@@ -1,125 +1,143 @@
|
||||
{
|
||||
"AllowedOrigins": [
|
||||
"http://localhost:5000",
|
||||
"https://localhost:5001",
|
||||
"http://api.saherelm.ir",
|
||||
"https://api.saherelm.ir",
|
||||
"http://api.saherelmhub.ir",
|
||||
"https://api.saherelmhub.ir"
|
||||
],
|
||||
"IdentityServiceConfiguration": {
|
||||
"Authority": "https://localhost:4001",
|
||||
"ApiName": "xSaherElmAPI",
|
||||
"ApiSecret": "s@H@1694056",
|
||||
"ClientId": "xSaherElmAPIClient",
|
||||
"ClientSecret": "s@H@1694056",
|
||||
"XPoweredValue": "SaherElmITCenter",
|
||||
"XRevisionSecretKey": "SaherElmITCenter@1694056",
|
||||
"DefaultClientTimeout": -1
|
||||
},
|
||||
"StorageConfiguration": {
|
||||
"Authority": "https://localhost:5001",
|
||||
"IdentityAuthority": "https://localhost:5001",
|
||||
"Storage": "Storage",
|
||||
"Temp": "Temp",
|
||||
"Thumb": "Thumb",
|
||||
"Uploads": "Uploads",
|
||||
"Widgets": "Widgets",
|
||||
"Image": "Image",
|
||||
"Audio": "Audio",
|
||||
"Video": "Video",
|
||||
"Document": "Document",
|
||||
"FilePrefix": "xSaherElm_",
|
||||
"ThumbPrefix": "Thumb_",
|
||||
"ThumbSize": 512,
|
||||
"ThumbQuality": 72,
|
||||
"MaxFileSize": 41943040
|
||||
},
|
||||
"AiApiConfiguration": {
|
||||
"Models": [
|
||||
{
|
||||
"ApiKey": "",
|
||||
"Name": "Gemma",
|
||||
"LLM": "gemma3:1b",
|
||||
"Provider": "OpenAI",
|
||||
"Url": "http://178.131.88.93:1112/v1"
|
||||
},
|
||||
{
|
||||
"ApiKey": "",
|
||||
"Name": "Qwen",
|
||||
"LLM": "qwen-9b",
|
||||
"Provider": "OpenAI",
|
||||
"Url": "http://178.131.88.93:1114/v1"
|
||||
},
|
||||
{
|
||||
"ApiKey": "",
|
||||
"Name": "Embed",
|
||||
"LLM": "bge-m3",
|
||||
"Provider": "OpenAI",
|
||||
"Url": "http://178.131.88.93:1113/v1"
|
||||
}
|
||||
],
|
||||
"Prompts": [
|
||||
{
|
||||
"Name": "Introduction",
|
||||
"Template": "your name is xSaherElmAi, you are a professional ai assistant which develped by SaherElm IT Center, answer each questions by it's language.",
|
||||
"Description": "",
|
||||
"Params": []
|
||||
},
|
||||
{
|
||||
"Name": "ContentExtraction",
|
||||
"Template": "You are an Expert Powerful OCR Engine. your job isReading all Contents in Given Document and Retrieve them as Raw Text by following these rules: 1. Converst all tables to Markdown format. 2. extract numbers, date and times and names exactly as is. 3. do not add any extra descriptions, introduction or summarization from yourself and just return extracted Content.",
|
||||
"Description": "",
|
||||
"Params": []
|
||||
},
|
||||
{
|
||||
"Name": "Embedding",
|
||||
"Template": "your name is xSaherElmAi, you are a professional ai assistant which develped by SaherElm IT Center specified for Embedding Documents",
|
||||
"Description": "",
|
||||
"Params": []
|
||||
}
|
||||
],
|
||||
"OCR": {
|
||||
"DataPath": "Models",
|
||||
"EngineMode": "LstmOnly",
|
||||
"EnableOcrFallback": true,
|
||||
"DefaultLanguage": "fas+eng"
|
||||
},
|
||||
"Transcript": {
|
||||
"Language": "fa",
|
||||
"ModelsPath": "Models/ggml-base.bin"
|
||||
},
|
||||
"PDFToImageDescriptor": {
|
||||
"Dpi": 300,
|
||||
"Width": 0,
|
||||
"Height": 0,
|
||||
"UseTiling": false,
|
||||
"WithFormFill": false,
|
||||
"WithAspectRatio": false,
|
||||
"WithAnnotations": false,
|
||||
"DpiRelativeToBounds": false,
|
||||
"MaxImageWidth": 2000,
|
||||
"MinTextLengthThreshold": 50,
|
||||
"MaxPagesForImageFallback": 0
|
||||
},
|
||||
"ProxyConfiguration": {
|
||||
"Enabled": true,
|
||||
"RoutePrefix": "/ai-model"
|
||||
},
|
||||
"TextChunker": {
|
||||
"ChunkSize": 800,
|
||||
"ChunkOverlap": 150,
|
||||
"MinChunkSize": 50,
|
||||
"NormalizeWhitespace": true,
|
||||
"ChunkIdentifierSeparator": "#"
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Microsoft": "Warning",
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
"AllowedOrigins": [
|
||||
"http://localhost:5000",
|
||||
"https://localhost:5001",
|
||||
"http://api.saherelm.ir",
|
||||
"https://api.saherelm.ir",
|
||||
"http://api.saherelmhub.ir",
|
||||
"https://api.saherelmhub.ir"
|
||||
],
|
||||
"IdentityServiceConfiguration": {
|
||||
"Authority": "https://localhost:4001",
|
||||
"ApiName": "xSaherElmAPI",
|
||||
"ApiSecret": "s@H@1694056",
|
||||
"ClientId": "xSaherElmAPIClient",
|
||||
"ClientSecret": "s@H@1694056",
|
||||
"XPoweredValue": "SaherElmITCenter",
|
||||
"XRevisionSecretKey": "SaherElmITCenter@1694056",
|
||||
"DefaultClientTimeout": -1
|
||||
},
|
||||
"StorageConfiguration": {
|
||||
"Authority": "https://localhost:5001",
|
||||
"IdentityAuthority": "https://localhost:5001",
|
||||
"Storage": "Storage",
|
||||
"Temp": "Temp",
|
||||
"Thumb": "Thumb",
|
||||
"Uploads": "Uploads",
|
||||
"Widgets": "Widgets",
|
||||
"Image": "Image",
|
||||
"Audio": "Audio",
|
||||
"Video": "Video",
|
||||
"Document": "Document",
|
||||
"FilePrefix": "xSaherElm_",
|
||||
"ThumbPrefix": "Thumb_",
|
||||
"ThumbSize": 512,
|
||||
"ThumbQuality": 72,
|
||||
"MaxFileSize": 41943040
|
||||
},
|
||||
"AiApiConfiguration": {
|
||||
"Models": [
|
||||
{
|
||||
"ApiKey": "",
|
||||
"Name": "Gemma",
|
||||
"LLM": "gemma3:1b",
|
||||
"Provider": "OpenAI",
|
||||
"Url": "http://178.131.88.93:1112/v1"
|
||||
},
|
||||
{
|
||||
"ApiKey": "",
|
||||
"Name": "Qwen",
|
||||
"LLM": "qwen-9b",
|
||||
"Provider": "OpenAI",
|
||||
"Url": "http://178.131.88.93:1114/v1"
|
||||
},
|
||||
{
|
||||
"ApiKey": "",
|
||||
"Name": "Embed",
|
||||
"LLM": "bge-m3",
|
||||
"Provider": "OpenAI",
|
||||
"Url": "http://178.131.88.93:1113/v1"
|
||||
}
|
||||
],
|
||||
"Prompts": [
|
||||
{
|
||||
"Name": "Introduction",
|
||||
"Template": "your name is xSaherElmAi, you are a professional ai assistant which develped by SaherElm IT Center, answer each questions by it's language.",
|
||||
"Description": "",
|
||||
"Params": []
|
||||
},
|
||||
{
|
||||
"Name": "ContentExtraction",
|
||||
"Template": "You are an Expert Powerful OCR Engine. your job isReading all Contents in Given Document and Retrieve them as Raw Text by following these rules: 1. Converst all tables to Markdown format. 2. extract numbers, date and times and names exactly as is. 3. do not add any extra descriptions, introduction or summarization from yourself and just return extracted Content.",
|
||||
"Description": "",
|
||||
"Params": []
|
||||
},
|
||||
{
|
||||
"Name": "Embedding",
|
||||
"Template": "your name is xSaherElmAi, you are a professional ai assistant which develped by SaherElm IT Center specified for Embedding Documents",
|
||||
"Description": "",
|
||||
"Params": []
|
||||
},
|
||||
{
|
||||
"Name": "ChatWithDocuments",
|
||||
"Template": "You are a document question-answering assistant. Answer the user's question ONLY based on the provided Context chunks below. Follow these rules: 1. If the answer is not present in the Context, clearly state that the information was not found in the provided documents and do not make up an answer. 2. When using information from a chunk, cite its source identifier in square brackets (e.g. [file.pdf#3]). 3. Answer in the same language as the user's question. 4. Be concise and precise; do not add unrelated information.",
|
||||
"Description": "System prompt for RAG based Chat With Documents",
|
||||
"Params": []
|
||||
}
|
||||
],
|
||||
"OCR": {
|
||||
"DataPath": "Models",
|
||||
"EngineMode": "LstmOnly",
|
||||
"EnableOcrFallback": true,
|
||||
"DefaultLanguage": "fas+eng"
|
||||
},
|
||||
"Transcript": {
|
||||
"Language": "fa",
|
||||
"ModelsPath": "Models/ggml-base.bin"
|
||||
},
|
||||
"PDFToImageDescriptor": {
|
||||
"Dpi": 300,
|
||||
"Width": 0,
|
||||
"Height": 0,
|
||||
"UseTiling": false,
|
||||
"WithFormFill": false,
|
||||
"WithAspectRatio": false,
|
||||
"WithAnnotations": false,
|
||||
"DpiRelativeToBounds": false,
|
||||
"MaxImageWidth": 2000,
|
||||
"MinTextLengthThreshold": 50,
|
||||
"MaxPagesForImageFallback": 0
|
||||
},
|
||||
"ProxyConfiguration": {
|
||||
"Enabled": true,
|
||||
"RoutePrefix": "/ai-model"
|
||||
},
|
||||
"TextChunker": {
|
||||
"ChunkSize": 800,
|
||||
"ChunkOverlap": 150,
|
||||
"MinChunkSize": 50,
|
||||
"NormalizeWhitespace": true,
|
||||
"ChunkIdentifierSeparator": "#"
|
||||
},
|
||||
"RAGDescriptor": {
|
||||
"MaxTopK": 20,
|
||||
"DefaultTopK": 5,
|
||||
"DefaultTtlMinutes": 30,
|
||||
"EmbeddingBatchSize": 32,
|
||||
"SourceSnippetLength": 200,
|
||||
"DefaultMinScore": "0.35f",
|
||||
"MetadataFileName": "fileName",
|
||||
"MetadataMimeType": "mimeType",
|
||||
"PromptName": "ChatWithDocuments",
|
||||
"MetadataChunkIndex": "chunkIndex"
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Microsoft": "Warning",
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user