How jamwithai/beginner-local-rag-system works
1. Overall shape
- This repo is a local Retrieval-Augmented Generation (RAG) application built around a Streamlit UI, a document ingestion/indexing pipeline, and an OpenSearch-backed retrieval layer.
- The design goal is privacy: documents stay local, embeddings are computed locally, and search/retrieval happens against a self-managed OpenSearch instance.
2. User-facing application layer
- The app entrypoint is Welcome.py, with the main UI split into Streamlit pages under pages/.
- pages/1_🤖_Chatbot.py is the query interface for asking questions over indexed documents.
- pages/2_📄_Upload_Documents.py is the document submission interface that feeds the ingestion pipeline.
- This split implies a two-step user flow: upload/index first, then ask questions.
3. Document ingestion subsystem
- src/ingestion.py is the core pipeline for bringing files into the system.
- uploaded_files/ is the local staging area for source documents, and the sample PDFs there indicate the app expects user-provided files to be stored on disk before processing.
- The ingestion flow likely extracts text, prepares chunks/records, builds embeddings, and writes searchable documents into OpenSearch.
4. OCR and text extraction boundary
- src/ocr.py is a dedicated boundary for handling scanned or image-based documents.
- This separates raw file handling from text normalization, which matters because the system must support both digitally generated PDFs and documents requiring OCR.
- In architecture terms, OCR sits between file input and downstream indexing.
5. Embedding generation
- src/embeddings.py handles vector creation using a local embedding model.
- The embedding_model/ directory and its README suggest the model is stored or configured locally rather than fetched dynamically at runtime.
- Embeddings are central to the semantic portion of retrieval and are produced during ingestion, then reused at query time for matching.
6. OpenSearch as the indexing and retrieval backend
- src/opensearch.py encapsulates connectivity and operations against OpenSearch.
- src/index_config.json likely defines the index mapping/settings needed for hybrid search, including text fields and vector fields.
- OpenSearch is the main persistence and retrieval layer, storing both document metadata/text and embedding vectors for hybrid search.
7. Question answering / chat subsystem
- src/chat.py is the orchestration layer for the chatbot experience.
- The likely flow is: user question → retrieval from OpenSearch → construction of a grounded prompt/context → response generation by an LLM.
- This module is the main RAG composition boundary, where search results become prompt context for generation.
8. Shared configuration and utilities
- src/constants.py centralizes settings such as model names, index names, and OpenSearch connection details.
- src/utils.py is the shared support layer for reusable helpers across ingestion, retrieval, and UI.
- This keeps environment-specific decisions out of the higher-level app logic.
9. Project data and local artifacts
- logs/ and app.log show the application records runtime behavior locally, which is useful for debugging ingestion/search issues.
- images/ contains UI/media assets used by the README and likely the Streamlit app branding.
- notebooks/ contains exploratory and instructional notebooks that document the setup and the end-to-end pipeline, but they are not the production runtime path.
10. Runtime and deployment model
- The repo is organized for local execution via Streamlit plus a locally accessible OpenSearch instance.
- Dependencies are managed through requirements.txt and pyproject.toml, with mypy.ini indicating static typing checks are part of the engineering workflow.
- The architecture assumes the developer/user has local access to models, documents, and search infrastructure, reinforcing the offline/private nature of the system.
11. End-to-end data flow
- Upload path: user uploads document → file lands in local storage → OCR/text extraction → chunking/normalization → embeddings generation → OpenSearch indexing.
- Chat path: user asks a question → query is embedded/processed → hybrid search against OpenSearch → top passages are assembled as context → LLM generates an answer.
- The critical architectural boundary is OpenSearch, which separates offline document preparation from interactive retrieval and response generation.
12. What matters most for a diagram
- Show three major boxes: Streamlit UI, Local processing pipeline, and OpenSearch index.
- Inside the processing pipeline, distinguish OCR/text extraction, embedding generation, and ingestion/indexing.
- On the query side, show retrieval + prompt assembly + LLM response in src/chat.py, with OpenSearch providing the retrieved context.
Main entry points: ingestion.py Ingestion · chat.py RAG chat · opensearch.py OpenSearch client · Welcome.py Home
Components 17
Streamlit UI
User-facing entrypoints and page flow
- User · Person uploading documents and asking questions
- Home · Main app entrypoint
Welcome.py - Upload docs · Document submission interface
pages/2_📄_Upload_Documents.py - Chatbot · Question-answering interface
pages/1_🤖_Chatbot.py
Local pipeline
Document ingestion, extraction, and embedding
- Upload store · On-disk location for source documents
uploaded_files - Ingestion · Core document processing and indexing flow
src/ingestion.py - OCR · Handles scanned or image-based documents
src/ocr.py - Embeddings · Builds local embeddings for documents and queries
src/embeddings.py
Search and chat
OpenSearch-backed retrieval and answer generation
- OpenSearch client · Connects application code to OpenSearch
src/opensearch.py - RAG chat · Retrieval, context assembly, and response flow
src/chat.py - OpenSearch · Stores indexed text, metadata, and vectors
Support files
Local assets, config, and artifacts
- Index config · Index settings and field definitions
src/index_config.json - Constants · Shared model, index, and connection settings
src/constants.py - Utils · Reusable support functions
src/utils.py - Local model · Locally stored embedding model artifacts
embedding_model/README.md - Logs · Local application logs
logs/app.log - Notebooks · Setup and walkthrough notebooks
notebooks/03_Hybrid_Search_and_Retrieval.ipynb
Connections 28
- User → Home: opens · Starts the app
- Home → Upload docs: routes to · Document upload flow
- Home → Chatbot: routes to · Question answering flow
- User → Upload docs: uploads · Submits documents for indexing
- User → Chatbot: asks · Submits questions over indexed content
- Upload docs → Upload store: stores · Writes source files to local staging
- Upload store → Ingestion: feeds · Documents are processed for indexing
- Ingestion → OCR: extracts text · Uses OCR when needed
- Ingestion → Embeddings: vectorizes · Generates document embeddings
- Ingestion → OpenSearch client: indexes via · Writes documents and vectors
- OCR → Ingestion: normalized text · Returns extracted text to the pipeline
- Embeddings → OpenSearch client: writes vectors · Supplies embedding payloads for indexing
- OpenSearch client → OpenSearch: connects to · Search and indexing backend
- Chatbot → RAG chat: invokes · Runs chatbot orchestration
- RAG chat → Embeddings: embeds query · Creates query vectors for retrieval
- RAG chat → OpenSearch client: retrieves from · Fetches ranked passages from search
- RAG chat → OpenSearch: queries · Uses indexed content as retrieval source
- RAG chat → Constants: reads settings · Uses shared runtime configuration
- Ingestion → Constants: reads settings · Uses shared runtime configuration
- OpenSearch client → Index config: applies schema · Uses index mapping and field config
- Embeddings → Local model: loads model · Uses local embedding artifacts
- Ingestion → Utils: uses · Shared helper functions
- RAG chat → Utils: uses · Shared helper functions
- Home → Logs: writes · Runtime logging
- Upload docs → Logs: writes · Runtime logging
- Chatbot → Logs: writes · Runtime logging
- Notebooks → Ingestion: demonstrates · Explores ingestion pipeline
- Notebooks → RAG chat: demonstrates · Explores retrieval and chat flow