How huangl22/chat3gpp works
Project type and purpose
• Chat3GPP is a Retrieval-Augmented Generation (RAG) framework specialized for 3GPP technical documents.
• It provides both an offline data‐ingestion pipeline (preprocessing and indexing into Elasticsearch) and an online query/response engine (user chat clients, retrievers, reranker, LLM).
File structure
• Top-level scripts:
• init_database.py – builds and populates Elasticsearch
• chat.py – simple direct chat client using LLM
• kb_chat.py – chat client that augments responses with retrieved 3GPP content
• Directories:
• configs/ – configuration of knowledge-base and model parameters
– kb_configs.py (Elasticsearch index settings, retrieval hyperparameters)
– model_configs.py (paths or endpoints for your embedding and LLM models)
• preprocess/ – data-cleaning scripts (remove_content.py)
• text_splitter/ – document chunking utilities (TSdocx_splitter.py)
• retrievers/ – retrieval abstractions and implementations
– base.py (abstract retriever interface)
– VectorRetriever.py (vector‐based Elasticsearch query)
• server/ – core RAG pipeline modules
– embedding.py (query/document embedding)
– reranker.py (reorder top-k retrievals)
– llm.py (invokes the language model for generation)
• utils.py – shared helper functions
README for insights
• Clearly describes two phases:
a) Preprocess & import standard docs into Elasticsearch
b) Run either chat.py or kb_chat.py for inference
• Dependencies: Python 3.8, Elasticsearch, ML models (via HuggingFace/OpenAI)
Main components
a. Offline Data-Ingestion Pipeline
• Preprocessor Module (preprocess/remove_content.py)
• Text Splitter Module (text_splitter/TSdocx_splitter.py)
• Database Initializer (init_database.py)
• Elasticsearch Cluster (knowledge base)
b. Online Inference Pipeline
• Chat Clients (chat.py, kb_chat.py)
• RAG Server Modules (server/embedding.py, server/llm.py, server/reranker.py)
• Retriever Layer (retrievers/base.py, retrievers/VectorRetriever.py)
• Model Serving (embedding model, generation LLM)
• Elasticsearch for retrieval
Relationships and interactions
• Offline:
1. Raw 3GPP docs → Preprocessor → Cleaned text
2. Cleaned text → Text Splitter → Chunks
3. init_database reads chunks + configs → indexes into Elasticsearch
• Online (kb_chat.py flow):
1. User Query → embedding.py → vector representation
2. VectorRetriever → Elasticsearch → top-N relevant chunks
3. reranker.py → reorder chunks by relevance
4. llm.py → prompt LLM with query + top contexts → Generated Response
5. Response → returned to User
• Direct Chat (chat.py) bypasses retrieval & reranker; sends query to llm.py only
Architectural patterns & design principles
• Modular pipeline: clear separation of preprocessing, indexing, retrieval, ranking, and generation
• Config-driven: all model and database settings in configs/
• Interface abstraction: retrievers implement a common interface (base.py) for future extension
• RAG pattern: blend vector search + LLM generation
Relevant technologies/frameworks
• Elasticsearch (vector and text search)
• Python 3.8, standard libraries
• HuggingFace Transformers or OpenAI API for embeddings & generation
• Optional: Docker/Kubernetes for Elasticsearch deployment