Skip to content

RAG system for chatting with local documents using DeepSeek-Coder, ChromaDB, and Streamlit. Transform your docs into an intelligent Q&A assistant.

Notifications You must be signed in to change notification settings

afrijaldz/ollama-rag-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔍 DeepSeek RAG - Local Document Chat

A Retrieval-Augmented Generation (RAG) system that allows you to chat with your local documents using DeepSeek's powerful language model. This project demonstrates how to build an intelligent document Q&A system using modern AI technologies.

🚀 Features

  • Local Document Processing: Automatically processes MDX and other document formats
  • Vector Database: Uses ChromaDB for efficient document embeddings and retrieval
  • DeepSeek Integration: Leverages DeepSeek-Coder model for intelligent responses
  • Streamlit Interface: Clean and intuitive web interface for document interaction
  • Smart Text Processing: Cleans MDX files and splits documents into optimal chunks

🛠️ Tech Stack

  • Language Model: DeepSeek-Coder (via Ollama)
  • Vector Database: ChromaDB
  • Embeddings: HuggingFace sentence-transformers/all-MiniLM-L6-v2
  • Framework: LangChain
  • Frontend: Streamlit
  • Document Processing: UnstructuredFileLoader, CharacterTextSplitter

📋 Prerequisites

Before running this project, ensure you have:

  1. Python 3.8+ installed
  2. Ollama installed and running
  3. DeepSeek-Coder model pulled in Ollama

Installing Ollama and DeepSeek-Coder

# Install Ollama (macOS)
brew install ollama

# Or download from https://ollama.ai

# Pull the DeepSeek-Coder model
ollama pull deepseek-coder

🚀 Installation

  1. Clone the repository

    git clone <your-repo-url>
    cd deepseek-rag
  2. Create a virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt

📖 Usage

  1. Prepare your documents

    • Place your documents in the docs/ folder
    • Supports MDX files and other formats (PDF, TXT, etc.)
    • The system will automatically process and clean MDX content
  2. Start the application

    streamlit run app.py
  3. Open your browser

    • Navigate to http://localhost:8501
    • Start asking questions about your documents!

🔧 Configuration

Customizing the RAG Chain

You can modify the RAG configuration in rag_chain.py:

# Adjust chunk size and overlap
splitter = CharacterTextSplitter(chunk_size=500, chunk_overlap=50)

# Change embedding model
embedding = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")

# Switch to different DeepSeek model
llm = Ollama(model="deepseek-coder")  # or "deepseek-chat"

Document Processing

The system automatically:

  • Cleans HTML tags from MDX files
  • Splits documents into chunks for better retrieval
  • Creates vector embeddings for semantic search
  • Persists the vector database in the db/ directory

📁 Project Structure

deepseek-rag/
├── app.py                 # Streamlit web interface
├── rag_chain.py          # RAG implementation and configuration
├── requirements.txt      # Python dependencies
├── docs/                 # Document directory (Next.js docs included)
│   ├── 01-installation.mdx
│   ├── 02-project-structure.mdx
│   └── ...
└── db/                   # ChromaDB vector database
    ├── chroma.sqlite3
    └── ...

🔍 How It Works

  1. Document Loading: The system scans the docs/ folder and loads all supported documents
  2. Text Processing: MDX files are cleaned of HTML tags, and all documents are split into chunks
  3. Embedding Creation: Text chunks are converted to vector embeddings using HuggingFace models
  4. Vector Storage: Embeddings are stored in ChromaDB for fast similarity search
  5. Query Processing: User questions are embedded and matched against document chunks
  6. Response Generation: DeepSeek-Coder generates answers based on retrieved context

🎯 Example Use Cases

This RAG system is perfect for:

  • Documentation Q&A: Ask questions about technical documentation
  • Knowledge Base: Build internal company knowledge systems
  • Research Assistant: Query research papers and technical documents
  • Learning Tool: Interactive way to explore complex documentation

🤝 Contributing

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

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

🐛 Troubleshooting

Ollama Connection Issues:

  • Ensure Ollama is running: ollama serve
  • Verify DeepSeek model is available: ollama list

Memory Issues:

  • Reduce chunk_size in rag_chain.py
  • Use a smaller embedding model

Document Processing Errors:

  • Check document formats are supported
  • Ensure documents are readable and not corrupted

Built with ❤️ using DeepSeek, LangChain, and Streamlit

About

RAG system for chatting with local documents using DeepSeek-Coder, ChromaDB, and Streamlit. Transform your docs into an intelligent Q&A assistant.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages