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.
- ๐ฌ 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.
| 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 |
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
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.
git clone https://github.com/maherdhami/AI-Knowledge-Assistant.git
cd AI-Knowledge-AssistantWindows โ PowerShell
python -m venv venv
.\venv\Scripts\Activate.ps1Windows โ Command Prompt
venv\Scripts\activate.batLinux or macOS
python3 -m venv venv
source venv/bin/activateCreate 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.txtFor reproducible deployments, pin and test compatible dependency versions.
Download and install Ollama:
Pull the model used by the application:
ollama pull llama3:8bEnsure the Ollama service is running before starting the application.
Verify the installed model:
ollama listCreate 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_tokenImportant:
- Keep
.envout 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.
From the project directory, activate your virtual environment and run:
streamlit run app.pyReplace 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.
Start the Streamlit application and open it in your browser.
Use the sidebar to:
- Upload one or more PDF documents.
- Enter a website URL to ingest its content.
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.
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.
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.
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.
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.
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.
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.
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
- Keep API keys and access tokens in environment variables.
- Never commit your
.envfile. - 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.
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
user1within 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.
- 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
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
Maher Dhami
If you find this project useful:
- Give the repository a star โญ
- Fork it to experiment with your own ideas ๐ด
- Share it with other developers ๐
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.