How z3phyru5646/qna-assistant-from-scratch-using-langchain works
1. Project shape
- This is a Streamlit-based hybrid RAG application named hybrid_rag.
- The repo is organized into a small number of clear layers: UI, RAG/core services, document ingestion and processing, configuration, and utility wrappers for external APIs.
2. Runtime entrypoint
- app.py is the top-level application entrypoint.
- It likely wires together authentication, sidebar/navigation, chat, notebook, dashboard, and monitoring views from the ui/ package.
3. User interface layer
- The ui/ directory contains the presentation layer for the Streamlit app:
- chat_interface.py for conversational interaction
- citation_panel.py for source attribution
- notebook_panel.py for note-taking / saved context
- sidebar.py, filter_buttons.py, and dashboard_metrics.py for controls and status views
- login_page.py for authentication UI
- system_monitor.py for runtime/health visibility
- styles.py for shared visual styling
- This layer does not appear to own retrieval logic; it consumes services from core/.
4. Document ingestion boundary
- ingest.py is the ingestion entrypoint.
- The core/ processors split input by file type and modality:
- pdf_processor.py, docx_processor.py, txt_processor.py
- text_pipeline.py, image_pipeline.py, table_pipeline.py
- This suggests the system can ingest mixed content types and normalize them into a common retrieval-ready representation.
5. Hybrid content processing
- The presence of separate pipelines for text, images, and tables indicates a hybrid retrieval design, not just plain text RAG.
- utils/google_lens_api.py and utils/google_ai_mode_api.py imply external AI services are used to enrich or interpret non-text content, especially images.
- core/autocorrect_engine.py likely cleans or standardizes extracted text before indexing or querying.
6. Embedding and vector storage
- core/embedding_manager.py handles embedding generation.
- core/vectorstore_manager.py manages persistence and access to the vector store.
- These form the indexing backbone: extracted content is transformed into embeddings and stored for similarity search.
7. Retrieval and answer generation
- core/retriever.py performs retrieval over the indexed corpus.
- core/rag_chain.py orchestrates the end-to-end retrieval-augmented generation flow.
- core/llm_manager.py abstracts LLM access, so the generation layer is isolated from the rest of the app.
- core/summarizer.py suggests an additional response mode for compressing retrieved content or producing concise outputs.
8. Safety, visibility, and control
- core/guardrails.py appears to enforce query or response constraints.
- core/query_visibility.py likely controls whether internal retrieval context or reasoning artifacts are exposed in the UI.
- core/question_suggester.py can generate follow-up questions or prompt suggestions to guide the user.
9. Memory and notebook features
- core/memory_manager.py and core/notebook_manager.py imply the app preserves conversation state and user-created notes.
- These are separate from the vector store: one supports conversational continuity, the other supports explicit user curation.
10. Authentication and access
- core/auth_manager.py and ui/login_page.py define the auth boundary.
- This likely gates access to the chat, notebook, and document features, and may influence what content or sessions a user can see.
11. Shared configuration and localization
- config/settings.py holds application settings, while config/translations.py suggests multilingual or localized UI strings.
- .streamlit/config.toml contains Streamlit-specific runtime/configuration settings.
12. External service integration
- utils/google_ai_mode_api.py and utils/google_lens_api.py are explicit integration points to Google services.
- The rest of the code appears to depend on these wrappers rather than calling external APIs directly, which keeps the core architecture decoupled from vendor-specific details.
13. Likely data flow for the main use case
- A user uploads or ingests documents.
- File-specific processors extract text, tables, and image-derived content.
- The content is normalized, embedded, and stored in the vector store.
- During chat, the retriever pulls relevant chunks.
- The RAG chain combines retrieved context with the LLM.
- The UI displays the answer, citations, suggested questions, and any notebook/memory state.
14. What to draw in an architecture diagram
- Show three main zones:
- UI / Streamlit frontend
- Core RAG services
- Ingestion + external AI/API integrations
- Connect ingestion into processors, then embeddings/vector store, then retriever, then RAG chain, then LLM, then back to the UI with citations and monitoring.
- Treat auth, memory, notebook, guardrails, and query visibility as cross-cutting services around the main retrieval loop.
Main entry points: rag_chain.py RAG chain · app.py App · chat_interface.py Chat · text_pipeline.py Text pipe
Components 31
UI
Streamlit presentation layer and app screens
- App · Top-level application wiring and navigation
app.py - Login · Authentication screen
ui/login_page.py - Sidebar · Primary app navigation and controls
ui/sidebar.py - Chat · Main user interaction surface for Q&A
ui/chat_interface.py - Citations · Source display and evidence panel
ui/citation_panel.py - Notebook · Saved notes and user-curated context
ui/notebook_panel.py - Monitor · Runtime and health visibility
ui/system_monitor.py
Core RAG
Retrieval, generation, memory, and control services
- Autocorrect · Cleanup and standardization of extracted text
core/autocorrect_engine.py - Embeddings · Embedding generation for indexed content
core/embedding_manager.py - Vector store · Persistence and access to vector index
core/vectorstore_manager.py - Retriever · Similarity search over indexed corpus
core/retriever.py - RAG chain · End-to-end retrieval augmented generation flow
core/rag_chain.py - LLM · Language model access abstraction
core/llm_manager.py - Guardrails · Query and response constraints
core/guardrails.py - Memory · Conversation continuity and session memory
core/memory_manager.py - Notebook svc · Persisted user notes and curation
core/notebook_manager.py - Visibility · Controls exposure of internal retrieval context
core/query_visibility.py - Suggester · Follow-up question generation
core/question_suggester.py - Summarizer · Concise summarization of retrieved content
core/summarizer.py - Auth · Authentication and session authorization
core/auth_manager.py
Ingestion
Document parsing and hybrid content pipelines
- Ingest · Document ingestion orchestration
ingest.py - PDF · PDF extraction and preparation
core/pdf_processor.py - DOCX · Word document extraction and preparation
core/docx_processor.py - Text · Plain-text extraction and preparation
core/txt_processor.py - Text pipe · Normalization and chunking for text content
core/text_pipeline.py - Image pipe · Image interpretation and enrichment pipeline
core/image_pipeline.py - Table pipe · Table extraction and normalization pipeline
core/table_pipeline.py
Config
Application settings and translations
- Settings · Application settings and environment values
config/settings.py - Translations · UI string and language resources
config/translations.py
External APIs
Wrappers around vendor and shared helper utilities
- Google AI · Wrapper for AI mode interactions
utils/google_ai_mode_api.py - Google Lens · Wrapper for image understanding interactions
utils/google_lens_api.py
Connections 40
- App → Login: auth flow · Routes unauthenticated users to login
- App → Sidebar: navigation · Builds global navigation and controls
- App → Chat: main view · Hosts the primary chat experience
- App → Citations: evidence view · Displays answer sources and citations
- App → Notebook: notes view · Shows saved notes and curated context
- App → Monitor: status view · Surfaces runtime and health information
- App → Settings: config · Loads runtime settings
- App → Translations: localization · Uses UI language resources
- Login → Auth: verify · Authenticates user sessions
- Chat → RAG chain: ask · Submits user queries to the RAG flow
- Chat → Memory: session state · Reads and writes conversation memory
- Chat → Suggester: suggest · Generates follow-up prompts
- Chat → Visibility: context toggle · Controls disclosure of internal context
- Chat → Guardrails: policy · Applies safety and query constraints
- Chat → Summarizer: summarize · Requests concise response variants
- Chat → Notebook svc: save note · Persists user-curated notes
- Notebook → Notebook svc: sync · Reads and updates notebook content
- Ingest → PDF: parse · Dispatches PDF documents
- Ingest → DOCX: parse · Dispatches DOCX documents
- Ingest → Text: parse · Dispatches text documents
- PDF → Text pipe: normalize · Feeds extracted text into the text pipeline
- DOCX → Text pipe: normalize · Feeds extracted text into the text pipeline
- Text → Text pipe: normalize · Feeds plain text into the text pipeline
- Text pipe → Autocorrect: clean · Standardizes extracted text before indexing
- Text pipe → Embeddings: embed · Creates embeddings for normalized chunks
- Image pipe → Google Lens: vision api · Uses external image understanding
- Image pipe → Google AI: enrich · Uses AI services to interpret visual content
- Image pipe → Embeddings: embed · Converts enriched image content to embeddings
- Table pipe → Text pipe: normalize · Reuses text normalization for table content
- Embeddings → Vector store: store · Persists embeddings in the vector index
- RAG chain → Retriever: retrieve · Pulls relevant chunks from the corpus
- Retriever → Vector store: search · Queries the vector store
- RAG chain → Guardrails: check · Validates retrieval and generation boundaries
- RAG chain → LLM: generate · Calls the model for answer synthesis
- RAG chain → Visibility: prepare context · Shapes what retrieval context is exposed
- RAG chain → Summarizer: compress · Produces concise answer or context summaries
- RAG chain → Suggester: follow-ups · Generates suggested next questions
- RAG chain → Memory: persist state · Updates conversational memory
- RAG chain → Notebook svc: store notes · Shares curated outputs with notebook storage
- Sidebar → Auth: session gate · Uses auth state to control access