A RAG pipeline specialized in African history and excellence
# Afrohistorian
An AI-powered assistant specialized in African history, built using Retrieval-Augmented Generation (RAG) with Pinecone vector database and OpenAI's GPT models.
## Overview
Afrohistorian is designed to provide accurate and detailed information about various aspects of African history, including significant events, cultural practices, historical figures, and more. The system uses semantic search to retrieve relevant historical documents and generates contextual responses using advanced language models.
## Features
- **Semantic Document Search**: Uses HuggingFace embeddings for intelligent document retrieval
- **RAG Architecture**: Combines retrieved context with GPT-3.5-turbo for accurate responses
- **PDF Processing**: Converts PDF documents to text with core content extraction
- **FastAPI Integration**: RESTful API for easy integration
- **Vector Database**: Utilizes Pinecone for efficient similarity search
## Architecture
```
PDF Documents → Text Extraction → Semantic Chunking → Vector Embeddings → Pinecone Storage
↓
User Query → Vector Search → Context Retrieval → GPT Response → Final Answer
```
## Installation
1. Clone the repository:
```bash
git clone
github.com
cd Afrohistorian
```
2. Create a virtual environment:
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
4. Set up environment variables by creating a `.env` file:
```env
OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=afrohistorian
```
## Usage
### Command Line Interface
Run the interactive CLI:
```bash
python main.py
```
### FastAPI Server
Start the API server:
```bash
uvicorn main:app --reload
```
The API will be available at `
localhost`
#### API Endpoints
- `GET /`: Welcome message
- `POST /ask`: Submit a query about African history
```json
{
"query": "What c …