This is a Retrieval-Augmented Generation (RAG) agent API built with FastAPI, leveraging OpenAI's language models and ChromaDB for document embedding and retrieval.
- Create document collections
- Semantic search across document collections
- AI-powered response generation using context retrieval
- Python 3.9+
- OpenAI API Key
- Clone the repository
- Create a virtual environment
python3 -m venv venv
source venv/bin/activate
- Install dependencies
pip install -r requirements.txt
- Set up environment variables
- Copy
.env.example
to.env
- Add your OpenAI API Key
uvicorn src.rag_agent.main:app --reload
/create_collection
: Add documents to a collection/query
: Retrieve context and generate AI responses/health
: Check application health
import requests
# Create a collection
create_response = requests.post('http://localhost:8000/create_collection', json={
'collection_name': 'my_documents',
'documents': ['Sample document 1', 'Sample document 2']
})
# Query the collection
query_response = requests.post('http://localhost:8000/query', json={
'collection_name': 'my_documents',
'query': 'What is the main topic?'
})
Customize settings in .env
:
OPENAI_API_KEY
: Your OpenAI API keyMISTRAL_API_KEY
: Your Mistral AI API keyMODEL_PROVIDER
: Choose between 'openai' or 'mistral'EMBEDDING_MODEL
: Sentence transformer modelCHROMA_DB_PATH
: Vector database storage path
The RAG agent supports two LLM providers:
-
OpenAI
- Default model: gpt-3.5-turbo
- Requires OPENAI_API_KEY
-
Mistral AI
- Default model: mistral-tiny
- Other options: mistral-small, mistral-medium
- Requires MISTRAL_API_KEY
To switch between providers, set MODEL_PROVIDER in .env to either 'openai' or 'mistral'.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request