Welcome to MYRAGAGENT, a project that implements a Retrieval-Augmented Generation (RAG) Agent using the swarmauri library and the Groq API from Groq, Inc. This agent combines a TF-IDF vector store for document retrieval with a conversational AI model to provide intelligent, context-aware responses based on personal details about the developer, Kosisochukwu. The project has evolved through multiple iterations, supporting local testing, interactive querying, and deployment via Docker on Northflank.
Key files include:
AgentKosiV1.py: Initial version of the RAG agent with basic document handling and query processing.AgentKosiV2.py: Enhanced and final version of the RAG agent, featuring large document chunking, session-based conversation management, an interactive query loop for local testing, and a FastAPI interface for deployment.RAG_Agent.ipynb: Jupyter Notebook for step-by-step development and testing of the RAG agent.RAG_Agent.py: Early standalone script that consolidates the functionality from the notebook.
The RAG agent answers queries about programming skills, database usage, deployment platforms, education, hobbies, and more, leveraging both document data and the Groq model's general knowledge.
- Document Management: Utilizes
TfidfVectorStorewith chunking for large texts, ensuring comprehensive context. - Conversational AI: Integrates the Groq API (
llama3-8b-8192model) for natural language responses. - Interactive Querying: Offers a local loop for continuous questioning and a web API endpoint.
- Scalability: Handles detailed personal profiles with overlapping chunks for better retrieval.
- Flexible Responses: Uses general knowledge when document data is unavailable, avoiding "not found" messages.
To run or deploy this project, you need:
- Python: Version 3.8 or higher (tested with 3.12).
- Dependencies (listed in
requirements.txt):swarmauri==0.4.1python-dotenv==1.0.1groq==0.26.0fastapi==0.115.12uvicorn==0.34.2scikit-learn==1.6.1joblib==1.5.1typing-extensions==4.13.2
- Groq API Key: Obtain from console.groq.com.
- Docker: For containerized deployment on Northflank.
- Jupyter Notebook (optional): For running
RAG_Agent.ipynb.
Install dependencies locally with:
pip install -r requirements.txt-
Clone the Repository:
git clone https://github.com/Ksschkw/MYRAGAGENT.git cd MYRAGAGENT -
Set Up Environment Variables:
- Create a
.envfile in the project root. - Add your Groq API key:
GROQ_API_KEY=your_groq_api_key_here
- Do not commit this file (add to
.gitignore).
- Create a
-
Install Dependencies: Run:
pip install -r requirements.txt
Activate your virtual environment (e.g.,
rag_env) if using one:.\rag_env\Scripts\activate
-
Prepare Documents:
- Documents are embedded in the code (e.g.,
documentslist inAgentKosiV2.py). - Modify or add large documents using the
chunk_documentfunction.
- Documents are embedded in the code (e.g.,
- Create a virtual environment:
python -m venv rag_env source rag_env/bin/activate # On Windows: rag_env\Scripts\activate pip install -r requirements.txt
- Add
rag_env/to.gitignoreto avoid committing it.
- Launch Jupyter:
jupyter notebook
- Open
RAG_Agent.ipynband execute cells to:- Initialize the vector store.
- Configure conversation context and integrate the Groq API.
- Test with sample queries.
-
Interactive Mode (AgentKosiV2.py):
- Run:
python AgentKosiV2.py
- Enter queries (e.g., "What languages does he write?"). Type
exitto quit. - Example Output:
Welcome to the RAG Agent! Type 'exit' to quit. Enter your query: What languages does he write? Query: What languages does he write? RAG Agent Response: Kosisochukwu writes Python, a little JavaScript, and a little Rust.
- Run:
-
Server Mode (AgentKosiV2.py):
- Run:
python AgentKosiV2.py --server
- Access via
http://localhost:5000/query/What+languages+does+he+write?. - Example Response:
{"query": "What languages does he write?", "response": "Kosisochukwu writes Python, a little JavaScript, and a little Rust."}
- Run:
-
Basic Mode (AgentKosiV1.py):
- Run:
python AgentKosiV1.py
- Processes predefined queries and prints responses.
- Run:
-
Local Testing with
TestClient:- The interactive loop in
AgentKosiV2.pyuses FastAPI’sTestClientto simulate HTTP requests, allowing you to test the API locally without starting a server.
- The interactive loop in
The application is deployed and accessible online:
-
API Endpoint: Query the RAG agent directly at https://p01--myragagent--qw5xhkblp8hy.code.run/query/{query}. Replace
{query}with your question. For example: -
Web GUI: Access the interactive interface at https://agentkosi.onrender.com/. Enter your queries in the provided input field to interact with the RAG agent.
- "What languages does he write?"
- "What database does he use?"
- "Where is he from?"
- "What is his GitHub?"
- "What does he study?" (e.g., software engineering)
- "Does he containerize his applications?" (e.g., yes, with Docker)
AgentKosiV1.py: Initial RAG agent implementation with basic functionality.AgentKosiV2.py: Enhanced version with chunking, session management, interactive loop, and FastAPI.RAG_Agent.ipynb: Notebook for development and testing.RAG_Agent.py: Early standalone script.start.sh: Shell script to start the FastAPI server for deployment.Dockerfile: Configuration for containerizing the application..env: Local environment file (not committed).requirements.txt: Dependency list.README.md: This documentation.
This project is containerized for deployment on Northflank using Docker. Follow these steps:
-
Prepare Files:
- Ensure
Dockerfile,start.sh, andrequirements.txtare in the project root. - Add
GROQ_API_KEYas a Northflank secret.
- Ensure
-
Build and Test Locally:
- Build the Docker image:
docker build -t rag-agent-kosi . - Run the container:
docker run -p 5000:5000 -e GROQ_API_KEY=your-api-key-here rag-agent-kosi
- Test at
http://localhost:5000/query/What+languages+does+he+write?.
- Build the Docker image:
-
Push to GitHub:
- Commit and push:
git add . git commit -m "Prepare for Northflank deployment" git push origin main
- Commit and push:
-
Northflank Setup:
- Log in to northflank.com.
- Create a project (e.g.,
MYRAGAGENT). - Add a service: "Container Image" > "Build from Git repository".
- Configure:
- Point to the
Dockerfile. - Expose port 5000.
- Add secret:
GROQ_API_KEYwith your API key.
- Point to the
- Deploy and test the provided URL.
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt \
&& rm -rf /root/.cache/pip
COPY . .
ENV GROQ_API_KEY=${GROQ_API_KEY}
CMD ["sh", "start.sh"]__pycache__
*.pyc
*.py[cod]
*$py.class
.env
.rag_env/
.git
.gitignore
.vscode/
Contributions are welcome! Please:
- Fork the repository.
- Create a feature branch (
git checkout -b feature-name). - Commit changes (
git commit -m "Add feature-name"). - Push and open a pull request.
Report issues or suggest enhancements via GitHub Issues at https://github.com/Ksschkw/MYRAGAGENT.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or feedback, contact Kosisochukwu via:
- GitHub: github.com/Ksschkw
- WhatsApp: +2349019549473 (include context when messaging).
- Session Persistence: Store session data in a database (e.g., SQLite) for long-term conversation history.
- Improved Chunking: Experiment with different chunk sizes or overlap strategies for better retrieval accuracy.
- Multi-Model Support: Allow switching between different Groq models dynamically.