Basic Configuration

SmartRAG can be configured with various options to suit your needs:

services.AddSmartRag(configuration, options =>
{
    options.AIProvider = AIProvider.Anthropic;
    options.StorageProvider = StorageProvider.Qdrant;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

Configuration Options

Option Type Default Description
AIProvider AIProvider OpenAI The AI provider to use for embeddings
StorageProvider StorageProvider InMemory The storage provider for vectors
MaxChunkSize int 1000 Maximum size of document chunks
MinChunkSize int 100 Minimum size of document chunks
ChunkOverlap int 200 Overlap between chunks
MaxRetryAttempts int 3 Maximum retry attempts
RetryDelayMs int 1000 Delay between retry attempts (ms)
RetryPolicy RetryPolicy ExponentialBackoff Retry policy for failed requests
EnableFallbackProviders bool false Enable fallback providers
FallbackProviders AIProvider[] [] List of fallback AI providers

AI Provider Configuration

Choose from multiple AI providers for embedding generation:

services.AddSmartRag(configuration, options =>
{
    options.AIProvider = AIProvider.Anthropic;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

// appsettings.json
{
  "Anthropic": {
    "ApiKey": "your-anthropic-key",
    "Model": "claude-3-sonnet-20240229"
  }
}
services.AddSmartRag(configuration, options =>
{
    options.AIProvider = AIProvider.OpenAI;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

// appsettings.json
{
  "OpenAI": {
    "ApiKey": "your-openai-key",
    "Model": "gpt-4",
    "EmbeddingModel": "text-embedding-ada-002"
  }
}
services.AddSmartRag(configuration, options =>
{
    options.AIProvider = AIProvider.AzureOpenAI;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

// appsettings.json
{
  "AzureOpenAI": {
    "ApiKey": "your-azure-key",
    "Endpoint": "https://your-resource.openai.azure.com/",
    "Model": "gpt-4",
    "EmbeddingModel": "text-embedding-ada-002"
  }
}
services.AddSmartRag(configuration, options =>
{
    options.AIProvider = AIProvider.Gemini;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

// appsettings.json
{
  "Gemini": {
    "ApiKey": "your-gemini-key",
    "Model": "gemini-pro",
    "EmbeddingModel": "embedding-001"
  }
}
services.AddSmartRag(configuration, options =>
{
    options.AIProvider = AIProvider.Custom;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

// appsettings.json
{
  "Custom": {
    "ApiKey": "your-custom-key",
    "Endpoint": "https://your-custom-api.com/v1",
    "Model": "your-custom-model"
  }
}

Storage Provider Configuration

Choose the storage backend that best fits your needs:

services.AddSmartRag(configuration, options =>
{
    options.StorageProvider = StorageProvider.Qdrant;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

// appsettings.json
{
  "Storage": {
    "Qdrant": {
      "Host": "localhost",
      "ApiKey": "your-qdrant-key",
      "CollectionName": "smartrag_documents",
      "VectorSize": 768
    }
  }
}
services.AddSmartRag(configuration, options =>
{
    options.StorageProvider = StorageProvider.Redis;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

// appsettings.json
{
  "Storage": {
    "Redis": {
      "ConnectionString": "localhost:6379",
      "Database": 0,
      "KeyPrefix": "smartrag:doc:"
    }
  }
}
services.AddSmartRag(configuration, options =>
{
    options.StorageProvider = StorageProvider.Sqlite;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

// appsettings.json
{
  "Storage": {
    "Sqlite": {
      "DatabasePath": "SmartRag.db",
      "EnableForeignKeys": true
    }
  }
}
services.AddSmartRag(configuration, options =>
{
    options.StorageProvider = StorageProvider.InMemory;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});
// No additional configuration needed
services.AddSmartRag(configuration, options =>
{
    options.StorageProvider = StorageProvider.FileSystem;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});

// appsettings.json
{
  "Storage": {
    "FileSystem": {
      "FileSystemPath": "./smartrag_storage"
    }
  }
}

Advanced Configuration

Fine-tune SmartRAG for your specific requirements:

Custom Chunking

services.AddSmartRag(configuration, options =>
{
    options.MaxChunkSize = 500;
    options.MinChunkSize = 50;
    options.ChunkOverlap = 100;
});

Retry Configuration

services.AddSmartRag(configuration, options =>
{
    options.MaxRetryAttempts = 3;
    options.RetryDelayMs = 1000;
    options.RetryPolicy = RetryPolicy.ExponentialBackoff;
    options.EnableFallbackProviders = true;
    options.FallbackProviders = new[] { AIProvider.Gemini, AIProvider.OpenAI };
});

Environment Configuration

Configure SmartRAG using environment variables or configuration files:

appsettings.json

{
  "Anthropic": {
    "ApiKey": "your-anthropic-key",
    "Model": "claude-3-sonnet-20240229"
  },
  "Storage": {
    "Qdrant": {
      "Host": "localhost",
      "ApiKey": "your-qdrant-key",
      "CollectionName": "smartrag_documents"
    }
  }
}

Environment Variables

export ANTHROPIC_API_KEY=your-anthropic-key
export QDRANT_API_KEY=your-qdrant-key

Best Practices

API Keys

Never hardcode API keys in source code. Use environment variables or secure configuration.

Chunk Size

Balance between context and performance. Smaller chunks for precision, larger for context.

Storage

Choose storage provider based on your scale and requirements.

Security

Use appropriate access controls and monitoring for production environments.