Skip to content

chetnarathore10/AI-Knowledge-Base-Builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 AI Knowledge Base

A full-stack RAG (Retrieval-Augmented Generation) document assistant powered by FastAPI, React/Vite, Qdrant, and Google Gemini.

Upload PDF documents and ask natural-language questions — the AI retrieves relevant context from your documents and generates grounded answers.


🏗️ Architecture

React (Vite) ←→ FastAPI ←→ Qdrant (vector DB)
                   ↕
             Google Gemini API
             (embeddings + chat)

Pipeline:

  1. PDF → text extraction (PyMuPDF)
  2. Text → overlapping chunks
  3. Chunks → Gemini embeddings → Qdrant
  4. Query → embed → Qdrant semantic search → top-k chunks
  5. Chunks + query → Gemini LLM → grounded answer

📁 Project Structure

project/
├── backend/
│   ├── main.py              # FastAPI app entry point
│   ├── config.py            # Settings (pydantic-settings)
│   ├── requirements.txt
│   ├── Dockerfile
│   ├── .env.example
│   ├── routers/
│   │   ├── documents.py     # /upload-pdf, /documents, /document/{id}
│   │   └── chat.py          # /ask
│   └── services/
│       ├── pdf_service.py   # Extraction + chunking
│       ├── embedding_service.py  # Gemini embeddings
│       ├── vector_service.py     # Qdrant CRUD
│       └── rag_service.py        # RAG pipeline
├── frontend/
│   ├── src/
│   │   ├── App.jsx
│   │   ├── index.css
│   │   ├── components/
│   │   │   ├── ChatPanel.jsx
│   │   │   ├── UploadPanel.jsx
│   │   │   ├── DocumentList.jsx
│   │   │   └── Toast.jsx
│   │   └── services/api.js
│   ├── package.json
│   └── vite.config.js
└── docker-compose.yml

⚙️ Prerequisites

  • Python 3.11+
  • Node.js 18+
  • Docker Desktop (for Qdrant)
  • Google Gemini API keyGet one here

🚀 Setup & Running

Option A — Docker Compose (Recommended)

  1. Clone / open the project folder.

  2. Create backend .env:

    cp backend/.env.example backend/.env
    # Edit backend/.env and set GEMINI_API_KEY=your_key_here
  3. Start backend + Qdrant:

    docker-compose up --build
  4. Start the frontend:

    cd frontend
    npm install
    npm run dev

Option B — Manual / Local Dev

Backend

# 1. Start Qdrant via Docker
docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant

# 2. Set up Python env
cd backend
python -m venv venv

# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate

pip install -r requirements.txt

# 3. Create .env
copy .env.example .env
# Edit .env and add your GEMINI_API_KEY

# 4. Run backend
uvicorn main:app --reload --port 8000

Frontend

cd frontend
npm install
npm run dev

🔑 Environment Variables

Variable Default Description
GEMINI_API_KEY (required) Google Gemini API key
QDRANT_HOST localhost Qdrant host
QDRANT_PORT 6333 Qdrant port
COLLECTION_NAME knowledge_base Qdrant collection name
CHUNK_SIZE 800 Characters per chunk
CHUNK_OVERLAP 150 Character overlap between chunks
TOP_K 5 Number of chunks to retrieve per query
EMBEDDING_MODEL models/text-embedding-004 Gemini embedding model
CHAT_MODEL gemini-1.5-flash Gemini chat model

📡 API Endpoints

Method Endpoint Description
POST /upload-pdf Upload and process a PDF
POST /ask Ask a question (RAG)
GET /documents List all uploaded documents
DELETE /document/{doc_id} Delete a document's vectors
GET /health Health check

Interactive API docs: http://localhost:8000/docs


🧪 Usage

  1. Open http://localhost:5173
  2. Drag & drop a PDF onto the upload zone (or click to browse)
  3. Click Upload & Process — the PDF is chunked, embedded, stored in Qdrant
  4. Type your question in the chat box and press Enter
  5. The AI retrieves relevant chunks and returns a grounded answer with source citations
  6. Manage your documents in the sidebar — delete when no longer needed

🐳 Docker Notes

  • Qdrant data is persisted in a Docker volume (qdrant_storage) — your documents survive restarts.
  • When using Docker Compose, QDRANT_HOST is automatically set to qdrant (the service name). In local dev, it remains localhost.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors