This project contains two related chatbot apps built on top of Ollama and Streamlit:
- A simple persona-based chat app using a Flask API and a Streamlit frontend
- A RAG-powered chatbot studio that can ingest documents, build embeddings, and answer questions from retrieved context
The code in this folder is implemented across several Python files and follows a lightweight local-first architecture.
base_api.py— Minimal Flask API for chatting with Ollama using personasbase_chatbot.py— Streamlit UI for the basic chatbotrag_core.py— Core business logic for chatbot creation, indexing, document parsing, embeddings, and retrievalrag_api.py— Flask API for the RAG chatbot applicationrag_chatbot.py— Streamlit frontend for the RAG chatbot studiopersonas.json— Persona definitions used by the base chat appdata/— Stores chatbot metadata, uploaded files, conversation logs, and vector indexes
The basic setup is a simple local chat interface:
base_api.pyexposes a Flask API on port5005base_chatbot.pyconnects to that API from Streamlit- It uses Ollama for model inference and
personas.jsonfor system prompts
- Health check endpoint for Ollama connectivity
- Persona listing endpoint
- Streaming chat responses from Ollama
- Persona-aware system prompt injection
- Simple chat UI with model and temperature controls
base_api.py includes:
-
GET /status
Returns whether Ollama is reachable and the available models. -
GET /personas
Returns the list of personas frompersonas.json. -
POST /chat
Accepts a request body like:
{
"model": "llama3",
"persona_id": "general",
"messages": [{ "role": "user", "content": "Hello" }],
"temperature": 0.7
}The server prepends the selected persona's system prompt before sending the conversation to Ollama.
- Start Ollama:
ollama serve- Pull the model you want to use, for example:
ollama pull llama3- Start the API:
python base_api.py- Run the UI:
streamlit run base_chatbot.pyThe RAG implementation is more advanced and is centered around rag_core.py.
It supports:
- chatbot creation
- uploading a source file
- parsing and chunking supported document types
- generating embeddings with Ollama embedding models
- storing a vector-style index on disk
- retrieving the most relevant chunks at query time
- composing a final answer using an LLM and the retrieved context
- persisting chat history and source references
- Creates and lists chatbot definitions
- Validates uploaded knowledge files
- Reads supported file types such as PDF, DOCX, TXT, MD, CSV, TSV, XLSX, JSON, HTML, and XML
- Splits text into overlapping chunks
- Uses LangChain-compatible document objects and embedding models
- Stores document and embedding payloads under
data/vectorstores/ - Maintains conversations in
data/conversations/ - Uses Ollama for both embeddings and LLM completion
The ingestion logic recognizes many common file types, including:
- text:
.txt,.md,.py,.js,.ts,.tsx,.jsx,.json,.jsonl - markup:
.html,.htm,.xml - tables:
.csv,.tsv,.xlsx,.xls,.xlsm,.xltx,.xltm - documents:
.pdf,.doc,.docx,.rtf,.odt
The service defaults to:
- LLM:
tinyllama - Embedding model:
mxbai-embed-large
These values are defined in rag_core.py and can be overridden when creating a chatbot.
rag_api.py exposes these endpoints:
-
GET /health
Simple health check -
GET /status/services
Returns FastAPI/Flask status and Ollama reachability -
GET /chatbots
Lists all saved chatbots -
GET /chatbots/<chatbot_id>
Fetches one chatbot's metadata -
POST /chatbots/stream-create
Creates a chatbot and streams progress events as SSE -
POST /chatbots/<chatbot_id>/index
Ensures the embedding index is built -
GET /chatbots/<chatbot_id>/conversation
Returns the conversation history -
POST /chatbots/<chatbot_id>/messages
Saves a message with optional sources -
POST /chatbots/<chatbot_id>/chat
Sends a question to the chatbot and returns the answer plus sources
The workflow is:
- Upload or select a source file
- Parse and extract text content
- Chunk the text into smaller segments
- Embed each chunk with Ollama embeddings
- Store the documents and embeddings on disk
- At query time, retrieve the most relevant chunks
- Pass those chunks as context to the Ollama LLM
- Save the user and assistant messages with source references
rag_chatbot.py provides the UI:
- Home page shows all available chatbots
- Create page lets you upload a knowledge source and configure models
- Chat page lets you ask questions against a selected chatbot
- Source references are shown in expandable sections with metadata
It talks to the Flask API on http://127.0.0.1:8000 by default.
- Start Ollama:
ollama serve- Pull the necessary models:
ollama pull tinyllama
ollama pull mxbai-embed-large- Start the RAG API:
python rag_api.py- Start the UI:
streamlit run rag_chatbot.pyThe workspace includes a data/ folder with:
chatbots.json— metadata for saved chatbotsconversations/— per-chatbot conversation logsuploads/— uploaded knowledge filesvectorstores/— embedding/index payloads stored as JSON
These files are created and updated at runtime by rag_core.py.
Install the Python dependencies required by the project, including:
pip install flask requests streamlit pydantic ollama langchain-core langchain-ollamaDepending on the file types you want to ingest, you may also need:
pip install pandas python-docx pdfplumber beautifulsoup4For spreadsheet, docx, PDF, and HTML parsing, the optional packages above are used by the ingestion layer.
There are two common workflows in this repo:
python base_api.py
streamlit run base_chatbot.pyUse this for direct persona-based chat against Ollama.
python rag_api.py
streamlit run rag_chatbot.pyUse this to create a bot from a file, build its index, and ask questions using retrieved document context.
- The project is designed for local development and uses local Ollama models.
rag_core.pyis the core engine and is what powers both indexing and retrieval.- The app stores state in the local filesystem rather than a database.
- This repo is a lightweight prototype for experimenting with local LLMs and retrieval-augmented chat workflows.