# netease-youdao/qanything architecture

> Architecture diagram of the GitHub repository netease-youdao/qanything, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/netease-youdao/qanything
- Repository: https://github.com/netease-youdao/qanything

## Overview

##### Main System Components

a. Core Components:
- Frontend Service (Web Interface)
- Backend API Service (Sanic-based)
- Knowledge Processing Pipeline
- Question-Answering Engine
- Storage Systems

b. Dependent Services:
- Embedding Service
- Reranking Service
- OCR Service
- PDF Parser Service
- Database Services (Milvus, MySQL)

**[Web Frontend (Port 8777)] --- [API Endpoints]**

**[QAnything Server]**

**[Knowledge Processing] --- [Question-Answering]**

**[File Upload] → [Document Parser] → [Text Chunking] → [Embedding Generation] → [Vector Storage]**

**[Embedding Service] --- [Reranking Service] --- [OCR Service] --- [PDF Parser]**

**[Milvus Vector DB] --- [MySQL Metadata DB] --- [File Storage]**

##### Key Interactions to Highlight

a. Document Processing Flow:
- File input flow through parsers
- Embedding generation process
- Storage in vector database

b. Query Processing Flow:
- Query embedding process
- Two-stage retrieval (embedding + reranking)
- LLM integration for answer generation

##### Special Features

- Two-stage retrieval architecture
- Multi-format document support
- Offline capability
- Independent service architecture
- Quick start mode
- Retrieval-only mode

##### Technical Details to Note

- Docker-based deployment
- CPU-optimized processing
- Multiple platform support (Windows, Mac, Linux)
- API compatibility with OpenAI
- BCEmbedding integration

##### Additional Elements

- Version information
- Hardware requirements
- Offline-capable components

##### The independent service design

Remember to:
- Use consistent styling
- Major components
- Clear data flow paths
- Two-stage retrieval process

This system design should reflect QAnything's sophisticated architecture while maintaining clarity and understandability for technical stakeholders.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        Frontend["Web Frontend\n(Port 8777)"]:::frontend
        API["API Endpoints"]:::api
    end

    subgraph Core["Core Services Layer"]
        Server["QAnything Server"]:::server
        KnowProcess["Knowledge Processing"]:::process
        QAEngine["Question-Answering Engine"]:::qa
    end

    subgraph Pipeline["Processing Pipeline"]
        Upload["File Upload"]:::process
        Parser["Document Parser"]:::process
        Chunking["Text Chunking"]:::process
        EmbedGen["Embedding Generation"]:::process
        VecStore["Vector Storage"]:::storage
    end

    subgraph Services["Dependent Services"]
        EmbedService["Embedding Service"]:::service
        RerankService["Reranking Service"]:::service
        OCRService["OCR Service"]:::service
        PDFService["PDF Parser Service"]:::service
    end

    subgraph Storage["Storage Layer"]
        Milvus[(Milvus Vector DB)]:::db
        MySQL[(MySQL Metadata DB)]:::db
        FileStore[("File Storage")]:::storage
    end

    subgraph LLM["LLM Integration"]
        LLMService["LLM Service"]:::llm
    end

    %% Connections
    Frontend <--> API
    API --> Server
    Server --> KnowProcess
    Server --> QAEngine
    
    KnowProcess --> Upload
    Upload --> Parser
    Parser --> Chunking
    Chunking --> EmbedGen
    EmbedGen --> VecStore
    
    Parser --> PDFService
    Parser --> OCRService
    EmbedGen --> EmbedService
    QAEngine --> RerankService
    QAEngine --> LLMService
    
    VecStore --> Milvus
    KnowProcess --> MySQL
    Upload --> FileStore

    %% Styles
    classDef frontend fill:#2374ab
    classDef api fill:#2374ab,stroke-dasharray: 5 5
    classDef server fill:#48a9a6
    classDef process fill:#4ea5d9
    classDef qa fill:#4ea5d9
    classDef service fill:#e4572e
    classDef storage fill:#ffc914
    classDef db fill:#ffc914,stroke:#333,stroke-width:2px
    classDef llm fill:#c17767

    %% Click Events
    click Frontend "https://github.com/netease-youdao/QAnything/tree/qanything-v2/qanything_kernel/qanything_server/dist/qanything"
    click API "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/qanything_server/sanic_api.py"
    click Server "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/qanything_server/handler.py"
    click KnowProcess "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/core/local_doc_qa.py"
    click QAEngine "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/core/chains/condense_q_chain.py"
    click EmbedService "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/dependent_server/embedding_server/embedding_server.py"
    click RerankService "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/dependent_server/rerank_server/rerank_server.py"
    click OCRService "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/dependent_server/ocr_server/ocr_server.py"
    click PDFService "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/dependent_server/pdf_parser_server/pdf_parser_server.py"
    click Milvus "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/connector/database/milvus/milvus_client.py"
    click MySQL "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/connector/database/mysql/mysql_client.py"
    click LLMService "https://github.com/netease-youdao/QAnything/blob/qanything-v2/qanything_kernel/connector/llm/llm_for_openai_api.py"
    click Parser "https://github.com/netease-youdao/QAnything/tree/qanything-v2/qanything_kernel/utils/loader"
```
