Skip to content

gajjarkav/rag-coder

Repository files navigation

RAG-Coder 🤖📚

A simple AI coding agent that combines Retrieval-Augmented Generation (RAG) with file writing capabilities. It can search through your documentation and generate code files based on your requests.

What is this? 🤔

This is a basic RAG-powered AI agent that:

  • 📖 Reads documents from a docs/ folder
  • 🔍 Searches through them using vector embeddings
  • 💬 Answers questions based on the documentation
  • 📝 Writes code files to a workplace/ directory
  • 🧠 Uses LangChain + ChromaDB for RAG functionality

What it's NOT:

  • Not a production-ready tool
  • Not optimized for large-scale use
  • Just a learning project for RAG + agents

Project Structure 📁

rag-coder/
├── agent.py           # Loads documents from docs/ folder
├── config.py          # Configuration using pydantic-settings
├── llm.py            # LLM provider setup (OpenRouter or Groq)
├── main.py           # Main entry point with agent loop
├── tools.py          # Agent tools (write files, search docs)
├── vectorstore.py    # ChromaDB vector store setup
├── docs/             # Put your .txt or .md files here
├── workplace/        # Generated files go here
└── .chromadb/        # Vector database (auto-created)

Prerequisites 📋

  • Python 3.9+
  • OpenRouter API key OR Groq API key
  • Basic understanding of virtual environments

Installation 🛠️

1. Clone or download this project

cd rag-coder

2. Create a virtual environment

Windows:

python -m venv .venv
.venv\Scripts\activate

Linux/Mac:

python3 -m venv .venv
source .venv/bin/activate

3. Install dependencies

pip install langchain langchain-community langchain-openai langchain-groq langchain-huggingface
pip install chromadb
pip install pydantic-settings
pip install langchain-text-splitters

4. Create a .env file

Create a file named .env in the project root:

For OpenRouter: (Get your API key from https://openrouter.ai/keys)

OPEN_ROUTER_API_KEY=your_openrouter_api_key_here
OPENROUTER_URL_BASE=https://openrouter.ai/api/v1
LLM_MODEL_NAME=meta-llama/llama-3.1-8b-instruct:free

For Groq: (Get your API key from https://console.groq.com/keys)

GROQ_API_KEY=your_groq_api_key_here
LLM_MODEL_NAME=llama3-8b-8192

How to Use 🚀

1. Add documents to the RAG system

Put your .txt or .md files in the docs/ folder:

# Example: Create a document
echo "Python is a programming language" > docs/python_info.txt

The agent will load these documents on startup and use them to answer questions.

2. Run the agent

python main.py

3. Interact with the agent

Ask questions about your docs:

🧑 You: What is Python?

The agent will search the docs and answer based on the content.

Generate code files:

🧑 You: Write a hello world program in Python

The agent will create the file in the workplace/ directory.

Exit:

🧑 You: exit

Adding New Documents to RAG 📄

Step 1: Create your document

Put any .txt or .md file in the docs/ folder:

docs/
├── test.txt
├── my_notes.md
└── project_info.txt

Step 2: Restart the agent

The documents are loaded when you run python main.py. Just restart to load new docs.

Step 3: Ask questions

The agent will automatically search through all documents when you ask questions.

Example:

# Add this to docs/kavy.txt
Name: Kavy Gajjar
Email: gajjarkav@gmail.com
Website: https://kavy.dev

Then ask:

🧑 You: Who is Kavy Gajjar?

The agent will search the docs and provide the information.

How It Works 🔧

  1. Document Loading (agent.py):

    • Scans docs/ folder for .txt and .md files
    • Splits documents into chunks (800 chars, 100 overlap)
    • Uses HuggingFace embeddings (all-MiniLM-L6-v2)
  2. Vector Store (vectorstore.py):

    • Creates ChromaDB vector database
    • Stores document embeddings
    • Provides similarity search retriever
  3. Agent (main.py):

    • Uses LangChain agents with tool calling
    • Has 2 tools: search_documentation and write_files
    • Decides when to search docs or write files
  4. LLM Provider (llm.py):

    • Supports OpenRouter or Groq
    • Reads API key from .env file

Limitations ⚠️

  • 🐌 Slow document loading on first run
  • 📦 Limited to small document sets (not optimized)
  • 🔄 Requires restart to load new documents
  • 🎯 Basic tool calling (no advanced features)
  • 🗂️ No document management UI
  • ⚡ Not async (blocking operations)

Troubleshooting 🔨

"No LLM API key found"

  • Check your .env file exists
  • Verify the API key variable names match

"VectorStoreRetriever object has no attribute..."

  • Update LangChain packages: pip install --upgrade langchain langchain-community

"Loaded 0 documents"

  • Make sure you have .txt or .md files in the docs/ folder

"Error: write_file() missing argument"

  • This should be fixed with StructuredTool. If not, reinstall langchain-core

Tech Stack 💻

  • LangChain - Agent framework
  • ChromaDB - Vector database
  • HuggingFace - Embeddings (all-MiniLM-L6-v2)
  • OpenRouter/Groq - LLM providers
  • Pydantic - Settings management

Future Improvements (maybe) 🚧

  • Auto-reload documents without restart
  • Support for PDF, DOCX files
  • Better error handling
  • Document metadata tracking
  • Multiple workspace folders
  • Web interface
  • Chat history persistence

License 📜

Do whatever you want with this code. No warranty, no guarantees.

Author ✍️

Made by someone learning RAG and AI agents.


Note: This is a learning project. Don't use it for anything important without proper testing and improvements.

RAG-Coder 🤖📚

A simple AI coding agent that combines Retrieval-Augmented Generation (RAG) with file writing capabilities. It can search through your documentation and generate code files based on your requests.

What is this? 🤔

This is a basic RAG-powered AI agent that:

  • 📖 Reads documents from a docs/ folder
  • 🔍 Searches through them using vector embeddings
  • 💬 Answers questions based on the documentation
  • 📝 Writes code files to a workplace/ directory
  • 🧠 Uses LangChain + ChromaDB for RAG functionality

What it's NOT:

  • Not a production-ready tool
  • Not optimized for large-scale use
  • Just a learning project for RAG + agents

Project Structure 📁

rag-coder/
├── agent.py           # Loads documents from docs/ folder
├── config.py          # Configuration using pydantic-settings
├── llm.py            # LLM provider setup (OpenRouter or Groq)
├── main.py           # Main entry point with agent loop
├── tools.py          # Agent tools (write files, search docs)
├── vectorstore.py    # ChromaDB vector store setup
├── docs/             # Put your .txt or .md files here
├── workplace/        # Generated files go here
└── .chromadb/        # Vector database (auto-created)

Prerequisites 📋

Installation 🛠️

1. Clone or download this project

cd rag-coder

2. Create a virtual environment

Windows:

python -m venv .venv
.venv\Scripts\activate

Linux/Mac:

python3 -m venv .venv
source .venv/bin/activate

3. Install dependencies

pip install langchain langchain-community langchain-openai langchain-groq langchain-huggingface
pip install chromadb
pip install pydantic-settings
pip install langchain-text-splitters

4. Create a .env file

Create a file named .env in the project root:

For OpenRouter:

OPEN_ROUTER_API_KEY=your_openrouter_api_key_here
OPENROUTER_URL_BASE=https://openrouter.ai/api/v1
LLM_MODEL_NAME=meta-llama/llama-3.1-8b-instruct:free

For Groq:

GROQ_API_KEY=your_groq_api_key_here
LLM_MODEL_NAME=llama3-8b-8192

How to Use 🚀

1. Add documents to the RAG system

Put your .txt or .md files in the docs/ folder:

# Example: Create a document
echo "Python is a programming language" > docs/python_info.txt

The agent will load these documents on startup and use them to answer questions.

2. Run the agent

python main.py

3. Interact with the agent

Ask questions about your docs:

🧑 You: What is Python?

The agent will search the docs and answer based on the content.

Generate code files:

🧑 You: Write a hello world program in Python

The agent will create the file in the workplace/ directory.

Exit:

🧑 You: exit

Adding New Documents to RAG 📄

Step 1: Create your document

Put any .txt or .md file in the docs/ folder:

docs/
├── test.txt
├── my_notes.md
└── project_info.txt

Step 2: Restart the agent

The documents are loaded when you run python main.py. Just restart to load new docs.

Step 3: Ask questions

The agent will automatically search through all documents when you ask questions.

Example:

# Add this to docs/kavy.txt
Name: Kavy Gajjar
Email: gajjarkav@gmail.com
Website: https://kavy.dev

Then ask:

🧑 You: Who is Kavy Gajjar?

The agent will search the docs and provide the information.

How It Works 🔧

  1. Document Loading (agent.py):

    • Scans docs/ folder for .txt and .md files
    • Splits documents into chunks (800 chars, 100 overlap)
    • Uses HuggingFace embeddings (all-MiniLM-L6-v2)
  2. Vector Store (vectorstore.py):

    • Creates ChromaDB vector database
    • Stores document embeddings
    • Provides similarity search retriever
  3. Agent (main.py):

    • Uses LangChain agents with tool calling
    • Has 2 tools: search_documentation and write_files
    • Decides when to search docs or write files
  4. LLM Provider (llm.py):

    • Supports OpenRouter or Groq
    • Reads API key from .env file

Limitations ⚠️

  • 🐌 Slow document loading on first run
  • 📦 Limited to small document sets (not optimized)
  • 🔄 Requires restart to load new documents
  • 🎯 Basic tool calling (no advanced features)
  • 🗂️ No document management UI
  • ⚡ Not async (blocking operations)

Troubleshooting 🔨

"No LLM API key found"

  • Check your .env file exists
  • Verify the API key variable names match

"VectorStoreRetriever object has no attribute..."

  • Update LangChain packages: pip install --upgrade langchain langchain-community

"Loaded 0 documents"

  • Make sure you have .txt or .md files in the docs/ folder

"Error: write_file() missing argument"

  • This should be fixed with StructuredTool. If not, reinstall langchain-core

Tech Stack 💻

  • LangChain - Agent framework
  • ChromaDB - Vector database
  • HuggingFace - Embeddings (all-MiniLM-L6-v2)
  • OpenRouter/Groq - LLM providers
  • Pydantic - Settings management

License 📜

Do whatever you want with this code. No warranty, no guarantees.

Author ✍️

Made by KavyGajjar


Note: This is a learning project. Don't use it for anything important without proper testing and improvements.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages