- Node.js 20+
- Ollama installed locally
npm install
Create .env.local based on .env.example:
cp .env.example .env.local
Pull a local model for Ollama:
ollama pull llama3
This parses the HTML/PDF files in docs/, chunks them, generates embeddings, and writes
data/knowledge-base.json.
npm run ingest
npm run dev
Then open http://localhost:3000 and ask questions about the documents.
- Ingestion:
scripts/ingest.tsparses the HTML/PDFs, normalizes text, chunks it, and generates embeddings with@xenova/transformers. Output is stored locally as a JSON knowledge base. - Retrieval:
src/lib/retrieval.tsloads the knowledge base, embeds the user query, computes cosine similarity, and returns top-K chunks with source metadata. - LLM:
src/lib/ollama.tscalls a local Ollama model with the retrieved context. - API:
/api/chatwires retrieval + Ollama and returns{ answer, sources }. - UI: A simple chat UI renders messages and source citations.
- The documents live in
docs/and are the only supported formats (HTML + PDF). - Source attribution is derived from document metadata (doc name, section, page).