Quick Examples

Get started with SmartRAG in minutes.

Basic Usage

// 1. Upload document
var document = await _documentService.UploadDocumentAsync(file);

// 2. Search documents
var results = await _searchService.SearchDocumentsAsync(query, 10);

// 3. Generate RAG answer with conversation history
var response = await _searchService.GenerateRagAnswerAsync(question);

Controller Example

[ApiController]
[Route("api/[controller]")]
public class SearchController : ControllerBase
{
    private readonly IDocumentSearchService _searchService;
    
    [HttpPost("search")]
    public async Task Search([FromBody] SearchRequest request)
    {
        var response = await _searchService.GenerateRagAnswerAsync(
            request.Query, request.MaxResults);
        return Ok(response);
    }
}

public class SearchRequest
{
    public string Query { get; set; } = string.Empty;
    public int MaxResults { get; set; } = 5;
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        
        

Advanced Usage

Advanced examples for production use.

Batch Processing

// Upload multiple documents
var documents = await _documentService.UploadDocumentsAsync(files);

// Get storage statistics
var stats = await _documentService.GetStorageStatisticsAsync();

// Manage documents
var allDocs = await _documentService.GetAllDocumentsAsync();
await _documentService.DeleteDocumentAsync(documentId);

Maintenance Operations

// Regenerate embeddings
await _documentService.RegenerateAllEmbeddingsAsync();

// Clear data
await _documentService.ClearAllEmbeddingsAsync();
await _documentService.ClearAllDocumentsAsync();

Configuration

Configure SmartRAG for your needs.

Service Registration

// Program.cs
services.AddSmartRag(configuration, options =>
{
    options.AIProvider = AIProvider.Anthropic;
    options.StorageProvider = StorageProvider.Redis;
    options.MaxChunkSize = 1000;
    options.ChunkOverlap = 200;
});
</div> </div>