A fully local Retrieval-Augmented Generation (RAG) system built using FastAPI, Streamlit, Ollama, ChromaDB, and Sentence Transformers.
This project allows users to chat with their own documents, synthetic company knowledge bases, PDFs, reports, books, and notes using a local Large Language Model (LLM) without relying on cloud APIs.
The assistant supports both:
- Document-grounded question answering (RAG)
- General knowledge conversations using the LLM
- Supports PDF, Markdown, DOCX, and CSV documents
- Extracts and chunks document text automatically
- Stores embeddings locally using ChromaDB
- Retrieves relevant chunks during questioning
- Provides source-aware grounded answers
The system intelligently handles:
Examples:
- What is the leave policy?
- Explain normalization in DBMS
- Summarize the uploaded report
These use retrieval from indexed documents.
Examples:
- Who is Sachin Tendulkar?
- What is Artificial Intelligence?
- Explain black holes
These bypass retrieval and use the local LLM directly.
| Component | Technology |
|---|---|
| Backend API | FastAPI |
| Frontend UI | Streamlit |
| LLM Runtime | Ollama |
| Vector Database | ChromaDB |
| Embedding Model | paraphrase-MiniLM-L3-v2 |
| Embedding Framework | sentence-transformers |
| Language | Python |
| Testing | Pytest |
Documents / Synthetic Data
↓
Document Ingestion
(core/ingest.py)
↓
Chunking
(core/chunker.py)
↓
Embedding Generation
(core/embedder.py)
↓
Vector Storage (ChromaDB)
(data/vector_store/)
↓
Retriever
(core/retriever.py)
↓
RAG Pipeline
(core/rag.py)
↓
Ollama Local LLM
↓
FastAPI Backend
(api/)
↓
Streamlit UI
(ui/app.py)
ai-knowledge-assistant/
│
├── core/
│ ├── __init__.py
│ ├── ingest.py
│ ├── chunker.py
│ ├── embedder.py
│ ├── retriever.py
│ ├── rag.py
│ ├── redactor.py
│ └── config.py
│
├── api/
│ ├── __init__.py
│ ├── main.py
│ ├── routes/
│ │ ├── ask.py
│ │ └── reindex.py
│ ├── middleware/
│ │ └── auth.py
│ └── schemas.py
│
├── ui/
│ ├── app.py
│ ├── components/
│ │ ├── chat.py
│ │ ├── citations.py
│ │ ├── export.py
│ │ └── upload.py
│ └── .streamlit/
│ └── config.toml
│
├── data/
│ ├── raw/
│ ├── processed/
│ │ └── chunks.json
│ └── vector_store/
│
├── tools/
│ ├── synth_data.py
│ ├── evaluate.py
│ ├── logger.py
│ ├── export.py
│ └── reindex.py
│
├── tests/
│ ├── test_ingest.py
│ └── test_retriever.py
│
├── .env
├── requirements.txt
├── README.md
└── Makefile
Documents are loaded from:
data/raw/
Supported formats:
- DOCX
- Markdown
- CSV
- TXT
Large documents are split into overlapping chunks.
Purpose:
- improves semantic retrieval
- reduces token overload
- increases retrieval precision
Each chunk is converted into vector embeddings using:
paraphrase-MiniLM-L3-v2
This model is lightweight, fast, and optimized for semantic similarity tasks.
Embeddings are stored locally inside:
data/vector_store/
using ChromaDB.
When the user asks a question:
- the query is embedded
- similarity search is performed
- top-k relevant chunks are retrieved
Retrieved chunks are passed to the Ollama LLM as context.
The LLM generates a grounded answer with citations.
- Python 3.10+
- Ollama installed
- Git
- 8 GB RAM minimum
- 16 GB RAM recommended for larger models
Install Ollama:
https://ollama.com
Pull a model:
ollama pull llama3or:
ollama pull mistralStart Ollama:
ollama servegit clone https://github.com/your-username/ai-knowledge-assistant.git
cd ai-knowledge-assistantpython -m venv .venv
.venv\Scripts\activatepython3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtCreate a .env file:
OLLAMA_MODEL=llama3
EMBEDDING_MODEL=paraphrase-MiniLM-L3-v2
TOP_K=5
CHUNK_SIZE=500
CHUNK_OVERLAP=50
API_AUTH_TOKEN=change-mePlace documents inside:
data/raw/
Example:
data/raw/dbms.pdf
data/raw/company_policy.pdf
data/raw/report.docx
Generate sample company documents:
python tools/synth_data.pyThis creates:
- leave policies
- onboarding workflows
- SOPs
- FAQs
- incident response documents
These are useful for testing enterprise RAG behavior.
Run:
python tools/reindex.pyThis performs:
- ingestion
- chunking
- embedding generation
- vector database creation
Start FastAPI:
uvicorn api.main:app --host 127.0.0.1 --port 8000 --reloadFastAPI docs:
http://localhost:8000/docs
Start Streamlit:
streamlit run ui/app.pyUI opens at:
http://localhost:8501
Who is Sachin Tendulkar?
What is Artificial Intelligence?
Explain machine learning
What is the leave policy?
Explain normalization in DBMS
Summarize the uploaded report
To manually test retrieval:
python -c "from core.retriever import retrieve_chunks; r = retrieve_chunks('What is normalization?', top_k=3); print(r)"If retrieval works correctly, you should see:
source: dbms.pdf
inside the output.
The assistant supports exporting answers to:
- Word (.docx)
- Excel (.xlsx)
via Streamlit UI controls.
Run unit tests:
pytestor:
make testRun evaluation pipeline:
python tools/evaluate.pyMeasures:
- Recall@K
- citation grounding
- retrieval quality
- Local-only execution
- No cloud APIs required
- PII redaction supported
- Token-based API authentication
.envexcluded from Git
Whenever new documents are added:
data/raw/
you MUST rebuild the vector index:
python tools/reindex.pyOtherwise the assistant cannot retrieve information from new documents.
- DBMS books
- notes
- research papers
- university reports
- SOPs
- HR policies
- onboarding workflows
- incident response docs
- internal FAQs
- notes
- PDFs
- documentation
- manuals
- Hybrid search (BM25 + embeddings)
- Reranking
- Streaming responses
- Multi-user authentication
- Conversation memory
- GPU acceleration
- Advanced metadata filtering
Developed by Venkatesh Integrated M.Tech AI VIT Bhopal University