Sherwinj10/ai-knowledge-base
0
AI Knowledge Base Agent
An intelligent document assistant capable of ingesting, retrieving, and answering questions from PDF and Text documents using Retrieval-Augmented Generation (RAG) with session memory.
Overview
The AI Knowledge Base Agent is designed to bridge the gap between static documents and dynamic information retrieval. By leveraging RAG, it allows users to upload PDF or Text documents and ask natural language questions about them.
Unlike generic AI models, this agent grounds its answers strictly in the provided content, ensuring accuracy and relevance for specific use cases like HR policies, technical manuals, or legal contracts.
Features & Limitations
Features
- Document Ingestion: Supports PDF and TXT files using LangChain's
PyPDFLoaderandTextLoader. - Context-Aware Answers: Uses RAG to retrieve relevant document chunks for accurate answering.
- Structured Output: Answers are formatted with bullet points, a summary, and confidence levels.
- Source Citations: Provides transparency by citing the specific document chunks used.
- Local Privacy: Uses local HuggingFace embeddings (
all-MiniLM-L6-v2) to generate vectors on your machine. - Modern UI: Built with a clean HTML/JS Frontend and a fast FastAPI Backend.
- Cost-Effective: Uses Google Gemini 2.5 Flash for high-speed, low-cost inference.
Limitations
- Text-Only Analysis: Currently extracts text only; does not process images or tables within PDFs (no OCR).
- Single File Upload: Optimized for processing one file at a time.
- Session Memory: Chat history is session-based and clears when you refresh the page.
Tech Stack & APIs Used
- Frontend: HTML, CSS, JavaScript (Vanilla)
- Backend: FastAPI (Python)
- Ingestion: LangChain (PyPDFLoader, TextLoader)
- LLM: Google Gemini 2.5 Flash (via
langchain-google-genai) - Embeddings: HuggingFace
all-MiniLM-L6-v2(Local execution) - Vector Database: ChromaDB (Local persistence)
Setup & Run Instructions
Prerequisites
- Python 3.10 or higher
- A Google Cloud API Key (for Gemini)
Installation
- Clone the Repository
git clone <your-repo-url>
cd AI_Knowledge_Base_Agent- Create a Virtual Environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install Dependencies
pip install -r backend/requirements.txt- Set Up Environment Variables Create a
.envfile inbackend/.envand add your API key:
GOOGLE_API_KEY=your_google_keyRunning the App
- Start the Backend Server:
uvicorn backend.main:app --reload- Access the App: Open your browser and navigate to
http://localhost:8000.
Potential Improvements
- Multi-File Support: Allow uploading entire folders or multiple PDFs at once.
- OCR Integration: Add support for scanned documents and images using Tesseract or specialized models.
- Chat History Persistence: Save chat history to a database (SQLite/Postgres).
- Docker Support: Containerize the application for easier deployment.
Architecture Diagram
graph TD
subgraph Ingestion
A[PDF TXT Document] -->|PyPDFLoader TextLoader| B(Raw Text)
B -->|RecursiveSplitter| C[Text Chunks]
end
subgraph Embedding_Storage
C -->|HuggingFace Embeddings| D[(ChromaDB)]
end
subgraph Retrieval_Generation
E[User Query] -->|Embed| F[Query Embedding]
F -->|Vector Search| D
D -->|Retrieve Top k| G[Relevant Context]
G -->|Context plus Query| H[Gemini 25 Flash]
H -->|Generate| I[Structured Answer]
end
subgraph UI
J[Frontend HTML JS] -->|API| K[Backend FastAPI]
K --> J
K --> H
H --> K
end