Skip to main content

Add your description here

Project description

๐Ÿค– ROSRAG โ€” Robotics Retrieval-Augmented Generation Assistant

Python LLM VectorDB Embeddings UI

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

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:

  1. Retrieves the most relevant passages from a curated robotics knowledge base (ROS2 docs, drone manuals, SLAM research notes)
  2. Augments the LLM prompt with retrieved context
  3. 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

  1. Push your project to a public GitHub repo
  2. Go to share.streamlit.io
  3. Connect your repo and set streamlit_app.py as the entry point
  4. Add GEMINI_API_KEY as 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


Built as a production-grade engineering portfolio project demonstrating end-to-end RAG system design.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rosrag-0.1.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rosrag-0.1.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

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

Hashes for rosrag-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3c65e9dd07a121a72c08ac9e7c217b52b3d5615317710432b98558d897c35dde
MD5 96c82bf3462e1a7934423d6ff452671a
BLAKE2b-256 7f509cacc78ebb1a18b236cbf38de686f2fe0a61e80e3cce8b4deed8c5a94a98

See more details on using hashes here.

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

Hashes for rosrag-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 772ab2f494083ea3d3cc8d9ebf06e4ef4b283344d902d571834d68847182e02d
MD5 6efd4da8fe395937edd2127313d0402d
BLAKE2b-256 e2fc384f21e26b42847016a1e4fcad5c4249b714aadc5df91887a4677c822fdf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page