A hybrid Retrieval-Augmented Generation chatbot that answers coding questions — instantly retrieving high-quality pre-written answers for known topics, and generating fresh answers for novel ones. Runs fully offline after the initial model download.
flowchart TD
Q["User question"] --> EMB["Embed with multi-qa-mpnet-base-dot-v1"]
EMB --> SIM{"Similarity vs vector DB<br/>above confidence threshold?"}
SIM -- "yes (known topic)" --> RET["Return pre-written answer<br/>(instant, high quality)"]
SIM -- "no (novel question)" --> GEN["Generate with microsoft/phi-2"]
GEN --> LEARN["Optionally add Q→A pair<br/>back into the vector DB<br/>(self-improving)"]
RET --> OUT["Answer"]
LEARN --> OUT
- Retriever:
sentence-transformers/multi-qa-mpnet-base-dot-v1for high-precision semantic search - Generator:
microsoft/phi-2for coherent novel answers - Self-improving knowledge base: newly generated Q→A pairs can be folded back into the vector DB, so the assistant gets smarter over time
- Fully offline after initial model download
git clone https://github.com/YazanAi-Dev3/AI-Coding-Assistant.git
cd AI-Coding-Assistant
# Download both models into model_cache/{multi-qa-mpnet-base-dot-v1, phi-2}
python -m venv venv # activate, then:
pip install -r requirements.txt
python src/build_vector_db.py # builds database/vector_database.pkl from data/questions_answers.jsonThen run the interactive demo in Demo.ipynb.
AI-Coding-Assistant/
├── src/
│ ├── model_loader.py # loads retriever + generator
│ ├── build_vector_db.py # constructs the vector DB
│ └── chatbot_logic.py # two-path retrieval/generation logic
├── data/questions_answers.json # curated Q→A knowledge base
├── database/vector_database.pkl# prebuilt embeddings
└── Demo.ipynb
Python · sentence-transformers (MPNet) · microsoft/phi-2 · offline vector database
MIT — see LICENSE.