Add your description here
Project description
๐ค ROSRAG โ Robotics Retrieval-Augmented Generation Assistant
An intelligent robotics assistant that answers ROS2, drone, SLAM, and computer vision questions using a production-quality Retrieval-Augmented Generation (RAG) pipeline.
๐ Table of Contents
- Overview
- Architecture
- Project Structure
- Setup & Installation
- Running ROSRAG
- Example Queries & Output
- Configuration
- Extending the Knowledge Base
- Deployment
- Future Improvements
๐ฏ Overview
ROSRAG is a domain-specific AI assistant built on a Retrieval-Augmented Generation (RAG) architecture. Instead of relying solely on an LLM's parametric knowledge, ROSRAG:
- Retrieves the most relevant passages from a curated robotics knowledge base (ROS2 docs, drone manuals, SLAM research notes)
- Augments the LLM prompt with retrieved context
- Generates accurate, grounded, technically precise answers via Google Gemini
This approach drastically reduces hallucinations and keeps answers anchored to verified robotics documentation.
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ROSRAG Pipeline โ
โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ Knowledge โ โ Embedding โ โ FAISS Vector โ โ
โ โ Base JSON โโโโโถโ Layer โโโโโถโ Store (Index) โ โ
โ โ (data/) โ โ (MiniLM-L6) โ โ โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโ โ Top-K โ
โ โ User Query โ โโโโโโโโผโโโโโโโ โ
โ โ (CLI / UI) โโโโโโโโโโโโโโโโโโโโโโโโโโโถโ Retriever โ โ
โ โโโโโโโโโโโโโโโโ Query Embedding โโโโโโโโฌโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโ โ
โ โ Prompt Builder โ โ
โ โ System + Context + Query โ โ
โ โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโ โ
โ โ Google Gemini 1.5 Flash โ โ
โ โ (LLM Layer) โ โ
โ โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโ โ
โ โ Response + Source Citations โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Component Breakdown
| Component | File | Responsibility |
|---|---|---|
| Ingestion | src/ingestion.py |
Load JSON docs, clean text, chunk into passages |
| Embedding | src/embedding.py |
Convert text chunks to L2-normalized float32 vectors |
| Vector Store | src/vector_store.py |
FAISS IndexFlatIP build, save/load, similarity search |
| Retriever | src/retriever.py |
Embed query, search store, return ranked results |
| LLM | src/llm.py |
Prompt construction, Gemini API calls |
| Pipeline | src/rag_pipeline.py |
Orchestrates full flow, chat history, response struct |
| Utils | src/utils.py |
Logging, config loading, formatting helpers |
| CLI | app.py |
Interactive terminal interface with special commands |
| Web UI | streamlit_app.py |
Streamlit chat interface with source panel |
๐ Project Structure
rosrag/
โ
โโโ data/
โ โโโ knowledge.json # Primary robotics knowledge base
โ โโโ rosrag_index.faiss # (generated) FAISS vector index
โ โโโ rosrag_metadata.pkl # (generated) Document metadata
โ
โโโ src/
โ โโโ __init__.py
โ โโโ ingestion.py # Data loading, cleaning, chunking
โ โโโ embedding.py # SentenceTransformer embedding
โ โโโ vector_store.py # FAISS index management
โ โโโ retriever.py # Query โ context retrieval
โ โโโ llm.py # Gemini API + prompt engineering
โ โโโ rag_pipeline.py # Full pipeline orchestrator
โ โโโ utils.py # Logging, config, formatting
โ
โโโ logs/
โ โโโ rosrag.log # (generated) Application logs
โ
โโโ app.py # CLI entry point
โโโ streamlit_app.py # Streamlit web UI
โโโ requirements.txt # Python dependencies
โโโ config.json # Configuration file
โโโ README.md
โ๏ธ Setup & Installation
Prerequisites
- Python 3.10+
- Ubuntu 20.04 / 22.04 (or any Linux/macOS terminal)
- Google Gemini API key (get one here)
Step 1 โ Clone / Download the Project
git clone <your-repo-url> rosrag
cd rosrag
Step 2 โ Create a Virtual Environment
python3 -m venv venv
source venv/bin/activate
Step 3 โ Install Dependencies
pip install -r requirements.txt
โ ๏ธ First install may take a few minutes to download the embedding model (~90MB) and PyTorch.
Step 4 โ Set Your Gemini API Key
export GEMINI_API_KEY="your-gemini-api-key-here"
Add to ~/.bashrc for persistence:
echo 'export GEMINI_API_KEY="your-key-here"' >> ~/.bashrc
source ~/.bashrc
๐ Running ROSRAG
CLI Mode (Recommended)
python app.py
Options:
python app.py --rebuild # Force rebuild FAISS index from knowledge base
python app.py --debug # Enable verbose debug logging
python app.py --config path/to/config.json
python app.py --data path/to/custom_knowledge.json
CLI Commands during chat:
/help โ Show available commands
/history โ View conversation history
/clear โ Clear chat history
/sources โ Show sources from last answer
/quit โ Exit
Web UI Mode (Streamlit)
streamlit run streamlit_app.py
Then open http://localhost:8501 in your browser.
๐ฌ Example Queries & Output
Query 1: ROS2 Basics
You โฏ How do I create a publisher node in ROS2 Python?
๐ค ROSRAG:
To create a publisher node in ROS2 using Python (rclpy), follow these steps:
1. Import the required modules:
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
2. Create a class inheriting from Node:
class MyPublisher(Node):
def __init__(self):
super().__init__('my_publisher_node')
self.publisher_ = self.create_publisher(String, 'topic_name', 10)
timer_period = 0.5 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
def timer_callback(self):
msg = String()
msg.data = 'Hello ROS2!'
self.publisher_.publish(msg)
โโ Sources Retrieved โโโโโโโโโโโโโโโโโโโโโ
[1] ROS2 Documentation โ ROS2 Topics (score: 0.842)
[2] ROS2 Documentation โ ROS2 Nodes (score: 0.791)
โโ Latency: 1243ms โโโโโโโโโโโโโโโโโโโโโโโ
Query 2: SLAM
You โฏ What is SLAM and which algorithms are used with LiDAR?
๐ค ROSRAG:
SLAM (Simultaneous Localization and Mapping) is the process of building a map
of an unknown environment while simultaneously tracking the robot's location
within it...
[LiDAR SLAM algorithms include Cartographer, LOAM, LeGO-LOAM, LIO-SAM, KISS-ICP...]
Query 3: Drone Systems
You โฏ How does PX4 Offboard mode work with ROS2?
๐ค ROSRAG:
PX4 Offboard mode allows an external computer to control the drone by sending
setpoints at a minimum rate of 2Hz. In ROS2, you connect via the px4_msgs
package and micro-XRCE-DDS bridge...
๐ง Configuration
Edit config.json to customize behavior:
{
"data_path": "data/knowledge.json",
"index_path": "data/rosrag_index.faiss",
"meta_path": "data/rosrag_metadata.pkl",
"embed_model": "all-MiniLM-L6-v2",
"gemini_model": "gemini-1.5-flash",
"top_k": 5,
"min_score": 0.2,
"log_level": "INFO",
"log_file": "rosrag.log"
}
| Parameter | Default | Description |
|---|---|---|
top_k |
5 | Number of chunks to retrieve per query |
min_score |
0.2 | Minimum cosine similarity threshold (0โ1) |
gemini_model |
gemini-1.5-flash |
Gemini model variant |
embed_model |
all-MiniLM-L6-v2 |
SentenceTransformer model |
log_level |
INFO |
Logging verbosity |
๐ Extending the Knowledge Base
Add new knowledge entries to data/knowledge.json:
{
"id": "custom_001",
"source": "My Custom Notes",
"topic": "Custom Topic",
"content": "Your knowledge text here. Can be multiple sentences or paragraphs. The ingestion pipeline will chunk it automatically."
}
Then rebuild the index:
python app.py --rebuild
โ๏ธ Deployment
Local (Ubuntu)
source venv/bin/activate
export GEMINI_API_KEY="your-key"
python app.py # CLI
streamlit run streamlit_app.py # Web UI
Streamlit Cloud
- Push your project to a public GitHub repo
- Go to share.streamlit.io
- Connect your repo and set
streamlit_app.pyas the entry point - Add
GEMINI_API_KEYas a secret in the Streamlit Cloud dashboard
AWS EC2 (Ubuntu 22.04)
# Launch t3.medium instance, SSH in, then:
sudo apt update && sudo apt install python3-pip python3-venv -y
git clone <your-repo-url> rosrag && cd rosrag
python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
# Set API key
export GEMINI_API_KEY="your-key"
# Run CLI in background with tmux
tmux new-session -d -s rosrag 'python app.py'
# Or run Streamlit with nohup
nohup streamlit run streamlit_app.py --server.port 8501 --server.address 0.0.0.0 &
# Open EC2 security group port 8501
๐ฎ Future Improvements
| Feature | Priority | Description |
|---|---|---|
| Hybrid Search | High | Combine BM25 lexical search with dense retrieval |
| Re-ranking | High | Add cross-encoder re-ranking for improved precision |
| AWS S3 Integration | Medium | Load/save knowledge base and index from S3 |
| Multi-modal RAG | Medium | Support ingesting robot documentation PDFs |
| Streaming Responses | Medium | Stream Gemini output token-by-token in Streamlit |
| Docker Container | Medium | Containerize for one-command deployment |
| Query Expansion | Low | Use LLM to rephrase query before retrieval |
| Evaluation Suite | Low | Automated RAG evaluation with RAGAS metrics |
| Knowledge Graph | Low | Add entity relationship graph over robotics concepts |
๐ License
MIT License โ free to use, modify, and distribute.
๐ Credits
- Google Generative AI โ Gemini LLM
- Sentence Transformers โ Embedding model
- FAISS โ Facebook AI Similarity Search
- Streamlit โ Web UI framework
- ROS2 documentation, PX4 documentation, and robotics research community
Built as a production-grade engineering portfolio project demonstrating end-to-end RAG system design.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rosrag-0.1.0.tar.gz.
File metadata
- Download URL: rosrag-0.1.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c65e9dd07a121a72c08ac9e7c217b52b3d5615317710432b98558d897c35dde
|
|
| MD5 |
96c82bf3462e1a7934423d6ff452671a
|
|
| BLAKE2b-256 |
7f509cacc78ebb1a18b236cbf38de686f2fe0a61e80e3cce8b4deed8c5a94a98
|
File details
Details for the file rosrag-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rosrag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
772ab2f494083ea3d3cc8d9ebf06e4ef4b283344d902d571834d68847182e02d
|
|
| MD5 |
6efd4da8fe395937edd2127313d0402d
|
|
| BLAKE2b-256 |
e2fc384f21e26b42847016a1e4fcad5c4249b714aadc5df91887a4677c822fdf
|