How shawmica/real-time-rag-ai-assistant works
1. What this repo is
This is a Python-based Retrieval-Augmented Generation (RAG) assistant that combines a chat UI, an API layer, document ingestion, vector search, and an LLM response generator. The architecture is split into a user-facing Streamlit app, a FastAPI backend, and local storage for documents and vectors.
2. Primary runtime split
The app appears to run as two cooperating services:
- Streamlit for the interactive user interface
- FastAPI for backend orchestration and request handling
The README’s flow is consistent with: user interaction in Streamlit, backend retrieval via FastAPI, then generation through Groq.
3. User interface layer
The frontend lives in streamlit-app.py, with login-page.py suggesting a separate authentication or onboarding screen. This layer handles user interaction, chat input, file/upload actions, and rendering answers, but it should be treated as a thin client rather than the place where retrieval or generation logic lives.
4. API / application boundary
api.py is the central backend entry point. It likely exposes endpoints for chat, retrieval, upload/ingestion, and possibly authentication/session-related operations. This file is the main boundary between the UI and the RAG pipeline.
5. RAG orchestration layer
rag-system.py is the core application glue. It likely coordinates:
- query preprocessing
- retrieval from the vector store
- prompt/context assembly
- calling the Groq LLM
- returning a final answer
This is the highest-level “business logic” layer of the assistant.
6. Document ingestion and parsing
contract-parser.py and the docs/ plus extracted/ folders indicate a document-processing path, probably for PDFs. The presence of docs/#2 - Securing Enterprise Networks.pdf and extracted/fixed_extracted_text.txt suggests a pipeline where raw PDF content is parsed/extracted into normalized text before indexing. This is the offline or pre-chat ingestion side of the system.
7. Embeddings and indexing
embeddings.py is the embedding-generation component, likely using HuggingFace models as noted in the README. vector_store.py likely manages ChromaDB collection creation, persistence, upserts, and similarity search. Together these form the retrieval substrate: text chunks become embeddings, and embeddings are stored for semantic lookup.
8. Data flow through the RAG path
The end-to-end flow is:
- document/PDF input enters the ingestion pipeline
- text is extracted and normalized
- chunks are embedded
- embeddings are stored in ChromaDB
- a user query comes in through Streamlit
- FastAPI hands the query to the RAG system
- retriever pulls relevant chunks from ChromaDB
- Groq LLM generates the final answer using retrieved context
This is the main architecture diagram backbone.
9. Persistence and state
db.py indicates a separate persistence layer beyond the vector store, likely for users, login state, metadata, or application records. In this repo, persistent state is therefore split between:
- ChromaDB for semantic document retrieval
- a traditional database for app/user data
- local files for source PDFs and extracted text artifacts
10. Operational and admin utilities
check-groqapi.py is a health/test utility for validating Groq connectivity. reset-users.py is an admin/maintenance script for clearing or reinitializing user records. These are not part of the main request path, but they matter operationally because they support setup, troubleshooting, and lifecycle management.
11. External dependencies that shape the architecture
The major external services/frameworks are:
- Groq LLM for generation
- HuggingFace embeddings for vectorization
- ChromaDB for vector retrieval
- FastAPI for backend APIs
- Streamlit for UI
- LangChain as the integration layer around retrieval/LLM composition
These are not incidental libraries; they define the architecture and the separation of concerns.
12. How to draw the diagram
The most accurate diagram should show:
- a user interacting with Streamlit
- Streamlit calling FastAPI
- FastAPI delegating to RAG orchestration
- RAG calling ChromaDB for retrieval
- RAG calling Groq for completion
- an offline/side ingestion path from PDF/docs to text extraction to embeddings to ChromaDB
- a separate DB for app/user state
That separation captures both the live chat path and the indexing/maintenance path without conflating them.
Main entry points: rag-system.py RAG System · api.py FastAPI · streamlit-app.py Streamlit App · embeddings.py Embeddings
Components 18
User Interface
Interactive client and entry screens
- User · End user asking questions and uploading documents
- Streamlit App · Primary chat and upload interface
streamlit-app.py - Login Page · Authentication or onboarding screen
login-page.py
Backend Core
API and RAG orchestration
- FastAPI · Backend request entry point and orchestration boundary
api.py - RAG System · Coordinates retrieval, prompt assembly, and generation
rag-system.py - Query Flow · Live chat request handling from user input to answer
- Groq LLM · External model used to generate final answers
- LangChain · Composition layer for retrieval and LLM calls
Ingestion
Document parsing and indexing path
- Parser · Extracts and normalizes document text
contract-parser.py - Embeddings · Creates embeddings for indexed text chunks
embeddings.py - Documents · PDF and document inputs for indexing
docs - Extracted Text · Parsed text artifacts used for downstream chunking
extracted/fixed_extracted_text.txt - HuggingFace · External embedding provider or model family
Storage
Persistent state and retrieval backends
- Vector Store · Manages ChromaDB persistence and similarity search
vector_store.py - App DB · Stores application or user state beyond vectors
db.py - ChromaDB · Semantic retrieval backend for embedded chunks
Operations
Health and maintenance utilities
- Groq Check · Connectivity test for Groq access
check-groqapi.py - Reset Users · Maintenance script for user records
reset-users.py
Connections 21
- User → Streamlit App: uses · User interacts through the Streamlit interface
- Streamlit App → Login Page: auth entry · Streamlit can route to the login or onboarding screen
- Streamlit App → FastAPI: requests · UI sends chat and upload actions to the backend API
- FastAPI → RAG System: delegates · FastAPI hands RAG work to the orchestration layer
- RAG System → LangChain: composes · RAG logic uses LangChain-style composition
- LangChain → Vector Store: retrieves · Retriever queries the vector store for relevant chunks
- LangChain → Groq LLM: generates · LLM call produces the final response
- RAG System → App DB: reads state · RAG or API may consult app/user persistence
- Documents → Parser: ingests · Raw documents are parsed into normalized text
- Parser → Extracted Text: produces · Parser outputs extracted text artifacts
- Extracted Text → Embeddings: embeds · Normalized text is transformed into vectors
- Embeddings → ChromaDB: stores · Embeddings and chunks are written to ChromaDB
- ChromaDB → Vector Store: backing store · Vector store manages the retrieval database
- Embeddings → HuggingFace: uses · Embedding generation relies on HuggingFace models
- RAG System → ChromaDB: searches · RAG retrieves context from the semantic index
- FastAPI → Groq Check: ops check · Utility validates Groq connectivity during setup or debugging
- FastAPI → Reset Users: admin · Utility resets user state when needed
- RAG System → Groq LLM: calls · Answer generation is performed by Groq
- FastAPI → Query Flow: handles · Represents the live request path through the backend
- Query Flow → RAG System: routes to · Query flow reaches the RAG orchestrator
- Documents → Extracted Text: source to text · Document inputs become extracted text for indexing