This project demonstrates how to build a local Retrieval-Augmented Generation (RAG) AI agent using Python. The agent runs entirely on your machine and leverages:
- Ollama for open-source LLMs and embeddings
- LangChain for orchestration
- SingleStore as the vector store
By the end we'll have a working Q&A system powered by the local data and models.
Ensure the following are installed and configured:
- Docker (running)
- Python 3.9+
- Ollama installed and working
- Visit ollama.com and download the installer for your OS
- Follow the on-screen instructions
- Download the required models by running:
ollama serve ollama pull llama3 ollama pull mxbai-embed-large
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
The project uses a CSV file (pizza_reviews.csv
) containing pizza reviews. The file should have the following columns:
- Title
- Date
- Rating
- Review
The Python script will automatically start a SingleStore instance using Docker. Just make sure Docker is running.
Start the application from the command line:
python3 main.py
Once running, you can ask questions about the pizza reviews. For example:
Enter your question about pizza (or 'exit' to quit): What do people think about the crust?
The system will:
- Find relevant reviews using vector similarity search
- Use the LLaMA model to generate an answer based on those reviews
.
├── README.md
├── requirements.txt
├── main.py
└── pizza_reviews.csv
The project uses the following main dependencies:
- langchain
- langchain-ollama
- langchain-singlestore
- singlestoredb
- pandas
- docker
Feel free to experiment with:
- Different LLMs or embedding models via Ollama
- Other datasets
- Custom prompt templates
- Adjusting the number of retrieved reviews (currently set to 2)
This project is licensed under the MIT License - see the LICENSE file for details.
This project is based on the tutorial "Build a Local AI Agent with Python, Ollama, LangChain and SingleStore" by Volodymyr Tkachuk, Engineering Manager at SingleStore. Original tutorial can be found at: SingleStore Blog.