{"id":41467574,"url":"https://github.com/testpress/langchain_rag","last_synced_at":"2026-01-23T16:34:21.331Z","repository":{"id":303227439,"uuid":"1014794727","full_name":"testpress/langchain_rag","owner":"testpress","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-06T12:43:24.000Z","size":58,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-06T13:42:39.601Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/testpress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-06T12:37:24.000Z","updated_at":"2025-07-06T12:43:28.000Z","dependencies_parsed_at":"2025-07-06T13:52:45.602Z","dependency_job_id":null,"html_url":"https://github.com/testpress/langchain_rag","commit_stats":null,"previous_names":["testpress/langchain_rag"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/testpress/langchain_rag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testpress%2Flangchain_rag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testpress%2Flangchain_rag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testpress%2Flangchain_rag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testpress%2Flangchain_rag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/testpress","download_url":"https://codeload.github.com/testpress/langchain_rag/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testpress%2Flangchain_rag/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28695553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T15:57:05.722Z","status":"ssl_error","status_checked_at":"2026-01-23T15:56:27.656Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-23T16:34:20.695Z","updated_at":"2026-01-23T16:34:21.325Z","avatar_url":"https://github.com/testpress.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LangChain RAG (Retrieval-Augmented Generation)\n\nA Python project demonstrating Retrieval-Augmented Generation (RAG) using LangChain and LangGraph. This project implements two different approaches to RAG: a custom graph-based approach and a ReAct agent approach.\n\n## Overview\n\nThis project creates a question-answering system that:\n1. Loads and processes a blog post about AI agents from Lilian Weng's blog\n2. Splits the content into chunks and stores them in a vector database\n3. Provides two different RAG implementations:\n   - **Custom Graph Approach** (`main.py`): A custom LangGraph implementation with explicit retrieval and generation steps\n   - **ReAct Agent Approach** (`agent.py`): Uses LangGraph's prebuilt ReAct agent with retrieval tools\n\n## Features\n\n- **Web Scraping**: Automatically loads content from a specified blog post\n- **Text Processing**: Splits content into manageable chunks with overlap\n- **Vector Search**: Uses OpenAI embeddings for semantic search\n- **Two RAG Implementations**: \n  - Custom graph-based approach with explicit control flow\n  - ReAct agent approach with tool-based reasoning\n- **Conversation Memory**: Maintains conversation context across interactions\n- **Streaming Output**: Real-time response generation\n\n## Prerequisites\n\n- Python 3.13.5 or higher\n- OpenAI API key\n- Internet connection (for loading the blog post)\n\n## Installation\n\n1. Clone the repository:\n```bash\ngit clone \u003crepository-url\u003e\ncd langchain-rag\n```\n\n2. Install dependencies using uv:\n```bash\nuv sync\n```\n\n3. Set up your OpenAI API key:\n```bash\nexport OPENAI_API_KEY=\"your-api-key-here\"\n```\n\n## Usage\n\n### Custom Graph Approach (`main.py`)\n\nThis implementation uses a custom LangGraph with explicit nodes for query processing, retrieval, and response generation.\n\n```bash\nuv run main.py\n```\n\nThe script will:\n1. Load the blog post about AI agents\n2. Process and chunk the content\n3. Run several example queries demonstrating the RAG system\n\n### ReAct Agent Approach (`agent.py`)\n\nThis implementation uses LangGraph's prebuilt ReAct agent with a retrieval tool.\n\n```bash\nuv run agent.py\n```\n\nThe script will:\n1. Load and process the same blog post\n2. Create a ReAct agent with retrieval capabilities\n3. Run example queries using the agent\n\n## Project Structure\n\n```\nlangchain-rag/\n├── main.py          # Custom graph-based RAG implementation\n├── agent.py         # ReAct agent-based RAG implementation\n├── pyproject.toml   # Project dependencies and metadata\n├── README.md        # This file\n└── .venv/          # Virtual environment (created by uv)\n```\n\n## Key Components\n\n### Data Processing\n- **WebBaseLoader**: Loads content from the specified blog post\n- **RecursiveCharacterTextSplitter**: Splits content into 1000-character chunks with 200-character overlap\n- **OpenAIEmbeddings**: Creates embeddings for semantic search\n\n### Vector Store\n- **InMemoryVectorStore**: Stores document chunks and their embeddings\n- Supports similarity search for retrieving relevant content\n\n### RAG Implementations\n\n#### Custom Graph (`main.py`)\n- **query_or_respond**: Determines whether to use retrieval or respond directly\n- **tools**: Executes retrieval operations\n- **generate**: Generates responses using retrieved content\n- **Conditional Edges**: Routes between nodes based on tool usage\n\n#### ReAct Agent (`agent.py`)\n- **create_react_agent**: Prebuilt agent with reasoning capabilities\n- **retrieve tool**: Custom tool for document retrieval\n- **MemorySaver**: Maintains conversation state\n\n## Example Queries\n\nThe system can answer questions about:\n- AI agents and their capabilities\n- Task decomposition methods\n- Agent architectures and patterns\n- Specific concepts from the loaded blog post\n\n## Configuration\n\n- **Model**: Uses GPT-4o-mini for text generation\n- **Embeddings**: Uses text-embedding-3-large for vector embeddings\n- **Chunk Size**: 1000 characters with 200-character overlap\n- **Retrieval**: Returns top 2-3 most relevant documents\n\n## Dependencies\n\n- `langchain`: Core LangChain functionality\n- `langchain-openai`: OpenAI integration\n- `langchain-community`: Community components (document loaders)\n- `langchain-text-splitters`: Text processing utilities\n- `langgraph`: Graph-based workflow orchestration\n- `beautifulsoup4`: Web scraping for blog content\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests if applicable\n5. Submit a pull request\n\n## License\n\nThis project is open source and available under the MIT License.\n\n## Acknowledgments\n\nThis project is based on and adapted from the official LangChain tutorials:\n\n- [Build a Retrieval Augmented Generation (RAG) App: Part 1](https://python.langchain.com/docs/tutorials/rag/) - Core RAG implementation patterns\n- [Build a Retrieval Augmented Generation (RAG) App: Part 2](https://python.langchain.com/docs/tutorials/qa_chat_history/) - Chat history and conversation features\n\nThe project demonstrates two different approaches to RAG:\n- **Custom Graph Approach**: Inspired by the structured query analysis and retrieval patterns from the official tutorials\n- **ReAct Agent Approach**: Based on the agent-based RAG patterns with tool integration\n\nAdditional credits:\n- Uses content from [Lilian Weng's blog post about AI agents](https://lilianweng.github.io/posts/2023-06-23-agent/)\n- Built with LangChain and LangGraph frameworks\n- Inspired by modern RAG patterns and best practices\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestpress%2Flangchain_rag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftestpress%2Flangchain_rag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestpress%2Flangchain_rag/lists"}