Basic Configuration
SmartRAG basic configuration options - configuration methods, chunking and retry settings
Configuration Methods
SmartRAG offers two configuration methods:
Quick Setup (Recommended)
Configure SmartRAG in your Program.cs or Startup.cs:
For Web API Applications:
using SmartRAG.Extensions;
using SmartRAG.Enums;
var builder = WebApplication.CreateBuilder(args);
// Simple one-line configuration
builder.Services.AddSmartRag(builder.Configuration, options =>
{
options.StorageProvider = StorageProvider.InMemory;
options.AIProvider = AIProvider.Gemini;
options.DefaultLanguage = "tr"; // Optional: Default language for document processing
});
var app = builder.Build();
app.Run();
For Console Applications:
using SmartRAG.Extensions;
using SmartRAG.Enums;
var services = new ServiceCollection();
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
// UseSmartRag returns IServiceProvider with auto-started services
var serviceProvider = services.UseSmartRag(
configuration,
storageProvider: StorageProvider.InMemory,
aiProvider: AIProvider.Gemini,
defaultLanguage: "tr" // Optional
);
// Use the service provider
var documentService = serviceProvider.GetRequiredService<IDocumentService>();
Advanced Setup
using SmartRAG.Extensions;
using SmartRAG.Enums;
var builder = WebApplication.CreateBuilder(args);
// Advanced configuration with options
builder.Services.AddSmartRag(builder.Configuration, options =>
{
// AI Provider
options.AIProvider = AIProvider.OpenAI;
// Storage Provider
options.StorageProvider = StorageProvider.Qdrant;
// Chunking Configuration
options.MaxChunkSize = 1000;
options.MinChunkSize = 100;
options.ChunkOverlap = 200;
// Retry Configuration
options.MaxRetryAttempts = 3;
options.RetryDelayMs = 1000;
options.RetryPolicy = RetryPolicy.ExponentialBackoff;
// Fallback Providers
options.EnableFallbackProviders = true;
options.FallbackProviders = new List<AIProvider>
{
AIProvider.Anthropic,
AIProvider.Gemini
};
// Default Language
options.DefaultLanguage = "tr"; // Optional: Default language for document processing
});
var app = builder.Build();
app.Run();
SmartRagOptions - Core Options
Core configuration options available in SmartRagOptions:
| Option | Type | Default | Description |
|---|---|---|---|
AIProvider |
AIProvider |
OpenAI |
AI provider for embeddings and text generation |
StorageProvider |
StorageProvider |
InMemory |
Storage backend for documents and vectors |
ConversationStorageProvider |
ConversationStorageProvider? |
null |
Separate storage for conversation history (optional) |
EnableAutoSchemaAnalysis |
bool |
true |
Automatically analyze database schemas on startup |
DefaultLanguage |
string? |
null |
Default language code for document processing (ISO 639-1 format, e.g., "tr", "en", "de"). Used when language is not specified in WatchedFolderConfig or document upload. |
ConversationStorageProvider
Separate storage configuration for conversation history, independent from document storage:
builder.Services.AddSmartRag(configuration, options =>
{
options.AIProvider = AIProvider.OpenAI;
options.StorageProvider = StorageProvider.Qdrant; // For documents
options.ConversationStorageProvider = ConversationStorageProvider.Redis; // For conversations
});
Available Options
| Option | Description |
|---|---|
Redis |
Store conversations in Redis (high-performance cache) |
SQLite |
Store conversations in SQLite database (embedded, lightweight) |
FileSystem |
Store conversations in file system (simple, persistent) |
InMemory |
Store conversations in RAM (not persistent, development only) |
Configuration Example
{
"SmartRAG": {
"ConversationStorageProvider": "Redis",
"RedisConfig": {
"ConnectionString": "localhost:6379"
}
}
}
Conversation Storage Tips
- Redis: Best for production, high-performance caching
- SQLite: Good for development and small deployments
- FileSystem: Simple, human-readable storage
- InMemory: Fast, but data lost on restart
Chunking Options
| Option | Type | Default | Description |
|---|---|---|---|
MaxChunkSize |
int |
1000 |
Maximum size of each document chunk in characters |
MinChunkSize |
int |
100 |
Minimum size of each document chunk in characters |
ChunkOverlap |
int |
200 |
Number of characters to overlap between adjacent chunks |
Chunking Best Practices
- MaxChunkSize: 500-1000 characters for optimal balance
- ChunkOverlap: 15-20% of MaxChunkSize for context preservation
- Larger chunks: Better context, but slower search
- Smaller chunks: More precise results, but less context
Feature Toggles
Control which search capabilities are enabled globally:
builder.Services.AddSmartRag(configuration, options =>
{
options.Features.EnableDatabaseSearch = true;
options.Features.EnableDocumentSearch = true;
options.Features.EnableAudioSearch = true;
options.Features.EnableImageSearch = true;
options.Features.EnableMcpSearch = false;
options.Features.EnableFileWatcher = false;
});
Feature Toggle Options
| Option | Type | Default | Description |
|---|---|---|---|
Features.EnableDatabaseSearch |
bool |
true |
Enable multi-database query capabilities (SQL Server, MySQL, PostgreSQL, SQLite) |
Features.EnableDocumentSearch |
bool |
true |
Enable document text search (PDF, Word, Excel, etc.) |
Features.EnableAudioSearch |
bool |
true |
Enable audio file transcription and search (MP3, WAV, etc.) |
Features.EnableImageSearch |
bool |
true |
Enable image OCR and search (PNG, JPG, etc.) |
Features.EnableMcpSearch |
bool |
false |
Enable MCP (Model Context Protocol) server integration for external tools |
Features.EnableFileWatcher |
bool |
false |
Enable automatic document indexing from watched folders |
Feature Toggle Tips
- Per-Request Control: Use
SearchOptionsfor per-request feature control - Global Control: Use
Featuresfor global feature enablement - Performance: Disable unused features to improve performance
- Resource Management: Disable audio/image search if not needed to save processing resources
DocumentType Property
The DocumentType property in DocumentChunk allows filtering chunks by content type:
- “Document”: Regular text documents (PDF, Word, Excel, TXT)
- “Audio”: Audio file transcriptions (MP3, WAV, M4A)
- “Image”: Image OCR results (PNG, JPG, etc.)
Automatic Detection
DocumentType is automatically determined based on file extension and content type:
// Uploaded files are automatically categorized
var document = await _documentService.UploadDocumentAsync(
fileStream,
"invoice.pdf", // → DocumentType: "Document"
"application/pdf",
"user-123"
);
var audio = await _documentService.UploadDocumentAsync(
audioStream,
"meeting.mp3", // → DocumentType: "Audio"
"audio/mpeg",
"user-123"
);
var image = await _documentService.UploadDocumentAsync(
imageStream,
"receipt.jpg", // → DocumentType: "Image"
"image/jpeg",
"user-123"
);
Filtering by DocumentType
Use SearchOptions to filter by document type:
// Search only in text documents
var options = new SearchOptions
{
EnableDocumentSearch = true,
EnableAudioSearch = false, // Exclude audio chunks
EnableImageSearch = false // Exclude image chunks
};
var response = await _searchService.QueryIntelligenceAsync(
"Find invoice details",
maxResults: 10,
options: options
);
Retry & Resilience Options
| Option | Type | Default | Description |
|---|---|---|---|
MaxRetryAttempts |
int |
3 |
Maximum number of retry attempts for AI provider requests |
RetryDelayMs |
int |
1000 |
Delay between retry attempts in milliseconds |
RetryPolicy |
RetryPolicy |
ExponentialBackoff |
Retry policy for failed requests |
EnableFallbackProviders |
bool |
false |
Enable fallback to alternative AI providers on failure |
FallbackProviders |
List<AIProvider> |
[] |
List of fallback AI providers to try sequentially |
RetryPolicy Enum Values:
RetryPolicy.None- No retriesRetryPolicy.FixedDelay- Fixed delay between retriesRetryPolicy.LinearBackoff- Linearly increasing delayRetryPolicy.ExponentialBackoff- Exponentially increasing delay (recommended)
Example Configurations
Development Environment
builder.Services.AddSmartRag(configuration, options =>
{
// For fast development
options.AIProvider = AIProvider.Gemini;
options.StorageProvider = StorageProvider.InMemory;
options.MaxChunkSize = 500;
options.ChunkOverlap = 100;
});
Production Environment
builder.Services.AddSmartRag(configuration, options =>
{
// For reliable production
options.AIProvider = AIProvider.OpenAI;
options.StorageProvider = StorageProvider.Qdrant;
options.MaxChunkSize = 1000;
options.ChunkOverlap = 200;
options.MaxRetryAttempts = 5;
options.RetryPolicy = RetryPolicy.ExponentialBackoff;
options.EnableFallbackProviders = true;
options.FallbackProviders = new List<AIProvider> { AIProvider.Anthropic };
});