Installation

SmartRAG is available as a NuGet package and supports .NET Standard 2.1, making it compatible with:

  • ✅ .NET Core 3.0+
  • ✅ .NET 5, 6, 7, 8, 9+

Installation Methods

dotnet add package SmartRAG
Install-Package SmartRAG
<PackageReference Include="SmartRAG" Version="3.3.0" />

Basic Configuration

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();

Configuration File

Create appsettings.json or appsettings.Development.json:

{
  "SmartRAG": {
    "AIProvider": "OpenAI",
    "StorageProvider": "InMemory",
    "MaxChunkSize": 1000,
    "MinChunkSize": 100,
    "ChunkOverlap": 200,
    "MaxRetryAttempts": 3,
    "RetryDelayMs": 1000,
    "RetryPolicy": "ExponentialBackoff",
    "EnableFallbackProviders": false
  },
  "AI": {
    "OpenAI": {
      "ApiKey": "sk-proj-YOUR_API_KEY",
      "Endpoint": "https://api.openai.com/v1",
      "Model": "gpt-5.1",
      "EmbeddingModel": "text-embedding-3-small",
      "MaxTokens": 4096,
      "Temperature": 0.7
    },
    "Anthropic": {
      "ApiKey": "sk-ant-YOUR_API_KEY",
      "Endpoint": "https://api.anthropic.com",
      "Model": "claude-sonnet-4-5",
      "MaxTokens": 4096,
      "Temperature": 0.3,
      "EmbeddingApiKey": "pa-YOUR_VOYAGE_KEY",
      "EmbeddingModel": "voyage-3.5"
    },
    "Gemini": {
      "ApiKey": "YOUR_GEMINI_KEY",
      "Endpoint": "https://generativelanguage.googleapis.com/v1beta",
      "Model": "gemini-2.5-pro",
      "EmbeddingModel": "embedding-001",
      "MaxTokens": 4096,
      "Temperature": 0.3
    },
    "AzureOpenAI": {
      "ApiKey": "your-azure-openai-api-key",
      "Endpoint": "https://your-resource.openai.azure.com/",
      "Model": "gpt-5.1",
      "EmbeddingModel": "text-embedding-3-small",
      "ApiVersion": "2024-10-21",
      "MaxTokens": 4096,
      "Temperature": 0.7
    },
    "Custom": {
      "ApiKey": "your-custom-api-key",
      "Endpoint": "https://api.yourprovider.com/v1/chat/completions",
      "Model": "your-model-name",
      "MaxTokens": 4096,
      "Temperature": 0.7
    }
  },
  "Storage": {
    "InMemory": {
      "MaxDocuments": 1000
    },
    "Qdrant": {
      "Host": "localhost:6334",
      "UseHttps": false,
      "ApiKey": "",
      "CollectionName": "smartrag_documents",
      "VectorSize": 1536,
      "DistanceMetric": "Cosine"
    },
    "Redis": {
      "ConnectionString": "localhost:6379",
      "Password": "",
      "Username": "",
      "Database": 0,
      "KeyPrefix": "smartrag:doc:",
      "ConnectionTimeout": 30,
      "EnableSsl": false
    }
  }
}

Security Warning

Never commit API keys to source control! Use appsettings.Development.json for local development (add to .gitignore). Use environment variables or Azure Key Vault for production.

Quick Usage Example

1. Upload Documents

public class DocumentController : ControllerBase
{
    private readonly IDocumentService _documentService;
    
    public DocumentController(IDocumentService documentService)
    {
        _documentService = documentService;
    }
    
    [HttpPost("upload")]
    public async Task<IActionResult> Upload(IFormFile file)
    {
        var document = await _documentService.UploadDocumentAsync(
            file.OpenReadStream(),
            file.FileName,
            file.ContentType,
            "user-123"
        );
        
        return Ok(new 
        { 
            id = document.Id,
            fileName = document.FileName,
            chunks = document.Chunks.Count,
            message = "Document processed successfully"
        });
    }
}

2. Ask Questions with AI

public class IntelligenceController : ControllerBase
{
    private readonly IDocumentSearchService _searchService;
    
    public IntelligenceController(IDocumentSearchService searchService)
    {
        _searchService = searchService;
    }
    
    [HttpPost("ask")]
    public async Task<IActionResult> Ask([FromBody] QuestionRequest request)
    {
        var response = await _searchService.QueryIntelligenceAsync(
            request.Question,
            maxResults: 5
        );
        
        return Ok(response);
    }
}

public class QuestionRequest
{
    public string Question { get; set; } = string.Empty;
}

3. Response Example

{
  "query": "What are the main benefits?",
  "answer": "Based on the contract document, the main benefits include: 1) 24/7 customer support, 2) 30-day money-back guarantee, 3) Free updates for lifetime...",
  "sources": [
    {
      "sourceType": "Document",
      "documentId": "00000000-0000-0000-0000-000000000000",
      "fileName": "contract.pdf",
      "relevantContent": "Our service includes 24/7 customer support...",
      "relevanceScore": 0.94,
      "location": null
    }
  ],
  "searchedAt": "2025-10-18T14:30:00Z",
  "configuration": {
    "aiProvider": "OpenAI",
    "storageProvider": "Redis",
    "model": "gpt-5.1"
  }
}

Conversation History

SmartRAG automatically manages conversation history:

// First question
var q1 = await _searchService.QueryIntelligenceAsync("What is machine learning?");

// Follow-up question - AI remembers previous context
var q2 = await _searchService.QueryIntelligenceAsync("Can you explain supervised learning?");

// Start new conversation
var newConv = await _searchService.QueryIntelligenceAsync(
    "New topic", 
    startNewConversation: true
);

Pro Tip

SmartRAG automatically manages session IDs and conversation context. No manual session handling required!

Next Steps

Configuration

Explore all configuration options, AI providers, storage backends, and advanced settings.

Configure SmartRAG

API Reference

Complete API documentation with all interfaces, methods, parameters, and examples.

View API Docs

Examples

Real-world examples including multi-database queries, OCR processing, and audio transcription.

See Examples

Changelog

Track new features, improvements, and breaking changes across all versions.

View Changelog

Need Help?

Support & Community

If you encounter issues or need assistance: