Skip to content

Repository files navigation

πŸ¦œπŸ”— Langchain

A hands-on, module-by-module learning repository covering the LangChain ecosystem β€” from raw LLM calls to RAG pipelines, tools, and agents.

Python LangChain ChromaDB GitHub Stars GitHub Forks Last Commit

⚠️ Note on this README: This repository was documented from its folder/file structure alone (no source code, requirements.txt, or setup.py contents were provided). Sections that cannot be verified from the file names β€” such as license terms, live demos, and exact dependency versions β€” are marked accordingly instead of being guessed.


πŸ“– Project Overview

Langchain is a structured, numbered curriculum of standalone Python scripts and notebooks that walk through the LangChain framework end-to-end β€” starting from raw LLM invocation and progressing through chat models, embeddings, prompts, structured output, output parsers, chains, LCEL runnables, Retrieval-Augmented Generation (RAG), tools, and agents.

Why it exists

  • Serves as a personal reference / learning log while mastering LangChain concept-by-concept.
  • Each numbered folder (01 β†’ 11) isolates one concept so it can be studied or reused independently.

Real-world use case

  • A ready-made playground for anyone learning LangChain to see minimal, working examples of each building block (loaders, splitters, retrievers, chains, tools, agents) before combining them into a full application.

Target users

  • Students and developers learning LangChain
  • Engineers who want copy-paste-ready snippets for LLMs, RAG, and agent components
  • Instructors looking for a ready reference curriculum structure

✨ Features

Based on the modules present in the repository:

βœ… Basic LLM invocation examples (01.LLMs)

βœ… Multi-provider chat model examples β€” OpenAI, Anthropic, Google, Hugging Face (API & local) (02.ChatModels)

βœ… Embedding generation with OpenAI and local Hugging Face models, plus a document similarity demo (03.EmbeddingModels)

βœ… Static & dynamic prompts, chat templates, message placeholders, and a simple chatbot (04.Prompt)

βœ… Structured output using TypedDict, Pydantic, and JSON Schema (05.Structure_Output)

βœ… Output parsers β€” string, JSON, structured, and Pydantic parsers, including chain integration (06.OutputParser)

βœ… Chain compositions β€” simple, sequential, parallel, and conditional chains (07.Chains)

βœ… LCEL / Runnables β€” RunnableSequence, RunnableParallel, RunnablePassthrough, RunnableLambda, RunnableBranch, plus legacy LLMChain, a PDF reader, and a RetrievalQA chain example (08.Runnables)

βœ… End-to-end RAG pipeline:

  • Document loaders β€” text, PDF, directory (eager & lazy), web page (09.RAG/1.Document_Loader)
  • Text splitters β€” length-based, structure-based, markdown-based, and semantic chunking (09.RAG/2.Text_Splitter)
  • Vector storage with ChromaDB (09.RAG/3.Vector_Database)
  • Retrievers β€” Wikipedia, vector store, MMR, multi-query, and contextual compression retrievers (09.RAG/4.Retriever)

βœ… Tool usage β€” built-in tools (DuckDuckGo search, shell tool, Google search), custom tools (structured & base tool), and toolkits with tool binding/execution (10.Tools)

βœ… Agents β€” a search agent and a weather agent built with LangChain (11.Agents)


πŸ—οΈ Architecture

The repository doesn't ship a single application β€” it's a set of independent modules. The conceptual flow a learner follows (and the flow a RAG-based script in this repo implements) looks like this:

flowchart TD
    A[User / Script Input] --> B[Prompt Layer]
    B --> C[Chat Model<br/>OpenAI / Anthropic / Google / HF]
    C --> D{Needs External<br/>Knowledge or Tools?}
    D -- RAG --> E[Document Loader]
    E --> F[Text Splitter]
    F --> G[Embedding Model]
    G --> H[(ChromaDB<br/>Vector Store)]
    H --> I[Retriever<br/>Vector / MMR / MQR / CCR]
    I --> C
    D -- Tools/Agents --> J[Tools & Toolkits<br/>Search / Shell / Custom]
    J --> C
    C --> K[Output Parser<br/>String / JSON / Pydantic]
    K --> L[Final Response]
Loading

πŸ“‚ Folder Structure

Langchain.git/
β”œβ”€β”€ .gitignore
β”œβ”€β”€ 01.LLMs/
β”‚   β”œβ”€β”€ 1_LLM_demo.py
β”‚   └── __init__.py
β”œβ”€β”€ 02.ChatModels/
β”‚   β”œβ”€β”€ 1_chatmodel_openai.py
β”‚   β”œβ”€β”€ 2_chatmodel_anthropic.py
β”‚   β”œβ”€β”€ 3_chatmodels_google.py
β”‚   β”œβ”€β”€ 4_chatmodels_hf_api.py
β”‚   β”œβ”€β”€ 5_chatmodels_hf_local.py
β”‚   └── __init__.py
β”œβ”€β”€ 03.EmbeddingModels/
β”‚   β”œβ”€β”€ 1_embedding_openai_query.py
β”‚   β”œβ”€β”€ 2_embedding_openai_docs.py
β”‚   β”œβ”€β”€ 3_embedding_hf_local.py
β”‚   β”œβ”€β”€ 4_Document_Similarity.py
β”‚   └── __init__.py
β”œβ”€β”€ 04.Prompt/
β”‚   β”œβ”€β”€ 1_Static_Prompt.py
β”‚   β”œβ”€β”€ 2_Dynamic_Prompt.py
β”‚   β”œβ”€β”€ 3_Chatbot.py
β”‚   β”œβ”€β”€ 4_Messages.py
β”‚   β”œβ”€β”€ 5_Chat_Template.py
β”‚   β”œβ”€β”€ 6_Message_Placeholder.py
β”‚   └── chat_history.txt
β”œβ”€β”€ 05.Structure_Output/
β”‚   β”œβ”€β”€ 1_using_TypeDict.py
β”‚   β”œβ”€β”€ 2_with_structured_output_TypeDictAnnoted.py
β”‚   β”œβ”€β”€ 3_Pydantic.py
β”‚   β”œβ”€β”€ 4_Pydantic.py
β”‚   β”œβ”€β”€ 5_with_structured_output_TypeDict.py
β”‚   β”œβ”€β”€ 6_with_structured_output_Pydantic.py
β”‚   β”œβ”€β”€ 7_with_structured_output_JsonScheme.py
β”‚   β”œβ”€β”€ 8_with_structure_output_using_hf.py
β”‚   └── json_schema.json
β”œβ”€β”€ 06.OutputParser/
β”‚   β”œβ”€β”€ 1_string_output_parser.py
β”‚   β”œβ”€β”€ 2_string_output_parser.py
β”‚   β”œβ”€β”€ 3_json_output_parser.py
β”‚   β”œβ”€β”€ 4_json_output_parser_with_chain.py
β”‚   β”œβ”€β”€ 5_structured_ouput_parser.py
β”‚   └── 6_pydantic_output_parser.py
β”œβ”€β”€ 07.Chains/
β”‚   β”œβ”€β”€ 1_simple_chain.py
β”‚   β”œβ”€β”€ 2_sequential_chain.py
β”‚   β”œβ”€β”€ 3_parallel_chain.py
β”‚   └── 4_conditional_chain.py
β”œβ”€β”€ 08.Runnables/
β”‚   β”œβ”€β”€ 1.1_runnable_sequence.py
β”‚   β”œβ”€β”€ 1_runnable_sequence.py
β”‚   β”œβ”€β”€ 2_runnable_parallel.py
β”‚   β”œβ”€β”€ 3.1_simple_runnable_passthrough.py
β”‚   β”œβ”€β”€ 3.2_runnable_passthrough.py
β”‚   β”œβ”€β”€ 4.1_simple_runnable_lambda.py
β”‚   β”œβ”€β”€ 4.2_runnable_lambda.py
β”‚   β”œβ”€β”€ 5_runnable_branch.py
β”‚   β”œβ”€β”€ 6_LCEL.py
β”‚   β”œβ”€β”€ llm_using_llmchain.py
β”‚   β”œβ”€β”€ pdf_reader.py
β”‚   β”œβ”€β”€ retrievalQA_chain.py
β”‚   └── simple_llm.py
β”œβ”€β”€ 09.RAG/
β”‚   β”œβ”€β”€ 1.Document_Loader/
β”‚   β”‚   β”œβ”€β”€ 1_text_loader.py
β”‚   β”‚   β”œβ”€β”€ 2_pdf_loader.py
β”‚   β”‚   β”œβ”€β”€ 3.1_directory_loader_load.py
β”‚   β”‚   β”œβ”€β”€ 3.2_directory_loader_lazyload.py
β”‚   β”‚   β”œβ”€β”€ 4.1_WebPage_loader.py
β”‚   β”‚   β”œβ”€β”€ 4.2_WebPage_loader_application.py
β”‚   β”‚   β”œβ”€β”€ cricket.txt
β”‚   β”‚   └── pypdf.pdf
β”‚   β”œβ”€β”€ 2.Text_Splitter/
β”‚   β”‚   β”œβ”€β”€ 1.1_length_based_text_splitter.py
β”‚   β”‚   β”œβ”€β”€ 1_length_based_text_splitter.py
β”‚   β”‚   β”œβ”€β”€ 2_text_structure_based_text_splitter.py
β”‚   β”‚   β”œβ”€β”€ 3.1_markdown_splitter_using_text_splitter.py
β”‚   β”‚   β”œβ”€β”€ 3_document_structure_based_text_splitter.py
β”‚   β”‚   └── 4_semantic_meaning_based_text_splitter.py
β”‚   β”œβ”€β”€ 3.Vector_Database/
β”‚   β”‚   β”œβ”€β”€ 1_chromadb_vector_db.py
β”‚   β”‚   └── 2_chromadb-using-vector-database.ipynb
β”‚   β”œβ”€β”€ 4.Retriever/
β”‚   β”‚   β”œβ”€β”€ 1_wikipedia_retriever.py
β”‚   β”‚   β”œβ”€β”€ 2_vector_store_retriever.py
β”‚   β”‚   β”œβ”€β”€ 3_MMR_retriever.py
β”‚   β”‚   β”œβ”€β”€ 4_mqr.py
β”‚   β”‚   └── 5_ccr.py
β”‚   β”œβ”€β”€ Book/
β”‚   β”‚   β”œβ”€β”€ 1.pdf
β”‚   β”‚   β”œβ”€β”€ SDG_AI-Study-Assistant_Shravan-Kumar-Pandey.pdf
β”‚   β”‚   └── aknowledgement6th sem.pdf
β”‚   β”œβ”€β”€ __ini__.py
β”‚   └── dl-curriculum.pdf
β”œβ”€β”€ 10.Tools/
β”‚   β”œβ”€β”€ Built-in_Tool/
β”‚   β”‚   β”œβ”€β”€ 1_duckduckgo_search.py
β”‚   β”‚   β”œβ”€β”€ 2_shell_tool.py
β”‚   β”‚   └── 3_google_search.py
β”‚   β”œβ”€β”€ Custom_Tool/
β”‚   β”‚   β”œβ”€β”€ 1_custom-tool.ipynb
β”‚   β”‚   β”œβ”€β”€ 2_structured_tool.py
β”‚   β”‚   └── 3_Base_tool.py
β”‚   β”œβ”€β”€ Toolkit/
β”‚   β”‚   β”œβ”€β”€ 1_toolkit.py
β”‚   β”‚   β”œβ”€β”€ 2_tool_binding.py
β”‚   β”‚   β”œβ”€β”€ 3_tool_execution.py
β”‚   β”‚   └── 4_complete_toolkit_code.py
β”‚   └── __init__.py
β”œβ”€β”€ 11.Agents/
β”‚   β”œβ”€β”€ 1_search_agents_in_langchain.py
β”‚   └── 2_weather_agent_langchain.py
β”œβ”€β”€ README.md
β”œβ”€β”€ chroma_db/
β”‚   β”œβ”€β”€ 710c71c9-f247-4be4-a4cb-ddd48b7c3de1/
β”‚   β”‚   β”œβ”€β”€ data_level0.bin
β”‚   β”‚   β”œβ”€β”€ header.bin
β”‚   β”‚   β”œβ”€β”€ length.bin
β”‚   β”‚   └── link_lists.bin
β”‚   └── chroma.sqlite3
β”œβ”€β”€ requirements.txt
└── setup.py


πŸ› οΈ Technologies Used

Category Technology
Language Python
Core Framework LangChain
LLM Providers OpenAI, Anthropic, Google, Hugging Face (Inference API & local)
Embedding Models OpenAI Embeddings, Hugging Face (local) Embeddings
Vector Database ChromaDB
Data Sources Wikipedia, PDF files, plain text, web pages
Structured Output / Validation Pydantic, TypedDict, JSON Schema
Built-in Tools DuckDuckGo Search, Shell Tool, Google Search
Notebook Support Jupyter Notebooks (.ipynb)
Packaging requirements.txt, setup.py

Exact package versions could not be determined β€” see requirements.txt in the repository for the authoritative list.


βš™οΈ Installation

# 1. Clone the repository
git clone https://github.com/Shravan4598/Langchain.git
cd Langchain

# 2. Create and activate a virtual environment
python -m venv venv
source venv/bin/activate      # On Windows: venv\Scripts\activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. Configure environment variables
cp .env.example .env          # create this file if not already present
# then fill in your API keys (see table below)

# 5. Run any module script directly, e.g.:
python 01.LLMs/1_LLM_demo.py

πŸ”‘ Environment Variables

The scripts call multiple LLM/embedding providers and external search tools. Based on the modules present, you will likely need some or all of the following keys (add only the ones relevant to the script you're running):

Variable Description Required Example
OPENAI_API_KEY API key for OpenAI chat & embedding models For OpenAI scripts sk-...
ANTHROPIC_API_KEY API key for Anthropic (Claude) chat models For Anthropic scripts sk-ant-...
GOOGLE_API_KEY API key for Google (Gemini) chat models For Google scripts AIza...
HUGGINGFACEHUB_API_TOKEN Token for Hugging Face Inference API models For HF API scripts hf_...

ℹ️ A .env file / dotenv pattern is assumed based on standard LangChain conventions; confirm the exact variable names used by checking each script's os.getenv(...) calls, since these were not visible in the provided structure.


πŸš€ Usage

Each numbered folder is self-contained β€” pick a concept and run the corresponding script:

# Try a basic chat model call
python 02.ChatModels/2_chatmodel_anthropic.py

# Run a text splitter demo
python 09.RAG/2.Text_Splitter/2_text_structure_based_text_splitter.py

# Build/query the Chroma vector store
python 09.RAG/3.Vector_Database/1_chromadb_vector_db.py

# Run an agent example
python 11.Agents/2_weather_agent_langchain.py

For notebook-based examples (.ipynb files), launch Jupyter:

jupyter notebook

πŸ”„ How It Works (RAG Module Example)

User Query
   ↓
Document Loader (PDF / Text / Web / Directory)
   ↓
Text Splitter (chunking)
   ↓
Embedding Model (OpenAI / Hugging Face)
   ↓
ChromaDB (vector storage)
   ↓
Retriever (Vector / MMR / Multi-Query / Contextual Compression)
   ↓
Chat Model (LLM generates the final answer)
   ↓
Output Parser β†’ Response

🌟 Project Highlights

Concepts actually implemented in this repository:

  • LangChain Expression Language (LCEL) β€” RunnableSequence, RunnableParallel, RunnablePassthrough, RunnableLambda, RunnableBranch
  • Retrieval-Augmented Generation (RAG) β€” full loader β†’ splitter β†’ embedding β†’ vector store β†’ retriever pipeline
  • Prompt Engineering β€” static/dynamic prompts, chat prompt templates, message placeholders
  • Structured Output β€” TypedDict, Pydantic models, JSON Schema
  • Output Parsing β€” string, JSON, structured, and Pydantic parsers
  • Embeddings & Vector Search β€” OpenAI & Hugging Face embeddings with ChromaDB, including MMR-based diversity retrieval
  • Tools & Toolkits β€” built-in (DuckDuckGo, Shell, Google Search) and custom tools, with tool binding/execution
  • Agents β€” search agent and weather agent

πŸ“¦ Requirements

File Purpose
requirements.txt Python package dependencies (exact contents not provided β€” install via pip install -r requirements.txt)
setup.py Enables installing this repo as a local package

πŸ—ΊοΈ Future Improvements

  • Add a top-level .env.example documenting all required API keys
  • Add a LICENSE file to clarify usage terms
  • Add unit tests for reusable components (loaders, splitters, parsers)
  • Consolidate common utilities used across modules to reduce duplication
  • Add a consolidated requirements.txt with pinned versions per module

🀝 Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m "Add: your feature"
  4. Push to the branch: git push origin feature/your-feature
  5. Open a Pull Request

Please keep new examples consistent with the existing numbered-module structure.


πŸ“„ License

No LICENSE file was present in the provided repository structure. Please check the repository directly, or add one (e.g., MIT) to clarify usage terms for contributors and users.


πŸ‘€ Author

Shravan Kumar Pandey

  • πŸ“§ Email: shravankumarpandey825412@gmail.com
  • πŸ”— Portfolio: shravan-kumar-pandey-portfolio.vercel.app
  • πŸ’Ό LinkedIn: Shravan Kumar Pandey
  • πŸ† Kaggle / LeetCode: shravankumarpandey

πŸ™ Acknowledgements

  • LangChain β€” the core framework this repository is built around
  • ChromaDB β€” vector database used for RAG examples
  • OpenAI, Anthropic, Google, and Hugging Face β€” model providers integrated across the modules

❓ FAQ

Is this a production application? No β€” it's a structured, module-by-module learning repository of standalone LangChain examples, not a deployable application.
Do I need API keys for every provider? No. You only need the API key(s) corresponding to the specific script/provider you're running (e.g., only `OPENAI_API_KEY` for OpenAI scripts).
Where is the vector store data stored? Locally, in the chroma_db/ directory, generated when you run the ChromaDB examples in 09.RAG/3.Vector_Database.

πŸ› Troubleshooting

Issue Likely Cause Fix
AuthenticationError / 401 Missing or invalid API key Verify the relevant key is set in your .env and loaded correctly
ModuleNotFoundError Dependencies not installed Run pip install -r requirements.txt inside your virtual environment
Chroma errors on rerun Stale chroma_db/ state Delete the chroma_db/ folder and re-run the ingestion script
PDF loader fails Corrupt or unsupported PDF Confirm the PDF opens normally outside the script; try a different loader

πŸ”’ Security Notes

  • Never commit real API keys. Store them in a .env file and ensure .env is listed in .gitignore.
  • The repository's .gitignore is present at the root β€” confirm it excludes .env, __pycache__/, and virtual environment folders.
  • Treat chroma_db/ as generated/local data; avoid committing large binary vector store files to version control.

⭐ GitHub Tips

If you find this repository useful:

  • ⭐ Star the repo to bookmark it
  • 🍴 Fork it to build your own LangChain learning path
  • πŸ› Open an Issue for bugs or suggestions
  • πŸ”€ Submit a Pull Request to add new examples
  • πŸ‘€ Watch the repo for updates

About

A collection of hands-on examples and core components for building LLM-powered applications. This repository explores Large Language Models (LLMs), Chat Models, and Embedding Models to create complex, multi-step AI workflows.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages