Crate rrag

Crate rrag 

Source
Expand description

Β§RRAG - Enterprise Rust RAG Framework

Crates.io Documentation License: MIT Downloads Rust

RRAG (Rust RAG) is a high-performance, enterprise-ready framework for building Retrieval-Augmented Generation applications in Rust. Built from the ground up with safety, performance, and developer experience in mind.

§🎯 Why RRAG?

  • πŸš€ Native Performance: Zero-cost abstractions with compile-time optimizations
  • πŸ›‘οΈ Memory Safety: Rust’s ownership system prevents data races and memory leaks
  • ⚑ Async First: Built on Tokio for maximum concurrency
  • 🎯 Type Safety: Compile-time guarantees eliminate runtime errors
  • πŸ”Œ Modular Design: Pluggable architecture with swappable components
  • πŸ“Š Production Ready: Built-in observability, security, and monitoring

Β§πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Documents     │───▢│   Processing    │───▢│   Vector Store  β”‚
β”‚   (Input)       β”‚    β”‚   Pipeline      β”‚    β”‚   (Storage)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Responses     │◀───│     Agent       │◀───│    Retriever    β”‚
β”‚   (Output)      β”‚    β”‚   (rsllm)       β”‚    β”‚   (Search)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

§⚑ Quick Start

Add RRAG to your Cargo.toml:

[dependencies]
rrag = { version = "0.1", features = ["rsllm-client"] }
tokio = { version = "1.0", features = ["full"] }

Β§Basic RAG Application

use rrag::prelude::*;

#[tokio::main]
async fn main() -> RragResult<()> {
    // Create a RAG system
    let rag = RragSystem::builder()
        .with_rsllm_client("http://localhost:8080")
        .with_vector_store(InMemoryStorage::new())
        .with_chunk_size(512)
        .build()
        .await?;
    
    // Add documents
    rag.ingest_documents(vec![
        Document::new("Rust is a systems programming language..."),
        Document::new("RAG combines retrieval with generation..."),
    ]).await?;
    
    // Query the system
    let response = rag.query("What is Rust?").await?;
    println!("Response: {}", response.text);
    
    Ok(())
}

§🌟 Core Features

Β§πŸ” Advanced Retrieval

  • Hybrid Search: Combines semantic and keyword search with multiple fusion strategies
  • Graph-Based Retrieval: Knowledge graph construction with entity extraction
  • Multi-Modal Support: Process text, images, tables, charts, and documents
  • Smart Reranking: Cross-encoder models for precise result ranking

§🧠 Intelligent Agents

  • Tool Integration: Built-in calculator, HTTP client, and custom tool support
  • Memory Management: Conversation buffers, token limits, and summarization
  • Streaming Responses: Real-time token streaming with async iterators

§⚑ Performance & Scalability

  • Intelligent Caching: Multi-level caching with semantic similarity
  • Incremental Indexing: Efficient document updates without full rebuilds
  • Batch Processing: High-throughput document ingestion

Β§πŸ“Š Production Features

  • Observability Dashboard: Real-time monitoring with web UI and metrics
  • Security & Rate Limiting: Authentication, authorization, and abuse prevention
  • Health Checks: Component monitoring and dependency tracking

Β§πŸ“– Documentation

Visit docs.rs/rrag for complete API documentation and examples.

Β§πŸ”§ Feature Flags

[dependencies.rrag]
version = "0.1"
features = [
    "rsllm-client",      # rsllm integration
    "http",              # HTTP tools and clients
    "concurrent",        # Concurrent data structures
    "multimodal",        # Multi-modal processing
    "observability",     # Monitoring and metrics
    "security",          # Authentication and rate limiting
]

Β§πŸ“„ License

This project is licensed under the MIT License.

§🀝 Contributing

Contributions welcome! Please see our contributing guidelines for details.

Β§RRAG - Enterprise-Grade Rust RAG Framework

Crates.io Documentation License: MIT Build Status

RRAG (Rust RAG) is a comprehensive, high-performance framework for building production-ready Retrieval-Augmented Generation (RAG) applications in Rust.

Designed for enterprise deployments requiring extreme performance, reliability, and observability, RRAG provides everything needed to build, deploy, and maintain sophisticated RAG systems at scale.

Β§πŸš€ Key Features

  • πŸ”₯ Native Performance: Zero-cost abstractions with compile-time optimizations
  • πŸ›‘οΈ Memory Safe: Leverage Rust’s ownership system for bulletproof memory management
  • ⚑ Async First: Built on Tokio for high-concurrency workloads
  • 🎯 Type Safe: Compile-time guarantees prevent runtime errors
  • πŸ”Œ Pluggable: Modular architecture with swappable components
  • 🌊 Streaming: Real-time token streaming with async iterators
  • πŸ“Š Observable: Built-in metrics, tracing, and health checks

Β§πŸ—οΈ Architecture Overview

RRAG follows a modular, pipeline-based architecture that maximizes performance while maintaining flexibility:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Documents     │───▢│   Processing    │───▢│   Vector Store  β”‚
β”‚   (Input)       β”‚    β”‚   Pipeline      β”‚    β”‚   (Storage)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Responses     │◀───│     Agent       │◀───│    Retriever    β”‚
β”‚   (Output)      β”‚    β”‚   (rsllm)       β”‚    β”‚   (Search)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Β§πŸš€ Quick Start

Β§Basic RAG System

use rrag::prelude::*;

#[tokio::main]
async fn main() -> RragResult<()> {
    // Create a RAG system
    let rag = RragSystemBuilder::new()
        .with_name("My RAG System")
        .with_environment("development")
        .build()
        .await?;
     
    // Add documents
    let doc = Document::new("Rust is a systems programming language...")
        .with_metadata("source", "documentation".into())
        .with_content_hash();
     
    rag.process_document(doc).await?;
     
    // Search for relevant content
    let results = rag.search("What is Rust?".to_string(), Some(5)).await?;
    println!("Found {} results", results.total_results);
     
    Ok(())
}

Β§Advanced Agent with Tools

use rrag::prelude::*;

#[tokio::main]
async fn main() -> RragResult<()> {
    // Create an agent with tools
    let mut agent = AgentBuilder::new()
        .with_model("gpt-4")
        .with_temperature(0.7)
        .with_streaming(true)
        .build()
        .await?;
     
    // Register tools
    agent.register_tool(Calculator::new())?;
    agent.register_tool(HttpTool::new())?;
     
    // Chat with memory
    let memory = ConversationBufferMemory::new(100);
    let response = agent.chat_with_memory(
        "Calculate 15 * 23",
        &memory
    ).await?;
     
    println!("Agent: {}", response.text);
     
    Ok(())
}

Β§πŸ“¦ Feature Flags

RRAG supports multiple feature flags for flexible deployments:

  • default: Core functionality with HTTP and concurrency support
  • rsllm-client: Integration with rsllm for LLM operations
  • http: HTTP client support for external services
  • concurrent: Advanced concurrency features with DashMap
  • observability: Metrics, monitoring, and alerting
  • security: Authentication, authorization, and security features
  • security-full: Complete security suite with 2FA and WebAuthn
[dependencies]
rrag = { version = "0.1", features = ["rsllm-client", "observability", "security"] }

Β§πŸ—οΈ Module Organization

RRAG is organized into focused modules, each handling specific aspects of RAG functionality:

Β§Core Modules

  • error: Comprehensive error handling with structured error types
  • document: Document processing, chunking, and metadata management
  • embeddings: Multi-provider embedding generation and management
  • storage: Pluggable storage backends for documents and vectors
  • memory: Conversation memory and context management
  • agent: LLM agents with tool calling and streaming support
  • pipeline: Composable processing pipelines
  • system: High-level system orchestration and lifecycle management

Β§Advanced Modules

  • retrieval_core: Core retrieval interfaces and implementations
  • retrieval_enhanced: Advanced hybrid retrieval with BM25 and semantic search
  • reranking: Result reranking and relevance scoring
  • evaluation: Framework for evaluating RAG system performance
  • caching: Intelligent caching strategies for performance optimization
  • graph_retrieval: Knowledge graph-based retrieval and reasoning
  • incremental: Incremental indexing for large-scale document updates
  • observability: Comprehensive monitoring, metrics, and alerting
  • tools: Built-in and extensible tool implementations
  • streaming: Real-time streaming response handling
  • query: Query processing and optimization
  • multimodal: Multi-modal content processing support

Re-exportsΒ§

pub use agent::AgentBuilder;
pub use agent::AgentConfig;
pub use agent::AgentResponse;
pub use agent::ModelConfig;
pub use agent::RragAgent;
pub use agent::ToolCall;
pub use document::ChunkingStrategy;
pub use document::Document;
pub use document::DocumentChunk;
pub use document::DocumentChunker;
pub use document::Metadata;
pub use embeddings::Embedding;
pub use embeddings::EmbeddingBatch;
pub use embeddings::EmbeddingProvider;
pub use embeddings::EmbeddingRequest;
pub use embeddings::EmbeddingService;
pub use embeddings::LocalEmbeddingProvider;
pub use embeddings::MockEmbeddingService;
pub use embeddings::OpenAIEmbeddingProvider;
pub use error::ErrorSeverity;
pub use error::RragError;
pub use error::RragResult;
pub use memory::ConversationBufferMemory;
pub use memory::ConversationMessage;
pub use memory::ConversationSummaryMemory;
pub use memory::ConversationTokenBufferMemory;
pub use memory::Memory;
pub use memory::MemoryService;
pub use memory::MessageRole;
pub use pipeline::DocumentChunkingStep;
pub use pipeline::EmbeddingStep;
pub use pipeline::Pipeline;
pub use pipeline::PipelineConfig;
pub use pipeline::PipelineContext;
pub use pipeline::PipelineData;
pub use pipeline::PipelineStep;
pub use pipeline::RagPipelineBuilder;
pub use pipeline::RetrievalStep;
pub use pipeline::TextOperation;
pub use pipeline::TextPreprocessingStep;
pub use retrieval_core::InMemoryRetriever;
pub use retrieval_core::RetrievalService;
pub use retrieval_core::Retriever;
pub use retrieval_core::SearchAlgorithm;
pub use retrieval_core::SearchConfig;
pub use retrieval_core::SearchQuery;
pub use retrieval_core::SearchResult;
pub use retrieval_enhanced::BM25Config;
pub use retrieval_enhanced::BM25Retriever;
pub use retrieval_enhanced::FusionStrategy;
pub use retrieval_enhanced::HybridConfig;
pub use retrieval_enhanced::HybridRetriever;
pub use retrieval_enhanced::RankFusion;
pub use retrieval_enhanced::ReciprocalRankFusion;
pub use retrieval_enhanced::SemanticConfig;
pub use retrieval_enhanced::SemanticRetriever;
pub use retrieval_enhanced::TokenizerType;
pub use retrieval_enhanced::WeightedFusion;
pub use storage::FileStorage;
pub use storage::InMemoryStorage;
pub use storage::Storage;
pub use storage::StorageEntry;
pub use storage::StorageKey;
pub use storage::StorageQuery;
pub use storage::StorageService;
pub use streaming::StreamToken;
pub use streaming::StreamingResponse;
pub use streaming::TokenStreamBuilder;
pub use streaming::TokenType;
pub use system::ChatResponse;
pub use system::HealthCheckResult;
pub use system::ProcessingResult;
pub use system::RragSystem;
pub use system::RragSystemBuilder;
pub use system::RragSystemConfig;
pub use system::SearchResponse;
pub use system::SystemMetrics;
pub use tools::HttpTool;http
pub use tools::Calculator;
pub use tools::EchoTool;
pub use tools::Tool;
pub use tools::ToolRegistry;
pub use tools::ToolResult;
pub use graph_retrieval::EdgeType;
pub use graph_retrieval::Entity;
pub use graph_retrieval::EntityExtractor;
pub use graph_retrieval::EntityType;
pub use graph_retrieval::ExpansionResult;
pub use graph_retrieval::ExpansionStrategy;
pub use graph_retrieval::GraphAlgorithms;
pub use graph_retrieval::GraphBuildConfig;
pub use graph_retrieval::GraphConfig;
pub use graph_retrieval::GraphConfigBuilder;
pub use graph_retrieval::GraphEdge;
pub use graph_retrieval::GraphIndex;
pub use graph_retrieval::GraphMetrics;
pub use graph_retrieval::GraphNode;
pub use graph_retrieval::GraphQuery;
pub use graph_retrieval::GraphQueryResult;
pub use graph_retrieval::GraphRetrievalBuilder;
pub use graph_retrieval::GraphRetrievalConfig;
pub use graph_retrieval::GraphRetriever;
pub use graph_retrieval::GraphStorage;
pub use graph_retrieval::KnowledgeGraph;
pub use graph_retrieval::NodeType;
pub use graph_retrieval::PageRankConfig;
pub use graph_retrieval::PathFindingConfig;
pub use graph_retrieval::QueryExpander;
pub use graph_retrieval::RelationType;
pub use graph_retrieval::Relationship;
pub use graph_retrieval::TraversalConfig;
pub use incremental::AlertConfig;
pub use incremental::BatchConfig;
pub use incremental::BatchExecutor;
pub use incremental::BatchOperation;
pub use incremental::BatchProcessingStats;
pub use incremental::BatchProcessor;
pub use incremental::BatchResult;
pub use incremental::ChangeDetectionConfig;
pub use incremental::ChangeDetector;
pub use incremental::ChangeResult;
pub use incremental::ChangeType;
pub use incremental::ConflictResolution;
pub use incremental::ConsistencyReport;
pub use incremental::ContentDelta;
pub use incremental::DocumentChange;
pub use incremental::DocumentVersion;
pub use incremental::EmbeddingUpdate;
pub use incremental::HealthMetrics;
pub use incremental::IncrementalIndexManager;
pub use incremental::IncrementalIndexingService;
pub use incremental::IncrementalMetrics;
pub use incremental::IncrementalServiceBuilder;
pub use incremental::IncrementalServiceConfig;
pub use incremental::IndexManagerConfig;
pub use incremental::IndexOperation;
pub use incremental::IndexUpdate;
pub use incremental::IndexUpdateStrategy;
pub use incremental::IndexingStats;
pub use incremental::IntegrityChecker;
pub use incremental::IntegrityConfig;
pub use incremental::IntegrityError;
pub use incremental::MetricsCollector;
pub use incremental::MonitoringConfig;
pub use incremental::OperationLog;
pub use incremental::PerformanceTracker;
pub use incremental::QueueManager;
pub use incremental::RecoveryResult;
pub use incremental::RollbackConfig;
pub use incremental::RollbackManager;
pub use incremental::RollbackOperation;
pub use incremental::RollbackPoint;
pub use incremental::UpdateResult;
pub use incremental::ValidationResult;
pub use incremental::VectorBatch;
pub use incremental::VectorOperation;
pub use incremental::VectorUpdateConfig;
pub use incremental::VectorUpdateManager;
pub use incremental::VersionConflict;
pub use incremental::VersionHistory;
pub use incremental::VersionManager;
pub use incremental::VersionResolution;
pub use incremental::VersioningConfig;
pub use observability::AlertCondition;
pub use observability::AlertManager;
pub use observability::AlertNotification;
pub use observability::AlertRule;
pub use observability::AlertSeverity;
pub use observability::BottleneckAnalysis;
pub use observability::ComponentStatus;
pub use observability::DashboardConfig;
pub use observability::DashboardServer;
pub use observability::DataRetention;
pub use observability::ExportFormat;
pub use observability::ExportManager;
pub use observability::HealthChecker;
pub use observability::HealthReport;
pub use observability::HistoricalAnalyzer;
pub use observability::LogAggregator;
pub use observability::LogEntry;
pub use observability::LogFilter;
pub use observability::LogLevel;
pub use observability::LogQuery;
pub use observability::Metric;
pub use observability::MetricType;
pub use observability::MetricValue;
pub use observability::MetricsCollector as ObsMetricsCollector;
pub use observability::MetricsExporter;
pub use observability::MetricsRegistry;
pub use observability::ObservabilityBuilder;
pub use observability::ObservabilityConfig;
pub use observability::ObservabilitySystem;
pub use observability::PerformanceMonitor;
pub use observability::PerformanceReport;
pub use observability::ProfileData;
pub use observability::Profiler;
pub use observability::RealtimeMetrics;
pub use observability::ReportGenerator;
pub use observability::RetentionPolicy;
pub use observability::SearchAnalyzer;
pub use observability::SystemMonitor;
pub use observability::UserActivityTracker;
pub use observability::WebSocketManager;
pub use rsllm;rsllm-client

ModulesΒ§

agent
RRAG Agent System
caching
Intelligent Caching Layer
document
RRAG Document Types
embeddings
RRAG Embeddings System
error
RRAG Error Types
evaluation
RRAG Evaluation Framework
graph_retrieval
Graph-Based Retrieval Module
incremental
Incremental Indexing System for RRAG
memory
RRAG Memory System
multimodal
Multi-Modal RAG Processing
observability
RRAG Observability System
pipeline
RRAG Pipeline System
prelude
Prelude module for convenient imports
query
Query Processing Module
reranking
Advanced Reranking Module
retrieval_core
RRAG Retrieval System
retrieval_enhanced
Enhanced Retrieval Module
storage
RRAG Storage System
streaming
RRAG Streaming System
system
RRAG System Integration
tools
RRAG Tools System

MacrosΒ§

rrag_tool
Macro for creating simple tools with less boilerplate

ConstantsΒ§

DESCRIPTION
Framework description
LICENSE
Framework license
MSRV
Minimum supported Rust version (MSRV)
NAME
Framework name identifier
REPOSITORY
Framework repository URL
VERSION
Framework constants and metadata