Skip to content

Latest commit

ย 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  LangChain RAG + Agent System

A Python project exploring Retrieval-Augmented Generation (RAG), local LLM inference, and LangChain-based conversational agent workflows using Ollama and ChromaDB.

Python LangChain Ollama ChromaDB


๐Ÿ“Œ Overview

This repository contains experiments and implementations around two related AI application patterns:

1. PDF RAG System

A document question-answering pipeline that:

  • loads a PDF document
  • extracts and splits its content
  • creates embeddings
  • stores vectors in ChromaDB
  • retrieves relevant context
  • generates an answer using a local LLM

2. Conversational Agent Workflow

The repository also explores conversational AI workflows using LangChain, local model inference, memory, and tool-oriented interactions.

The RAG pipeline is the primary documented implementation in this repository.


๐ŸŽฏ What This Project Demonstrates

This project was built to explore practical concepts behind modern LLM applications, including:

  • Retrieval-Augmented Generation
  • document ingestion
  • text chunking
  • embeddings
  • vector databases
  • semantic retrieval
  • prompt-based grounding
  • local LLM inference
  • conversational AI workflows

โœจ RAG Features

  • ๐Ÿ“„ PDF document loading
  • โœ‚๏ธ Recursive text splitting
  • ๐Ÿง  Embedding generation
  • ๐Ÿ—„๏ธ ChromaDB vector storage
  • ๐Ÿ”Ž Semantic retrieval
  • ๐Ÿค– Local LLM inference with Ollama
  • ๐Ÿ’ฌ Context-aware question answering

๐Ÿค– Agent Features

The repository also explores:

  • conversational interaction
  • multi-turn context
  • LangChain-based tool workflows
  • local LLM inference

Agent functionality is currently exploratory and is not presented as a production-ready agent platform.


๐Ÿ—๏ธ RAG Architecture

PDF Document
     โ”‚
     โ–ผ
Document Loader
     โ”‚
     โ–ผ
Text Splitting
     โ”‚
     โ–ผ
Embedding Model
     โ”‚
     โ–ผ
ChromaDB
(Vector Store)
     โ”‚
     โ”‚
User Question
     โ”‚
     โ–ผ
Retriever
     โ”‚
     โ–ผ
Relevant Context
     โ”‚
     โ–ผ
Local LLM
(Ollama)
     โ”‚
     โ–ผ
Generated Answer

๐Ÿง  How the RAG Pipeline Works

1. Document Loading

The application loads the configured PDF document.

2. Text Splitting

Large document content is divided into smaller chunks to make retrieval more effective.

3. Embedding Generation

The document chunks are converted into vector representations.

4. Vector Storage

The embeddings are stored in ChromaDB.

5. Retrieval

When a user asks a question, the system retrieves relevant document chunks based on semantic similarity.

6. Generation

The retrieved context is passed to a local language model through Ollama.

7. Response

The model generates an answer based on the retrieved context.


๐Ÿงฉ Prompt Grounding

The RAG workflow uses a grounding-oriented prompt pattern similar to:

You are an assistant that answers questions using ONLY
the provided context.

If the answer is not in the context, reply:
"I don't know."

The purpose is to reduce unsupported generation when the required information is not present in the retrieved context.

Prompt instructions alone do not guarantee hallucination-free output.


๐Ÿ› ๏ธ Tech Stack

Area Technology
Language Python
LLM Framework LangChain
LLM Runtime Ollama
Vector Database ChromaDB
Embeddings Local embedding model
Document Processing PyPDF / LangChain loaders

๐Ÿ“‚ Project Structure

LangChain-Rag-Agent/
โ”‚
โ”œโ”€โ”€ rag.py
โ”‚   โ””โ”€โ”€ PDF-based RAG pipeline
โ”‚
โ”œโ”€โ”€ chatbot.py
โ”‚   โ””โ”€โ”€ Conversational workflow
โ”‚
โ”œโ”€โ”€ text_generation.py
โ”‚   โ””โ”€โ”€ LLM interaction utilities
โ”‚
โ”œโ”€โ”€ manual.pdf
โ”‚   โ””โ”€โ”€ Sample document used by the RAG pipeline
โ”‚
โ””โ”€โ”€ README.md

โš™๏ธ Getting Started

Prerequisites

Install:

  • Python 3.x
  • Git
  • Ollama

1. Clone the Repository

git clone https://github.com/abdullahk970/LangChain-Rag-Agent.git

cd LangChain-Rag-Agent

2. Install Dependencies

pip install langchain langchain-community langchain-ollama chromadb pypdf

3. Start Ollama

Start the local Ollama service:

ollama serve

Pull the required models:

ollama pull llama2
ollama pull nomic-embed-text

Model names should match the configuration used by the current application.


โ–ถ๏ธ Running the RAG System

Run:

python rag.py

The application will use the configured PDF document as the knowledge source.


๐Ÿค– Running the Conversational Workflow

The repository also contains an exploratory conversational workflow:

python chatbot.py

The current public repository should be considered experimental for this part of the project.


๐Ÿงช Evaluation

A useful next step for this project is to evaluate retrieval quality using a fixed question set.

Potential metrics include:

  • Recall@K
  • Precision@K
  • MRR
  • Context relevance
  • Answer relevance
  • Faithfulness

No numerical benchmark is claimed until a reproducible evaluation dataset and methodology are established.


โš ๏ธ Limitations

  • The current implementation is primarily an experimental/learning project.
  • Retrieval quality depends on chunking and embedding configuration.
  • Local model performance depends on available system resources.
  • LLM-generated responses may still contain incorrect information.
  • The current RAG implementation is centered around a configured PDF knowledge source.
  • The conversational agent portion should be considered exploratory rather than production-ready.

๐Ÿ”ฎ Future Improvements

  • Multi-document RAG
  • Web-based interface
  • Retrieval evaluation benchmarks
  • Better citation support
  • Metadata-aware retrieval
  • Reranking
  • Additional local models
  • Structured tool outputs
  • More robust agent workflows
  • Automated testing

๐Ÿ‘จโ€๐Ÿ’ป Author

Muhammad Abdullah Khan


๐Ÿ“„ License

This project is licensed under the MIT License.

About

Experimental RAG and AI agent system for document question-answering, conversational workflows, memory, and tool-based interactions using LangChain and Ollama.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages