Không có mô tả

alair 4cd7a66317 提交 3 tháng trước cách đây
.github 4cd7a66317 提交 3 tháng trước cách đây
.kiro 4cd7a66317 提交 3 tháng trước cách đây
alembic 4cd7a66317 提交 3 tháng trước cách đây
doc 6c1c098a0f 19维度图书解析流程调整-新增滑动窗口模式 3 tháng trước cách đây
docker 4cd7a66317 提交 3 tháng trước cách đây
docs 4cd7a66317 提交 3 tháng trước cách đây
examples 4cd7a66317 提交 3 tháng trước cách đây
scripts 4cd7a66317 提交 3 tháng trước cách đây
src 4cd7a66317 提交 3 tháng trước cách đây
tests 4cd7a66317 提交 3 tháng trước cách đây
.coveragerc 4cd7a66317 提交 3 tháng trước cách đây
.gitignore 5ef1502c14 初始化项目,首次提交 3 tháng trước cách đây
CHECKPOINT_1_VERIFICATION.md 4cd7a66317 提交 3 tháng trước cách đây
CI_CD_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
DEPLOYMENT_CHECKLIST.md 4cd7a66317 提交 3 tháng trước cách đây
FINAL_PROJECT_STATUS.md 4cd7a66317 提交 3 tháng trước cách đây
LOGGING_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
PERFORMANCE_BENCHMARK_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
PROJECT_COMPLETION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
README.md 4cd7a66317 提交 3 tháng trước cách đây
REFACTORING_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
TASK_3.10_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
TASK_3.11_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
TASK_3.8_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
TASK_5.10_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
TASK_5.1_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
TASK_5.2_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
TASK_5.3_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
TASK_5.4_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
TASK_5.8_IMPLEMENTATION_SUMMARY.md 4cd7a66317 提交 3 tháng trước cách đây
alembic.ini 4cd7a66317 提交 3 tháng trước cách đây
benchmark_results_simulated.json 4cd7a66317 提交 3 tháng trước cách đây
codecov.yml 4cd7a66317 提交 3 tháng trước cách đây
coverage.json 4cd7a66317 提交 3 tháng trước cách đây
main.py 18abbc31ea 19维度拆解 3 tháng trước cách đây
pytest.ini 4cd7a66317 提交 3 tháng trước cách đây
requirements.txt 4cd7a66317 提交 3 tháng trước cách đây
requirements.txt.bak.1 d8499a205e 多维度流程增加书、页拆分 3 tháng trước cách đây
test_logging_manual.py 4cd7a66317 提交 3 tháng trước cách đây
test_qa_workflow.py 1146474adc 多维度流程拆分 3 tháng trước cách đây
verification_report.txt 4cd7a66317 提交 3 tháng trước cách đây

README.md

RAG System

A production-ready Retrieval-Augmented Generation (RAG) system built with FastAPI, featuring clean architecture, comprehensive testing, and CI/CD integration.

🚀 Features

  • Clean Architecture: Domain-driven design with clear separation of concerns
  • Multiple Vector Databases: Support for Infinity and Elasticsearch
  • Document Processing: PDF, image, and text document parsing
  • Hybrid Search: Combined vector and full-text search capabilities
  • Knowledge Base Management: Organize documents into knowledge bases
  • Comprehensive Testing: Unit, integration, and end-to-end tests
  • CI/CD Pipeline: Automated testing and deployment with GitHub Actions
  • High Test Coverage: Maintained at 80%+ coverage
  • Structured Logging: JSON-formatted logs with request tracking
  • Type Safety: Full type hints and mypy validation

📋 Table of Contents

🏃 Quick Start

# Clone the repository
git clone https://github.com/YOUR_USERNAME/rag-system.git
cd rag-system

# Install dependencies
pip install -r requirements.txt

# Set up environment variables
cp .env.example .env
# Edit .env with your configuration

# Run tests
pytest

# Start the application
python main.py

📦 Installation

Prerequisites

  • Python 3.11 or 3.12
  • pip (Python package manager)
  • Git

Development Setup

  1. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Install development dependencies:

    pip install pytest pytest-asyncio pytest-cov hypothesis httpx
    pip install flake8 black isort mypy  # For linting
    pip install safety bandit  # For security scanning
    
  4. Set up pre-commit hooks (optional):

    pip install pre-commit
    pre-commit install
    

⚙️ Configuration

Configuration is managed through environment variables and the .env file.

Environment Variables

Copy .env.example to .env and configure:

# Application
APP_NAME=RAG System
DEBUG=false

# Database
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=rag_system
DB_USERNAME=your_username
DB_PASSWORD=your_password

# Vector Database (infinity or elasticsearch)
VECTOR_DB_TYPE=infinity

# Infinity Configuration
INFINITY_HOST=localhost
INFINITY_PORT=23817

# Elasticsearch Configuration
ES_HOST=localhost
ES_PORT=9200

See Configuration Guide for detailed configuration options.

🧪 Running Tests

Quick Test Commands

# Run all tests
pytest

# Run with coverage
pytest --cov=src --cov-report=html

# Run specific test types
pytest -m unit          # Unit tests only
pytest -m integration   # Integration tests only
pytest -m e2e          # End-to-end tests only

# Run fast tests only
pytest -m "not slow"

Using the Test Runner Script

# Run all tests with CI configuration
python scripts/run_tests.py

# Run with coverage report
python scripts/run_tests.py --coverage --html

# Run all checks (tests + lint + security)
python scripts/run_tests.py --all

# Run in parallel
python scripts/run_tests.py --parallel

Performance Testing

# Run simulated performance test (quick)
python scripts/benchmark_simple.py

# Run real performance test (requires running server)
python main.py  # In one terminal
python scripts/benchmark.py  # In another terminal

See Performance Guide for detailed performance testing documentation.

Test Organization

Tests are organized by type:

  • tests/unit/: Fast, isolated unit tests
  • tests/integration/: Component interaction tests
  • tests/e2e/: Complete workflow tests

See Testing Guide for detailed testing documentation.

🔄 CI/CD Pipeline

The project uses GitHub Actions for continuous integration and deployment.

Pipeline Jobs

  1. Test: Runs all tests with coverage measurement
  2. Lint: Code quality checks (flake8, black, isort, mypy)
  3. Security: Security scans (safety, bandit)
  4. Build Status: Aggregates results

Coverage Reporting

Coverage reports are automatically uploaded to Codecov on every push.

codecov

Setting Up CI/CD

  1. Enable GitHub Actions: Already configured in .github/workflows/test.yml

  2. Set up Codecov:

    • Sign up at codecov.io
    • Add your repository
    • Add CODECOV_TOKEN to GitHub Secrets

See CI/CD Guide for detailed pipeline documentation.

🏗️ Architecture

The system follows a clean, layered architecture:

┌─────────────────────────────────────┐
│      Presentation Layer             │  FastAPI routes, middleware
├─────────────────────────────────────┤
│      Application Layer              │  Use cases, handlers, DTOs
├─────────────────────────────────────┤
│      Domain Layer                   │  Entities, value objects, services
├─────────────────────────────────────┤
│      Infrastructure Layer           │  Databases, external services
└─────────────────────────────────────┘

Directory Structure

rag_system/
├── src/
│   ├── domain/              # Domain layer (business logic)
│   ├── application/         # Application layer (use cases)
│   ├── infrastructure/      # Infrastructure layer (databases, APIs)
│   ├── presentation/        # Presentation layer (API routes)
│   ├── config/             # Configuration management
│   └── shared/             # Shared utilities
├── tests/
│   ├── unit/               # Unit tests
│   ├── integration/        # Integration tests
│   └── e2e/               # End-to-end tests
├── docs/                   # Documentation
├── scripts/               # Utility scripts
└── docker/                # Docker configuration

See Architecture Documentation for detailed design information.

📚 Documentation

🤝 Contributing

We welcome contributions! Please follow these guidelines:

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Write tests: Ensure your code is well-tested
  4. Run tests: python scripts/run_tests.py --all
  5. Commit changes: Use clear, descriptive commit messages
  6. Push to your fork: git push origin feature/your-feature
  7. Create a Pull Request

Code Standards

  • Style: Follow PEP 8 (enforced by flake8 and black)
  • Type Hints: Use type hints for all functions
  • Documentation: Add docstrings to all public APIs
  • Testing: Maintain 80%+ test coverage
  • Commits: Use conventional commit messages

Running Quality Checks

# Format code
black src tests
isort src tests

# Lint code
flake8 src tests

# Type check
mypy src

# Run all checks
python scripts/run_tests.py --all

📊 Test Coverage

Current coverage by layer:

Layer Target Current
Domain Layer 90% TBD
Application Layer 85% TBD
Infrastructure Layer 70% TBD
Presentation Layer 75% TBD
Overall 80% TBD

🔒 Security

  • Dependency Scanning: Automated with safety
  • Code Scanning: Automated with bandit
  • Security Reports: Available in CI/CD artifacts

Report security vulnerabilities to: security@example.com

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • FastAPI for the excellent web framework
  • pytest for the comprehensive testing framework
  • Codecov for coverage reporting
  • GitHub Actions for CI/CD automation

📞 Support

🗺️ Roadmap

  • Phase 1: Infrastructure setup
  • Phase 2: Domain layer refactoring
  • Phase 3: Application layer refactoring
  • Phase 4: Infrastructure layer migration
  • Phase 5: Presentation layer migration
  • Phase 6: Documentation and cleanup

See Implementation Plan for detailed roadmap.


Built with ❤️ using Clean Architecture principles