An Optimized RAG System for Python Documentation
PyDocQ&A is a Retrieval-Augmented Generation (RAG) application that enables fast, accurate question answering over Python documentation using semantic search and a transformer-based language model.
The system is designed with a clear separation between offline indexing and online querying to ensure low-latency responses.
- Semantic search over Python documentation using FAISS
- Efficient text embeddings via Sentence Transformers
- Transformer-based answer generation using FLAN-T5
- One-time offline embedding and indexing for performance optimization
- Interactive Streamlit chat interface
- Modular, production-style project structure
Python Docs (.txt)
β
Document Chunking
β
Sentence Embeddings
β
FAISS Vector Index (Persisted)
β
Query Embedding
β
Top-K Semantic Retrieval
β
Context Injection
β
LLM Answer Generation
PyDocQ&A/
β
βββ artifacts/
β βββ faiss.index # FAISS vector index
β βββ chunks.pkl # Chunked document metadata
β
βββ src/
β βββ load_and_chunk.py # Load and chunk text documents
β βββ embeddings.py # Create sentence embeddings
β βββ build_index.py # One-time FAISS index builder
β βββ qa_chain.py # CLI-based question answering
β βββ app.py # Streamlit UI application
β
βββ .gitignore
βββ requirements.txt
βββ README.md
- Python
- FAISS β Vector similarity search
- SentenceTransformers β Text embeddings
- Transformers (FLAN-T5) β Answer generation
- Streamlit β Web UI
- LangChain β Document and text utilities
π Data & Artifacts Note
Raw Python documentation files are excluded from the repository to keep it lightweight and reproducible.
Precomputed FAISS indexes and processed artifacts are included to enable instant evaluation and fast querying without rebuilding embeddings.
π Performance Optimization
Stage Naive Approach Optimized Approach
Embedding Every run One-time offline
Indexing Every run Persisted FAISS
Query latency Minutes ~1β2 seconds
Startup time High Low