Express-Ollama is an open-source example project demonstrating the implementation of local LLM (Large Language Model) using Ollama, full offline, and ready to integrate with any document, regulation, or law database. This project showcases:
- Automatic parsing and chunking of PDF files
- Local embedding generation using Ollama's embedding model
- Embedding and document storage to SQL database (MySQL/PostgreSQL)
- Full-text search and semantic search (vector similarity)
- Question-answering (QA) API powered by local LLM (Ollama)
- Fully offline: All AI/embedding/QA runs on your machine
- Express.js backend: Simple and easy to extend
- LLM & embedding local: No paid API, use Ollama on your Mac/PC/server
- Works with regulations, legal docs, books, or any PDF
- API endpoint for QA:
/askendpoint for intelligent question-answering
- Node.js (18+ recommended)
- MySQL or PostgreSQL
- Ollama (installed locally)
- Docker (recommended for running database/vector DB)
- Git
git clone https://github.com/NeaByteLab/Express-Ollama.git
cd Express-Ollamanpm installDownload and install Ollama from https://ollama.com/download
Run Ollama:
ollama servePull the latest LLM & embedding models:
ollama pull llama3.2
ollama pull nomic-embed-textEdit .env with your database connection, example:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=express_ollama
OLLAMA_URL=http://localhost:11434
PORT=8080
npx knex migrate:latest --knexfile knexfile.jsRun the main script:
node index.js- Place your PDF files in the
dataset/folder. - No need for a watcher service—just put the files and run the service to (re)process your dataset.
- The service will automatically scan and process all PDF files in
dataset/on start.
POST to http://localhost:8080/ask with JSON:
{ "query": "Apa isi utama Peraturan Pemerintah tentang ..." }.
├── config/
│ └── db.js
├── dataset/
│ └── [your-pdf-files.pdf]
├── db/
│ └── migrations/
│ └── 001_init.js
├── helpers/
│ ├── ollama.js
│ └── parsePdf.js
├── index.js
├── knexFile.js
├── package.json
├── service/
│ └── pipeline.js
-
PDF Ingestion
- Place PDF files into the
dataset/folder. - The main service (
index.js) will scan and process all PDF files on startup. - No background watcher required—just add files to
dataset/before running, or rerun service after adding new files.
- Place PDF files into the
-
PDF Parsing & Chunking
- Each PDF is parsed using the helper in
helpers/parsePdf.js. - The content is split into chunks (e.g. per page or per 500 words) for optimal semantic processing.
- Each PDF is parsed using the helper in
-
Embedding Generation
- Each text chunk is sent to Ollama (
helpers/ollama.js) to generate vector embeddings usingnomic-embed-text.
- Each text chunk is sent to Ollama (
-
Database Storage
- Metadata, text chunks, and their embeddings are saved to your SQL database (MySQL/PostgreSQL) via Knex (
config/db.js). - All migration/schema is managed in
db/migrations/.
- Metadata, text chunks, and their embeddings are saved to your SQL database (MySQL/PostgreSQL) via Knex (
-
Question Answering API
- User sends a POST request to
/ask(handled inindex.jsor your Express API layer). - The system:
- Embeds the user query (with Ollama)
- Searches the most relevant text chunks from the database using full-text search and/or cosine similarity on embeddings
- Selects top-N best-matching chunks as context
- Builds a prompt for the LLM model (e.g. llama3.2 via Ollama)
- Generates and returns the answer to the user
- User sends a POST request to
-
Result Delivery
- The user receives the answer and (optionally) reference to the most relevant documents/chunks.
MIT © NeaByteLab