From e2c2813ce0070d70e161c86a55f9cc203baa9456 Mon Sep 17 00:00:00 2001 From: Madhu Date: Sun, 2 Feb 2025 01:05:57 +0530 Subject: [PATCH] full agentic rag code done with gemini --- .../ai_gemini_thinking_agent/README.md | 0 .../ai_gemini_thinking_agent/requirements.txt | 0 rag_tutorials/gemini_agentic_rag/README.md | 90 +++++++++++++++++++ .../gemini_agentic_rag/agentic_rag_gemini.py | 6 +- .../gemini_agentic_rag/requirements.txt | 6 ++ 5 files changed, 99 insertions(+), 3 deletions(-) delete mode 100644 ai_agent_tutorials/ai_gemini_thinking_agent/README.md delete mode 100644 ai_agent_tutorials/ai_gemini_thinking_agent/requirements.txt create mode 100644 rag_tutorials/gemini_agentic_rag/README.md rename ai_agent_tutorials/ai_gemini_thinking_agent/main.py => rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py (97%) create mode 100644 rag_tutorials/gemini_agentic_rag/requirements.txt diff --git a/ai_agent_tutorials/ai_gemini_thinking_agent/README.md b/ai_agent_tutorials/ai_gemini_thinking_agent/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/ai_agent_tutorials/ai_gemini_thinking_agent/requirements.txt b/ai_agent_tutorials/ai_gemini_thinking_agent/requirements.txt deleted file mode 100644 index e69de29..0000000 diff --git a/rag_tutorials/gemini_agentic_rag/README.md b/rag_tutorials/gemini_agentic_rag/README.md new file mode 100644 index 0000000..0042f11 --- /dev/null +++ b/rag_tutorials/gemini_agentic_rag/README.md @@ -0,0 +1,90 @@ +# Agentic RAG with Gemini Thinking ⌘G + +A RAG Agentic system built with the new Gemini 2.0 Flash Thinking model and gemini-exp-1206, Qdrant for vector storage, and Agno (phidata prev) for agent orchestration. This application features intelligent query rewriting, document processing, and web search fallback capabilities to provide comprehensive AI-powered responses. + +## Features + +- **Document Processing** + - PDF document upload and processing + - Web page content extraction + - Automatic text chunking and embedding + - Vector storage in Qdrant cloud + +- **Intelligent Querying** + - Query rewriting for better retrieval + - RAG-based document retrieval + - Similarity search with threshold filtering + - Automatic fallback to web search + - Source attribution for answers + +- **Advanced Capabilities** + - Exa AI web search integration + - Custom domain filtering for web search + - Context-aware response generation + - Chat history management + - Query reformulation agent + +- **Model Specific Features** + - Gemini Thinking 2.0 Flash for chat and reasoning + - Gemini Embedding model for vector embeddings + - Agno Agent framework for orchestration + - Streamlit-based interactive interface + +## Prerequisites + +### 1. Google API Key +1. Go to [Google AI Studio](https://aistudio.google.com/apikey) +2. Sign up or log in to your account +3. Create a new API key + +### 2. Qdrant Cloud Setup +1. Visit [Qdrant Cloud](https://cloud.qdrant.io/) +2. Create an account or sign in +3. Create a new cluster +4. Get your credentials: + - Qdrant API Key: Found in API Keys section + - Qdrant URL: Your cluster URL (format: `https://xxx-xxx.cloud.qdrant.io`) + +### 3. Exa AI API Key (Optional) +1. Visit [Exa AI](https://exa.ai) +2. Sign up for an account +3. Generate an API key for web search capabilities + +## How to Run + +1. Clone the repository: +```bash +git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git +cd rag_tutorials/gemini_agentic_rag +``` + +2. Install dependencies: +```bash +pip install -r requirements.txt +``` + +3. Run the application: +```bash +streamlit run agentic_rag_gemini.py +``` + +## Usage + +1. Configure API keys in the sidebar: + - Enter your Google API key + - Add Qdrant credentials + - (Optional) Add Exa AI key for web search + +2. Upload documents: + - Use the file uploader for PDFs + - Enter URLs for web content + +3. Ask questions: + - Type your query in the chat interface + - View rewritten queries and sources + - See web search results when relevant + +4. Manage your session: + - Clear chat history as needed + - Configure web search domains + - Monitor processed documents diff --git a/ai_agent_tutorials/ai_gemini_thinking_agent/main.py b/rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py similarity index 97% rename from ai_agent_tutorials/ai_gemini_thinking_agent/main.py rename to rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py index 22583a3..dac188f 100644 --- a/ai_agent_tutorials/ai_gemini_thinking_agent/main.py +++ b/rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py @@ -36,11 +36,11 @@ class GeminiEmbedder(Embeddings): # Constants -COLLECTION_NAME = "indecisive" +COLLECTION_NAME = "gemini-thinking-agent-agno" # Streamlit App Initialization -st.title("🤖 AI Agent with Gemini & Qdrant RAG") +st.title("🤖 Agentic RAG with Gemini Thinking and Agno") # Session State Initialization if 'google_api_key' not in st.session_state: @@ -313,7 +313,7 @@ if st.session_state.google_api_key: agent = Agent( name="Gemini RAG Agent", model=Gemini(id="gemini-2.0-flash-thinking-exp-01-21"), - instructions="You are AGI. You are an elite specialist in all fields and an expert in all fields. Answer user's questions clearly, if any document is added, Use retrieved documents to answer questions accurately.", + instructions="You are an Intelligent Agent. You are an elite specialist and an expert in all fields. Answer user's questions clearly, if any document is added, Use retrieved documents to answer questions accurately.", show_tool_calls=True, markdown=True, ) diff --git a/rag_tutorials/gemini_agentic_rag/requirements.txt b/rag_tutorials/gemini_agentic_rag/requirements.txt new file mode 100644 index 0000000..1ac2d62 --- /dev/null +++ b/rag_tutorials/gemini_agentic_rag/requirements.txt @@ -0,0 +1,6 @@ +agno +exa==0.5.26 +qdrant-client==1.12.1 +langchain-qdrant==0.2.0 +langchain-community==0.3.13 +streamlit==1.41.1 \ No newline at end of file