Intelligent document search powered by Agentic RAG & LangGraph
π Live Demo β’ Features β’ Installation β’ Usage β’ Architecture β’ Troubleshooting
- Overview
- Features
- Architecture
- Prerequisites
- Installation
- Configuration
- Usage
- How It Works
- Project Structure
- Troubleshooting
- Contributing
- License
AI Blog Search is a sophisticated Retrieval-Augmented Generation (RAG) application that enables intelligent question-answering over web documents. Built with LangGraph and LangChain, it uses an agentic workflow to retrieve, evaluate, and generate accurate responses from indexed blog content.
π Try it now: Live Demo
- π§ Agentic RAG: Uses LangGraph to orchestrate intelligent retrieval and generation workflows
- π Smart Retrieval: Automatically evaluates document relevance and rewrites queries when needed
- πΎ Local Storage: Uses ChromaDB for free, persistent vector storage
- π¨ Modern UI: Beautiful Streamlit interface with gradient designs
- β‘ Fast & Efficient: Optimized document processing and retrieval
- π Document Indexing: Add any blog URL to create a searchable knowledge base
- π Intelligent Search: Ask natural language questions about indexed content
- π€ Agentic Workflow:
- Automatic query understanding
- Document relevance scoring
- Query rewriting for better results
- Context-aware answer generation
- π¬ Natural Language Interface: Ask questions in plain English
- π Persistent Storage: Documents are stored locally and persist between sessions
- Vector Embeddings: Uses Google Gemini embeddings for semantic search
- Chunking Strategy: Intelligent text splitting with overlap for context preservation
- Relevance Grading: LLM-powered document relevance assessment
- Query Transformation: Automatic query improvement for better retrieval
βββββββββββββββββββ
β User Query β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Agent Node β βββΊ Decides to retrieve or end
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Retrieve Node β βββΊ Searches vector database
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Grade Node β βββΊ Evaluates document relevance
ββββββββββ¬βββββββββ
β
ββββββ΄βββββ
β β
βΌ βΌ
ββββββββββ ββββββββββββ
βGenerateβ β Rewrite β βββΊ Improves query if docs irrelevant
ββββββββββ ββββββββββββ
β
βΌ
βββββββββββββββ
β Answer β
βββββββββββββββ
- Agent Node: Decides whether to retrieve documents or end the workflow
- Retrieve Node: Searches the ChromaDB vector store using semantic similarity
- Grade Node: Evaluates if retrieved documents are relevant to the query
- Rewrite Node: Transforms queries to improve retrieval when documents are irrelevant
- Generate Node: Creates final answers using retrieved context
Before you begin, ensure you have:
- Python 3.8+ installed on your system
- Google Gemini API Key (Get one here)
- pip package manager
git clone <your-repo-url>
cd rag# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtpython -c "import streamlit; import langchain; print('Installation successful!')"-
Get your Gemini API Key:
- Visit Google AI Studio
- Sign in with your Google account
- Create a new API key
- Copy the API key
-
Configure in the App:
- Run the application (see Usage section)
- Open the sidebar
- Enter your Gemini API key
- Click "Save API Key"
β οΈ Security Note: Never commit your API keys to version control. Consider using environment variables for production deployments.
π Access the deployed application - No installation required!
Simply visit the link above, enter your Gemini API key, and start using the application.
streamlit run app.pyThe application will open in your default web browser at http://localhost:8501
- Open the sidebar (click the
>icon) - Enter your Gemini API key
- Click "πΎ Save API Key"
- Enter a blog URL in the "Add Documents" section
- Click "β Add"
- Wait for the documents to be processed and indexed
- You'll see a success message when complete
- Type your question in the "Ask Questions" section
- Click "π Search"
- Wait for the AI to process and retrieve relevant information
- View the answer displayed in a styled box
# 1. Add a blog post
URL: https://example.com/blog-post
# 2. Ask questions
Question: "What are the main concepts discussed in this blog?"
Answer: [AI-generated response based on the content]
Question: "Can you summarize the key takeaways?"
Answer: [Contextual summary from the indexed documents]- Loading: WebBaseLoader fetches content from the provided URL
- Splitting: RecursiveCharacterTextSplitter divides content into chunks (100 tokens with 50 token overlap)
- Embedding: Google Gemini embeddings convert text chunks into vectors
- Storage: Vectors are stored in ChromaDB with unique IDs
- Query Input: User submits a natural language question
- Agent Decision: LangGraph agent decides if retrieval is needed
- Retrieval: Vector similarity search finds relevant document chunks
- Relevance Check: LLM evaluates if retrieved documents are relevant
- Query Rewrite (if needed): If documents aren't relevant, query is improved
- Generation: Final answer is generated using relevant context
- LangChain: Framework for building LLM applications
- LangGraph: State machine for orchestrating agent workflows
- ChromaDB: Open-source vector database for embeddings
- Google Gemini: LLM for embeddings and chat completions
- Streamlit: Web framework for the user interface
rag/
β
βββ app.py # Main application file
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ chroma_db/ # ChromaDB storage (created automatically)
β βββ ... # Vector database files
β
βββ .gitignore # Git ignore file (recommended)
app.py: Contains all application logic, UI components, and LangGraph workflowrequirements.txt: Lists all Python package dependencieschroma_db/: Directory where ChromaDB stores vector embeddings (auto-created)
Solution: Ensure all dependencies are installed
pip install -r requirements.txtSolution:
- Verify your Gemini API key is correct
- Check if the API key has proper permissions
- Ensure you've saved the key in the sidebar
Solution:
# Clear the chroma_db directory and restart
rm -rf chroma_db/
# Then restart the appSolution:
- Verify the URL is accessible
- Check if the website blocks web scrapers
- Try a different URL format
Solution:
- Ensure documents have been added successfully
- Try rephrasing your question
- Check if the content is relevant to your query
- Chunk Size: Adjust
chunk_sizeandchunk_overlapinadd_documents_to_vectorstore()for different document types - Retrieval Count: Modify
search_kwargs={"k": 5}to retrieve more/fewer documents - Model Selection: Change
model="gemini-2.0-flash"to other Gemini models if needed
In app.py, modify the RecursiveCharacterTextSplitter:
text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(
chunk_size=200, # Increase for longer chunks
chunk_overlap=50 # Adjust overlap
)Modify the retriever configuration:
retriever = db.as_retriever(
search_type="similarity",
search_kwargs={"k": 10} # Retrieve more documents
)Edit the prompt templates in:
grade_documents(): Relevance checking promptrewrite(): Query rewriting promptgenerate(): Answer generation prompt
| Package | Version | Purpose |
|---|---|---|
langchain |
β₯0.3.0 | LLM framework |
langchain-google-genai |
β₯1.0.0 | Google Gemini integration |
langchain-chroma |
β₯0.1.0 | ChromaDB vector store |
langgraph |
β₯0.2.0 | Agent workflow orchestration |
streamlit |
β₯1.28.0 | Web UI framework |
chromadb |
β₯0.4.0 | Vector database |
pydantic |
β₯2.0.0 | Data validation |
See requirements.txt for complete list.
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Install development dependencies
pip install -r requirements.txt
# Run the app in development mode
streamlit run app.py --server.runOnSave trueThis project is licensed under the MIT License - see the LICENSE file for details.
- LangChain team for the amazing framework
- LangGraph for agentic workflow capabilities
- ChromaDB for free vector storage
- Google Gemini for powerful LLM capabilities
- Streamlit for the beautiful UI framework
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Review the LangChain Documentation
- Check LangGraph Documentation
- Open an issue on GitHub
Potential features for future versions:
- Support for multiple document formats (PDF, DOCX, etc.)
- Batch document upload
- Export conversation history
- Multi-language support
- Advanced filtering options
- Document metadata search
- API endpoint for programmatic access
- User authentication
- Multiple vector stores support
Made with β€οΈ using LangChain, LangGraph, and Streamlit
β Star this repo if you find it helpful!