How hacktronaut/ollama-rag-demo works
Project type and purpose
• This is a Node.js‐based command‐line Retrieval Augmented Generation (RAG) demo.
• It uses langchain.js to orchestrate retrieval + LLM calls, Ollama as the local LLM provider, and ChromaDB as the vector store.
• Purpose: ingest a corpus (utils/data.txt), index it (loadData.js), then answer user questions with context from the corpus (index.js).
File structure
• Top level:
• package.json / package-lock.json – Node dependencies (langchain, ollama, chroma)
• index.js – entry point for QA pipeline
• utils/
– data.txt – raw documents to index
– loadData.js – script to load documents, compute embeddings, and push to ChromaDB
• No frontend or multiple microservices—just a simple backend pipeline with two scripts.
• Configuration is embedded in code (baseUrl, model, collectionName, url).
README for additional insights
• Confirms the two‐step process:
a) run loadData.js to index documents
b) run index.js to start QA
• Shows how to configure OllamaEmbeddings and Ollama LLM instances, and how to connect to ChromaDB.
• Highlights dynamic prompt templates and RAG-powered QA flow.
a. Main components
1. Data Source (utils/data.txt)
2. Embedding Service (OllamaEmbeddings via ollama‐inference API)
3. Vector Store (ChromaDB instance)
4. QA Application (index.js running langchain.js chains)
5. LLM Service (Ollama LLM model via ollama‐inference API)
6. User (CLI)
b. Relationships & data flow
1. loadData.js reads data.txt → sends each doc to Embedding Service → receives embeddings → writes to Vector Store
2. index.js receives user question → Optionally uses prompt template → Vector Store searches with embeddings to retrieve top‐k docs → constructs augmented prompt → sends to LLM Service → returns answer → prints to user
c. Architectural patterns & principles
• Retrieval-Augmented Generation pipeline: separation of indexing vs. query-time retrieval
• Modular – data ingestion (utility script) is decoupled from QA runtime
• Single responsibility: index.js orchestrates only query-time flow; loadData.js handles ingestion
d. Key technologies
• Node.js (runtime)
• langchain.js (pipeline orchestration)
• OllamaEmbeddings & Ollama LLM (local LLM via HTTP)
• ChromaDB (vector store for similarity search)