How jamwithai/build_your_local_rag_system works
Main Components
• Frontend/UI:
• This is represented by the Streamlit entry point (Welcome.py) and supporting pages (found in the “pages” directory, e.g., the Chatbot and Upload Documents pages). These provide the user interface where users interact with the system.
• Document Processing & Ingestion:
• Modules in the “src” folder such as ingestion.py and ocr.py handle the processing of incoming documents (including OCR if needed) and prepare them for further processing.
• Embedding Generation:
• The embeddings.py module (and the “embedding_model” folder) is responsible for transforming documents into vector representations using Sentence Transformers or a similar technology.
• Search and Indexing:
• opensearch.py in “src” indicates integration with OpenSearch. This component handles indexing of document embeddings and performing hybrid search (traditional text matching + semantic search).
• Chat/LLM Interaction:
• The chat.py module in “src” seems to facilitate the conversation logic, integrating responses from a local LLM to generate context-aware answers based on retrieved documents.
• Configuration & Utilities:
• constant.py and index_config.json store configuration parameters and settings. The utils.py module provides supporting functionality.
• Logging & Monitoring:
• There are multiple logging setups (app.log at the root and inside the “logs” directory) to capture system events.
Relationships and Data Flow
• User interactions via the Frontend trigger document upload or chat-based queries.
• For uploaded documents:
• The Frontend routes the file uploads to the ingestion module (src/ingestion.py) and the OCR module (src/ocr.py) if needed.
• Processed documents are then passed to the embedding generator (src/embeddings.py) to create vector representations.
• These representations get stored/indexed in OpenSearch through the opensearch.py module.
• For query handling:
• A user’s query is received by the Frontend and forwarded to the chat module (src/chat.py).
• The chat module uses OpenSearch to retrieve relevant document embeddings.
• The system then uses the local LLM (configured via constants in constants.py) to generate natural language responses that augment the retrieved information.
• The data flow also includes logs-generation and error/exception monitoring across every stage.
Architectural Patterns & Technologies
• The design follows a layered architecture that separates the UI, business logic (ingestion, processing, embedding generation), and data layer (OpenSearch).
• A modular design is evident with clearly delineated roles for each module.
• Dependency injection is possible via configuration files (like constants.py and index_config.json).
• Technologies/Frameworks:
• Frontend: Streamlit (as indicated by the Welcome.py and pages scripts).
• Search and indexing: OpenSearch.
• AI Components: Local LLMs and Sentence Transformers handling the document embeddings and text generation.
• Auxiliary libraries and utilities (as referenced by pyproject.toml and requirements.txt).