I built my first RAG system two years ago. It cost me $400 in OpenAI API calls before I realized the team was querying the same 50 documents repeatedly. We were paying per token for retrieval over a static knowledge base. That's when it clicked-most RAG use cases don't need a frontier model in the cloud. They need a decent local model, a vector store that doesn't require a PhD to operate, and a framework that gets out of your way.
If you've ever wanted to run a production-grade retrieval-augmented chatbot on your own infrastructure-on a laptop, a homelab server, or a single VPS-this is the stack I'd recommend in 2025: LangChain for orchestration, ChromaDB for vector storage, and Ollama for the LLM runtime. No API keys. No per-token billing. No data leaving your network.
Let me walk you through building one end-to-end, including the parts most tutorials skip: chunking strategy, retrieval tuning, conversation memory, caching, monitoring, and Docker deployment.
$32
Prerequisites
You'll need:
- A machine with at least 16GB RAM (32GB if you want to run 14B+ models comfortably)
- Python 3.10 or newer
- Ollama installed (we'll cover this)
- Around 10GB free disk for models and the vector store
- Basic familiarity with Python and the command line
For the LLM, I'll use Llama 3.1 8B through this guide. It's a solid default-small enough to run on a laptop, capable enough for most RAG tasks. If you have more RAM, swap in qwen2.5:14b or mistral-nemo and the code stays the same.
Architecture Overview
Here's the request flow for our chatbot:
┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │ User │────▶│ LangChain │────▶│ Retriever │ │ Query │ │ Chain │ │ (ChromaDB) │ └─────────────┘ └──────────────┘ └─────────────┘ │ │ │ ▼ │ ┌─────────────┐ │ │ Top-K Docs │ │ └─────────────┘ ▼ │ ┌─────────────┐ │ │ Ollama │◀─────────────┘ │ (Llama3) │ └─────────────┘ │ ▼ ┌─────────────┐ │ Response │ └─────────────┘ The pipeline is straightforward:
- User sends a query.
- LangChain embeds the query using a local embedding model.
- ChromaDB returns the top-K most similar document chunks.
- Those chunks get injected into the LLM prompt as context.
- Ollama generates the final answer.
- Conversation history is preserved for follow-up questions.
The ingestion pipeline (run separately) looks like:
PDF/Markdown/Code ──▶ Loader ──▶ Splitter ──▶ Embedder ──▶ ChromaDB Project Structure
local-rag/ ├── app/ │ ├── __init__.py │ ├── config.py │ ├── ingest.py │ ├── retriever.py │ ├── chain.py │ └── cli.py ├── data/ │ └── docs/ # Source documents ├── chroma_db/ # Persisted vector store ├── .env ├── requirements.txt ├── Dockerfile └── docker-compose.yml Keep chroma_db/ on a persistent volume in production. Lose that directory and you'll re-embed your entire corpus, which for large datasets means hours of compute and a window where the chatbot returns zero results.
Installing Ollama and Pulling Models
Install Ollama from ollama.com or via the install script:
curl -fsSL https://ollama.com/install.sh | sh Pull the models we'll use:
# The chat model ollama pull llama3.1:8b # The embedding model (lightweight, fast, good enough for most use cases) ollama pull nomic-embed-text Verify they're running:
ollama list ollama serve # starts the API on http://localhost:11434 I prefer nomic-embed-text over OpenAI's text-embedding-3-small for local setups. It's a 137M parameter model, runs in milliseconds on CPU, and produces embeddings competitive with proprietary options on standard benchmarks. If you need multilingual support, swap in bge-m3.
$33
$34
$35
$36
$37
$38
Caching Embeddings and LLM Calls
Embedding the same chunk twice is wasted compute. LangChain supports caching out of the box:
from langchain_core.globals import set_llm_cache from langchain_community.cache import InMemoryCache set_llm_cache(InMemoryCache()) For persistence, use SQLite:
from langchain_community.cache import SQLiteCache set_llm_cache(SQLiteCache(database_path=".langchain.db")) This is also useful during development. When you're iterating on prompts or chunking strategies, caching the LLM calls saves you from regenerating answers for unchanged contexts-which on a local 8B model still takes 5-10 seconds per query and adds up fast when you're running evals.
$39
$3a
$3b
$3c
$3d
Alternatives Comparison
| Feature | LangChain + Chroma | LlamaIndex + Qdrant | Haystack + Weaviate |
|---|---|---|---|
| Setup complexity | Low | Medium | High |
| Local-first | Yes | Yes | Partial |
| Multi-modal RAG | Limited | Good | Excellent |
| Production maturity | Good | Excellent | Excellent |
| Community size | Largest | Large | Smaller |
| Embedding flexibility | High | High | Medium |
| Best for | Quick prototypes, internal tools | Production search | Enterprise pipelines |
I've used all three in production. LangChain wins on developer ergonomics and the size of the integration ecosystem. LlamaIndex has better ingestion pipelines for complex document types and a more opinionated (in a good way) approach to retrieval. Haystack is overkill unless you're building a search product at scale.
$3e
Cost Considerations
A breakdown for a typical small-team deployment (5-20 users, ~10K documents):
| Component | One-time | Recurring |
|---|---|---|
| VPS (16GB RAM, 4 vCPU) | - | $40/month |
| Model storage (disk) | ~$5 | - |
| Initial ingestion compute | ~2 hours | - |
| Maintenance (your time) | - | ~2 hrs/month |
Total: roughly $50/month plus your time. Compare this to per-seat pricing on hosted RAG services, which typically run $20-50/user/month. For a 10-person team, you're looking at $200-500/month vs $50/month. The break-even point is usually around 3-5 users.
The hidden cost is the ops burden. You're now responsible for uptime, updates, and incident response. If your team doesn't have bandwidth for that, the hosted option is worth the premium.
Conclusion
Local RAG has crossed the threshold from "interesting experiment" to "production-ready default" in the last year. The combination of LangChain's orchestration, ChromaDB's simplicity, and Ollama's model runtime gives you a stack that's private, predictable in cost, and fast enough for real users.
The hard part isn't the setup. It's the iteration-tuning chunk size, picking the right embedding model, deciding between semantic and hybrid search, and building the observability to know when things break. Start with the defaults in this article, ship it to your team, and refine based on actual usage. The first version will be 70% as good as it could be. That's enough to be useful, and the feedback loop will tell you what to fix next.
Originally published on Mango Developer.
