Building RAG With Open-Source Models: A Practical Starter Guide

Build a local RAG system with open-source models: Ollama for inference, LangChain for the pipeline, open embeddings, and ChromaDB. Six steps to a working app.

By Galactic News Editorial · Published 2026-11-25T05:07:14+00:00 · Updated 2026-11-25T05:07:14+00:00

Building RAG with open source models starter guide

Building RAG With Open-Source Models: A Practical Starter Guide

Retrieval-Augmented Generation, or RAG, lets a language model answer questions from your own documents. The model retrieves relevant chunks at query time and grounds its answer in them. Building RAG with open source models means the whole stack can run on your own machine. No API keys. No data leaving your network. This guide walks through the stack, the choices, and a working starter setup.

How RAG Works in Four Steps

Every RAG pipeline has the same shape. First, load documents into a structured format. Second, split them into chunks. Third, convert each chunk into a numeric vector with an embedding model. Fourth, store the vectors in a vector store. At query time, the question is embedded the same way. The store returns the closest chunks. The model answers using those chunks as context.

The pieces are swappable. That is the point of the open-source stack. Change the embedding model without touching the loader. Change the vector store without touching the model. Start simple. Improve one piece at a time.

Building RAG With Open-Source Models: The Starter Stack

Four layers make up the stack. Pick one option per layer to start.

1. The runtime: Ollama

Ollama runs open models locally. It handles downloading, quantization, and memory management. Install it, pull a model, and call it from Python or an HTTP API. It is the default local runtime in 2026. Popular starter models include Llama 3.3 and Qwen3. Both are open-weight models with strong general performance. For a small machine, a 7B or 8B quantized model is the right start. Larger models need more RAM and a GPU.

2. The framework: LangChain or LlamaIndex

LangChain is the most widely adopted choice. Its modular design lets you swap loaders, splitters, embeddings, and vector stores without rebuilding the pipeline. LlamaIndex specializes in indexing and retrieval. It suits projects with structured and unstructured data mixed together. For a first project, LangChain covers most cases. LlamaIndex is the pick when retrieval quality is the main problem. Haystack sits between the two and is built specifically for RAG.

3. The embedding model

The embedding model decides what "similar" means. Good open options include BGE-large-en-v1.5 from BAAI, with 1024 dimensions, and nomic-embed-text-v1.5, with 768 dimensions and long-context support. Both run locally. BGE-large is a strong general choice. Nomic-embed is lighter and handles long documents well. Match the embedding model to your documents. Short FAQ chunks and long contracts want different settings.

4. The vector store

ChromaDB is the simplest start. It runs in-process or as a small server. It needs no setup. pgvector adds vector search to PostgreSQL. It fits teams that already run Postgres and want one database for everything. For a single-node deployment, either works. ChromaDB is faster to start. pgvector scales further.

LayerStarter pickAlternativeWhy it fits
RuntimeOllamavLLM, llama.cppSimplest local model serving
FrameworkLangChainLlamaIndex, HaystackModular, most examples
EmbeddingsBGE-large-en-v1.5nomic-embed-text-v1.5Strong open quality
Vector storeChromaDBpgvectorZero setup to start
LLMLlama 3.3 / Qwen3DeepSeek, MistralOpen weights, local

Build It in Six Numbered Steps

  1. Collect your documents. Start with 20 to 50 files. PDFs, Markdown, and plain text are fine. Remove duplicates and outdated versions first.
  2. Load and split. Use a document loader from LangChain or LlamaIndex. Split with a recursive character splitter. A chunk size of 500 to 1,000 characters with 100 to 200 characters of overlap is a good default.
  3. Embed and store. Pick an embedding model. Embed every chunk. Store the vectors in ChromaDB. Keep the source filename and page number as metadata on each chunk.
  4. Build the retriever. Embed the question. Retrieve the top 5 chunks by similarity. This is the core of the system. Test it before adding a model.
  5. Add the generator. Pass the retrieved chunks and the question to a local model through Ollama. Instruct it to answer only from the provided context. Ask it to say when the context does not contain the answer.
  6. Evaluate with real questions. Write 20 questions your users actually ask. Check each answer against the source documents. Fix retrieval first. Most bad RAG answers are retrieval failures, not model failures.

Common Mistakes to Avoid

Chunks that are too large dilute the match. Chunks that are too small lose context. Start at 500 to 1,000 characters and adjust from test results. Never skip metadata. A chunk without its source is unverifiable. Keep the document name and page on every chunk.

Do not let the model answer from memory. The prompt must restrict it to the retrieved context. If the answer is not in the context, the correct output is "I don't know." That is a feature. A confident hallucination is worse than a refusal.

Watch the connection budget if you use pgvector. Every unpooled connection eats into PostgreSQL's default limit of 100. Use PgBouncer in transaction-pooling mode before you scale. For a single-node deployment, this is usually the first thing that breaks.

When to Add More

Start with two-step RAG: retrieve, then generate. It is simple and predictable. Add agentic RAG only when the questions need it. An agent that decides when to retrieve suits research assistants with many sources. It adds latency and complexity. Most documentation bots never need it.

Hybrid search helps when exact terms matter. Pure vector search can miss a product code or a name. Combining keyword search with vector search catches both. Add it when your test questions show missed matches on exact terms.

Bottom Line

Building RAG with open source models is a weekend project, not a research program. Ollama runs the model. LangChain wires the pipeline. BGE or nomic-embed handles similarity. ChromaDB stores the vectors. Start with 20 documents and 20 test questions. Fix retrieval before blaming the model. The stack is free, local, and private. The quality comes from your documents and your tests.