How ashgen12/aerocraft_rag_chatbot works
Project type and purpose
• This is a Python-based AI chatbot application built with Streamlit.
• Its purpose is to answer questions about the fictional AeroCraft ACE-900 takeoff procedures by combining:
• A Retrieval-Augmented Generation (RAG) pipeline (vector store + embeddings)
• A dynamically built Knowledge Graph (KG) for structured context
• A Large Language Model (LLM) via the OpenRouter API
• An interactive Streamlit frontend, including a KG visualization
File structure
• Top-level scripts:
• app.py → Streamlit app / UI orchestration
• rag_chain.py → RAG pipeline setup (LangChain chains, FAISS store)
• kg_builder.py → KG construction & Plotly visualization (NetworkX + regex)
• utils.py → configuration, logging, helper routines
• Data directories:
• data/ace900_takeoff_manual.txt → source text for retrieval
• static/kg_visualization.html → optional saved KG graph
• Config and dependencies:
• .env → API keys for OpenRouter & HuggingFace
• requirements.txt → Python libraries (Streamlit, LangChain, NetworkX, FAISS, Plotly, python-dotenv)
README for additional insights
• Confirms architecture components: vector embeddings via Hugging Face, in-memory FAISS store, OpenRouter LLM backend, NetworkX KG, Streamlit UI, real-time logging of pipeline steps.
• Explains how queries traverse retrieval, graph extraction, and LLM synthesis.
Main components & their interactions
a. Frontend (Streamlit in app.py)
• Chat interface (user questions / assistant responses)
• Sidebar: KG visualization, processing logs
b. RAG Pipeline (rag_chain.py + FAISS)
• Chunk and embed manual text
• FAISS vector store for similarity search
c. Knowledge Graph Builder (kg_builder.py + NetworkX)
• Parse raw text into nodes & edges
• Provide structured context by querying graph for entities in user query
d. LLM Integration (OpenRouter API)
• Receives combined context (retrieved chunks + KG context) + user question
• Returns final answer
e. Utilities (utils.py)
• Logging each pipeline step
• Loading environment variables
f. Data Storage
• data/ace900_takeoff_manual.txt (source)
• FAISS in-memory index
• Optional static HTML export of KG
Architectural patterns and design principles
• Modular separation: UI layer, retrieval layer, knowledge-graph layer, LLM layer
• RAG pattern: decouple retrieval (vector store) from generation (LLM)
• Knowledge-graph enhancement: add structured context to improve grounding
• Dependency injection via utils (e.g., config loader)
• In-memory services: FAISS and NetworkX simplify deployment (no external DB)
1. User question → Streamlit Frontend
2. Frontend invokes RAG Chain & KG Builder in parallel:
• RAG Chain → embed query → search FAISS → retrieve text chunks
3. Combine KG context + text chunks → build LLM prompt via rag_chain.py
4. Send prompt → OpenRouter LLM API → receive answer
5. Streamlit displays answer; logs and interactive KG rendered in sidebar
Final checklist
• Components: Streamlit UI, RAG Chain, FAISS, KG Builder, NetworkX, LLM API, Embedding API
• Emphasis on modular separation and pipeline transparency