Skip to content

About

A Streamlit-based AI Knowledge Assistant powered by LangChain, Ollama, ChromaDB and HuggingFace Embeddings. Upload PDFs, scrape websites and chat with your knowledge base using Retrieval-Augmented Generation (RAG).

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

12 Commits

Folders and files

Repository files navigation

๐Ÿค– AI Knowledge Assistant

A Streamlit-based AI Knowledge Assistant that lets users upload PDF documents, ingest website content, and ask questions using Retrieval-Augmented Generation (RAG).

Built with LangChain, Ollama, ChromaDB, and HuggingFace embeddings, the application retrieves relevant information from your knowledge sources and uses a local Large Language Model (LLM) to generate context-aware responses.

๐Ÿš€ Features

  • ๐Ÿ’ฌ Conversational AI Interface โ€” Interact with your knowledge base through a chat interface.
  • ๐Ÿ“„ PDF Question Answering โ€” Upload PDF documents and ask questions about their contents.
  • ๐ŸŒ Website Ingestion โ€” Extract content from website URLs.
  • ๐Ÿง  Retrieval-Augmented Generation (RAG) โ€” Generate responses using relevant retrieved document context.
  • ๐Ÿ” Semantic Search โ€” Find relevant information using vector embeddings.
  • ๐Ÿ—‚๏ธ Vector Database โ€” Store and retrieve document embeddings using ChromaDB.
  • ๐Ÿค— HuggingFace Embeddings โ€” Generate embeddings with sentence-transformers/all-MiniLM-L6-v2.
  • ๐Ÿฆ™ Local LLM Inference โ€” Generate responses using Llama 3 through Ollama.
  • ๐Ÿ’ญ Conversation History โ€” Maintain conversational context using LangChain message history.
  • โœ‚๏ธ Chat History Trimming โ€” Limit retained conversation history to help manage context length.
  • โšก Streamlit UI โ€” A lightweight interface with document upload and chat functionality.

๐Ÿ› ๏ธ Tech Stack

Component Technology
Frontend and UI Streamlit
LLM Llama 3 8B
Local Model Runtime Ollama
LLM Orchestration LangChain
Embedding Model sentence-transformers/all-MiniLM-L6-v2
Vector Database ChromaDB
PDF Processing PyPDFLoader
Website Loading WebBaseLoader
Text Splitting RecursiveCharacterTextSplitter
Conversation History RunnableWithMessageHistory
Environment Configuration python-dotenv

๐Ÿ—๏ธ Architecture

The application follows a Retrieval-Augmented Generation workflow.

                 KNOWLEDGE SOURCES
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚  PDF Documentsโ”‚
                 โ”‚ Website URLs  โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚ Document      โ”‚
                 โ”‚ Loaders       โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚ Text Splittingโ”‚
                 โ”‚ and Chunking  โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚ HuggingFace   โ”‚
                 โ”‚ Embeddings    โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚ ChromaDB      โ”‚
                 โ”‚ Vector Store  โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
USER QUESTION โ”€โ”€โ–บ Semantic Retrieval
                         โ”‚
                         โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚ Prompt with   โ”‚
                 โ”‚ Retrieved     โ”‚
                 โ”‚ Context       โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚ Llama 3 8B    โ”‚
                 โ”‚ via Ollama    โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
                  GENERATED ANSWER

โš™๏ธ Prerequisites

Before running the application, install:

  • Python 3.10 or newer
  • Git
  • Ollama
  • Sufficient memory and storage for your selected local LLM

The Llama 3 8B model requires significant memory and disk space. Actual requirements depend on the model quantization and your hardware.

๐Ÿ“ฅ Installation

1. Clone the Repository

git clone https://github.com/maherdhami/AI-Knowledge-Assistant.git
cd AI-Knowledge-Assistant

2. Create a Virtual Environment

Windows โ€” PowerShell

python -m venv venv
.\venv\Scripts\Activate.ps1

Windows โ€” Command Prompt

venv\Scripts\activate.bat

Linux or macOS

python3 -m venv venv
source venv/bin/activate

3. Install Dependencies

Create a requirements.txt file containing:

streamlit
python-dotenv
langchain
langchain-community
langchain-core
langchain-text-splitters
langchain-huggingface
langchain-chroma
langchain-ollama
chromadb
sentence-transformers
pypdf
beautifulsoup4

Install the dependencies:

pip install -r requirements.txt

For reproducible deployments, pin and test compatible dependency versions.

4. Install Ollama

Download and install Ollama:

https://ollama.com

Pull the model used by the application:

ollama pull llama3:8b

Ensure the Ollama service is running before starting the application.

Verify the installed model:

ollama list

5. Configure Environment Variables

Create a .env file in the project root if you want to enable LangSmith tracing or use a HuggingFace token.

LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=your_langsmith_api_key
LANGCHAIN_PROJECT=AI-Knowledge-Assistant
HF_TOKEN=your_huggingface_token

Important:

  • Keep .env out of version control.
  • Never commit API keys or access tokens.
  • LangSmith credentials are only necessary if you configure tracing.
  • A HuggingFace token may not be necessary for public models that can be downloaded anonymously.

The current application loads these environment variables but does not otherwise use them directly.

โ–ถ๏ธ Run the Application

From the project directory, activate your virtual environment and run:

streamlit run app.py

Replace app.py with the actual Python filename if your entry-point file has a different name.

Streamlit will display a local URL, usually:

http://localhost:8501

Open that URL in your browser.

๐Ÿ“š How to Use

Step 1: Launch the Application

Start the Streamlit application and open it in your browser.

Step 2: Add Knowledge Sources

Use the sidebar to:

  • Upload one or more PDF documents.
  • Enter a website URL to ingest its content.

Step 3: Process Documents

Click Process Documents to load the selected knowledge sources, split the content into chunks, generate embeddings, and create a ChromaDB vector store.

The current implementation also loads content from HuggingFace's website by default.

Step 4: Ask Questions

Enter a question in the chat box.

If a knowledge base has been created, the application retrieves relevant document chunks and passes them to the language model as context.

Step 5: Continue the Conversation

The application maintains message history for the active session, allowing follow-up questions to use previous conversational context.

Use Clear Chat in the sidebar to clear the displayed conversation and reset the active session's message history.

๐Ÿง  Core Concepts

Retrieval-Augmented Generation

RAG combines information retrieval with language generation.

Instead of relying only on information learned during model training, the application retrieves relevant content from uploaded documents and websites to help the model answer questions.

Embeddings and Semantic Search

The embedding model converts document chunks into numerical vectors.

ChromaDB stores these vectors and supports similarity-based retrieval, helping the application find content relevant to a user's question.

Conversation Memory

LangChain's RunnableWithMessageHistory maintains messages associated with a session ID.

The current implementation stores message history in application memory, so the history is not guaranteed to survive application restarts.

Local Language Model

Ollama runs Llama 3 locally, allowing the application to generate answers without sending prompts to a hosted LLM API.

The application still needs an internet connection for initial model downloads and website ingestion.

๐Ÿ“ Project Structure

The following is the intended logical structure. File names may differ from your current repository.

AI-Knowledge-Assistant/
โ”‚
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ .env
โ”œโ”€โ”€ .gitignore
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ””โ”€โ”€ Uploaded documents
โ”‚
โ”œโ”€โ”€ chroma_db/
โ”‚   โ””โ”€โ”€ Persistent vector storage (future enhancement)
โ”‚
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ screenshot1.png
โ”‚   โ””โ”€โ”€ screenshot2.png
โ”‚
โ””โ”€โ”€ utils/
    โ””โ”€โ”€ Reusable application modules

๐Ÿ” Security and Privacy

  • Keep API keys and access tokens in environment variables.
  • Never commit your .env file.
  • Uploaded PDFs are written to the application's working directory by the current implementation.
  • Local LLM inference can improve privacy, but website ingestion and any external tracing services still involve network requests.
  • Review document handling and storage policies before deploying the application for multiple users.

โš ๏ธ Current Implementation Notes

The project is a functional foundation for a local RAG application. The following limitations are worth noting:

  • In-memory conversation history: Message history is not persistently stored.
  • Vector database persistence: The current code creates a ChromaDB instance without explicitly configuring persistent storage.
  • Document processing: Processing documents again creates a new vector store rather than updating an existing persistent collection.
  • Fixed default website: HuggingFace content is loaded when the knowledge base is processed.
  • Chat history trimming: The current implementation trims the stored history before each request, but the trimmed history is not explicitly passed to the model independently of the history wrapper.
  • Response generation: Responses are generated synchronously rather than streamed.
  • Source citations: The application does not currently display document source references in its answers.
  • Session management: The session ID is fixed to user1 within the Streamlit session state initialization, rather than implementing authenticated multi-user sessions.

These are opportunities for further development rather than features that should be assumed to exist already.

๐Ÿ”ฎ Future Improvements

  • Persistent ChromaDB storage
  • Incremental document indexing
  • Source citations and page references
  • Streaming responses
  • Multiple LLM providers
  • Configurable embedding models
  • Chat export and downloadable conversations
  • Support for DOCX and additional file formats
  • Improved conversation history management
  • Authentication and multi-user support
  • Document deletion and knowledge-base management
  • Hybrid retrieval and reranking
  • Cloud deployment
  • Automated testing and evaluation of RAG responses

๐ŸŽฏ Skills Demonstrated

This project demonstrates practical experience with:

  • Generative AI
  • Retrieval-Augmented Generation (RAG)
  • LangChain
  • Large Language Model integration
  • Prompt engineering
  • Semantic search
  • Text embeddings
  • Vector databases
  • Document loading and processing
  • Conversational memory
  • Python application development
  • Streamlit
  • Local AI inference with Ollama

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

Maher Dhami

โญ Support

If you find this project useful:

  • Give the repository a star โญ
  • Fork it to experiment with your own ideas ๐Ÿด
  • Share it with other developers ๐Ÿš€

๐Ÿ“œ License

This project is intended to be distributed under the MIT License.

If you choose the MIT License, add a LICENSE file containing the standard MIT License text and the appropriate copyright holder and year. Until that file exists, do not assume the repository is already licensed under MIT.

About

A Streamlit-based AI Knowledge Assistant powered by LangChain, Ollama, ChromaDB and HuggingFace Embeddings. Upload PDFs, scrape websites and chat with your knowledge base using Retrieval-Augmented Generation (RAG).

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages