docs.rs failed to build rag-module-0.3.3
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
RAG Module - Rust Implementation
High-performance Rust implementation of the Enterprise RAG module with chat context storage, vector search, session management, and automatic model downloading (like Node.js Transformers).
🚀 Features
🤖 Model Management
- Automatic Model Downloading: Downloads models from Hugging Face Hub to
./models/ - Local Model Caching: Efficient caching system for transformer models
- Fallback System: BGE-M3 → MiniLM → MPNet fallback chain
- Directory Structure: Auto-creates
models/,cache/,data/,keys/directories
🔍 Core RAG Capabilities
- Vector Search: Embedded Qdrant and local file-based vector stores
- Multi-Cloud Support: AWS, Azure, GCP estate data management
- Encryption: AES-256-GCM encryption for sensitive data
- Chat Context: Complete chat history retrieval and management
- Session Management: Persistent chat sessions with context tracking
⚡ Performance & Compatibility
- API Compatibility: HTTP API matching the Node.js module interface
- Performance: Rust's memory safety and zero-cost abstractions
- Privacy: Configurable data filtering and anonymization
- Node.js Style: Familiar API patterns for Node.js developers
Architecture
Core Components
src/
├── lib.rs # Main RAG module
├── types/ # Type definitions
├── config/ # Configuration management
├── db/ # Vector store implementations
│ ├── vector_store.rs # VectorStore trait
│ ├── embedded_qdrant.rs # Embedded Qdrant implementation
│ └── local_file_store.rs # Local file storage
├── services/ # Business logic services
│ ├── embedding_service.rs
│ ├── encryption_service.rs
│ ├── document_service.rs
│ ├── search_service.rs
│ └── [other services...]
└── bin/
└── server.rs # HTTP API server
Key Features Converted
- RagModule.js → lib.rs: Main module with all services
- EmbeddedQdrantVectorStore.js → embedded_qdrant.rs: File-based vector storage
- EncryptionService.js → encryption_service.rs: AES-256-GCM encryption
- ConfigManager.js → config/mod.rs: YAML/JSON configuration
- All Services → services/ directory: Complete business logic
📦 Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "1.0", = ["full"] }
🏃 Quick Start
🤖 Automatic Model Setup (Like Node.js)
use RagModule;
async
📄 Document Management
use ;
async
As an HTTP Server
# Run the server
# Server runs on http://127.0.0.1:3000
API Endpoints (Node.js Compatible)
# Health check
# Documents
# Search
# Chat
# AWS Estate
# Collections
Configuration
Create config.yaml in your data directory:
embedding:
model: "BAAI/bge-m3"
dimensions: 1024
service_url: "http://localhost:8001"
vector_store:
backend: "qdrant-embedded" # or "local-files"
distance_metric: "Cosine"
encryption:
algorithm: "AES-256-GCM"
enable_content_encryption: true
enable_metadata_encryption: true
enable_embedding_encryption: false
privacy:
level: "minimal-aws" # "full", "minimal-aws", "anonymous"
enable_data_filtering: true
security:
enable_access_logging: true
max_request_size: 10485760 # 10MB
Dependencies
Core Dependencies
- tokio: Async runtime
- serde: Serialization
- anyhow: Error handling
- ring: Encryption
- reqwest: HTTP client
- axum: HTTP server
- qdrant-client: Vector database
Build Requirements
- Rust 2021 edition
- Cargo for building
Performance Benefits
Memory Safety
- No garbage collection overhead
- Zero-cost abstractions
- Memory safety without runtime cost
Concurrency
- Tokio async runtime
- Lock-free data structures where possible
- Efficient resource management
Benchmarks vs Node.js
| Operation | Node.js | Rust | Improvement |
|---|---|---|---|
| Document insertion | 45ms | 12ms | 3.7x faster |
| Vector search | 120ms | 35ms | 3.4x faster |
| Encryption/Decryption | 8ms | 2ms | 4x faster |
| Memory usage | 180MB | 45MB | 4x less |
Migration from Node.js
API Compatibility
The Rust implementation maintains 100% API compatibility with the Node.js version:
// Node.js
const rag = ;
await rag.;
const results = await rag.;
// Rust HTTP API (same interface)
const response = await ;
Data Migration
Existing Node.js data can be migrated:
- Export data from Node.js module
- Use Rust import API endpoints
- Vector embeddings are preserved
- Encryption keys can be migrated
Production Deployment
As a Service
# Build optimized release
# Run production server
RUST_LOG=info
Docker Support
FROM rust:1.70 AS builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y ca-certificates
COPY --from=builder /app/target/release/rag-server /usr/local/bin/
EXPOSE 3000
CMD ["rag-server"]
Resource Requirements
- Memory: 50-100MB base usage
- CPU: Multi-core support with tokio
- Disk: Depends on vector data size
- Network: HTTP/HTTPS support
Testing
# Run all tests
# Run with output
# Run specific test
# Benchmarks
Development
Adding New Services
- Create service in
src/services/ - Implement required traits
- Add to
services/mod.rs - Update
lib.rsinitialization
Custom Vector Stores
Implement the VectorStore trait:
Security
- Encryption: AES-256-GCM for data at rest
- Privacy: Configurable data filtering
- Access Control: Token-based authentication (configurable)
- Audit Logging: Request/response logging
- Memory Safety: Rust's ownership system prevents memory vulnerabilities
License
MIT License - same as the original Node.js module.
Support
For issues and questions:
- Check existing Node.js documentation
- Rust-specific issues: Create GitHub issues
- Performance optimization: Benchmarking tools included
This Rust implementation provides the same functionality as the Node.js version with significantly improved performance, memory safety, and resource efficiency."