# Granite RAG Agent A fully local Agentic RAG system powered by **IBM Granite 4.0 Micro** (loaded from HuggingFace) with **FAISS** for vector retrieval and **Tavily** for live web search. No paid LLM API required — only a free Tavily key. ## Architecture ``` User Query │ ▼ Granite 4.0 Micro (local, HuggingFace) │ ├── Tool: retriever → FAISS vector store (local, offline) └── Tool: tavily_search → Tavily web search (free API) │ ▼ Final Answer ``` - **LLM**: `ibm-granite/granite-4.0-micro` via `transformers` — runs on CPU, no GPU needed - **Embeddings**: `ibm-granite/granite-embedding-125m-english` — runs locally - **Vector Store**: FAISS — no server required, index stored on disk - **Web Search**: Tavily — free tier, 1000 searches/month --- ## Setup ### 1. Get a free Tavily API key 1. Go to [https://app.tavily.com](https://app.tavily.com) 2. Click **Sign Up** (free, no credit card needed) 3. Copy your API key from the dashboard ### 2. Configure environment ```bash cp .env.example .env ``` Open `.env` and replace `your_tavily_api_key_here` with your key: ``` TAVILY_API_KEY=tvly-xxxxxxxxxxxxxxxxxxxxxxxx ``` ### 3. Install dependencies ```bash pip install -r requirements.txt ``` ### 4. Build the knowledge base (one-time) This downloads tax-related documents from the web and builds a local FAISS index: ```bash python ingestion.py ``` A `faiss_index/` folder will be created in the current directory. ### 5. Run the API server ```bash uvicorn app:app --reload ``` Server starts at `http://localhost:8000` --- ## Usage ### Query via API ```bash curl -X POST http://localhost:8000/v1/query \ -H "Content-Type: application/json" \ -d '{"user_query": "What are the best tax deductions for self-employed people in 2026?"}' ``` ### Health check ```bash curl http://localhost:8000/health ``` ### Interactive docs Open `http://localhost:8000/docs` in your browser for the Swagger UI. --- ## Example queries - *"What are the best tax deductions for self-employed people in 2026?"* → uses `retriever` - *"What is the current gold price?"* → uses `tavily_search` - *"How does a backdoor Roth IRA work?"* → uses `retriever` - *"What happened in the stock market today?"* → uses `tavily_search` --- ## Project structure ``` agent/ ├── granite_agent.py # Core agent: model loading, tools, agentic loop ├── app.py # FastAPI server ├── ingestion.py # Builds the FAISS index from web sources ├── requirements.txt ├── .env.example # Environment variable template └── README.md ```