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:
using SmartRAG.Extensions;
using SmartRAG.Enums;
var builder = WebApplication.CreateBuilder(args);
// Simple one-line configuration
builder.Services.UseSmartRag(builder.Configuration,
storageProvider: StorageProvider.InMemory, // Start with in-memory
aiProvider: AIProvider.Gemini // Choose your AI provider
);
var app = builder.Build();
app.Run();
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
};
});
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 |
EnablePeriodicSchemaRefresh |
bool |
true |
Periodically refresh database schemas |
DefaultSchemaRefreshIntervalMinutes |
int |
60 |
Default interval in minutes for schema refresh |
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
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 };
});