By the end of this post you will have a working RAG in one Python file: Qdrant stores the vectors, bge-m3 turns text into them, and a 7B model answers from what comes back. You will also have a way to check it with numbers instead of a feeling. It should fit on a 16 GB laptop, though we did not measure one; we measured it on two DGX Sparks.
What you need
- Docker, for Qdrant.
- Ollama with two models:
ollama pull bge-m3andollama pull qwen2.5:7b-instruct. - Python 3 with
requests. No framework, no API key. - A folder of Markdown or text files. We used 50 of our own published Spanish posts.
If you already run our n8n tutorial, this is the same idea without the workflow editor, so you can see every step.
Step 1: start Qdrant
docker run -d --name qdrant -p 6333:6333 -v qdrant_data:/qdrant/storage qdrant/qdrant
curl -s localhost:6333/collections
# {"result":{"collections":[]},"status":"ok",...}If the port is taken, map another (-p 6334:6333) and change QDRANT in the script.
Step 2: the whole pipeline in one file
Save this as rag_local.py. It cuts each file into chunks at word boundaries, embeds them with bge-m3, stores them in Qdrant and answers with the 7B model through Ollama’s OpenAI-style endpoint.
import sys, uuid, pathlib, requests
OLLAMA = "http://localhost:11434"
QDRANT = "http://localhost:6333"
LLM = "http://localhost:11434/v1" # Ollama's OpenAI-style endpoint (vLLM: :8000/v1)
LLM_MODEL = "qwen2.5:7b-instruct"
COLL, SIZE = "docs", 1000 # chunk size in characters
def chunks(text, size=SIZE, overlap=150):
words, out, i = text.split(), [], 0
while i < len(words):
start, cur, n = i, [], 0
while i < len(words) and (not cur or n + len(words[i]) < size):
cur.append(words[i]); n += len(words[i]) + 1; i += 1
out.append(" ".join(cur))
if i >= len(words): break
back = 0
while back < overlap and i > start + 1:
i -= 1; back += len(words[i]) + 1
return out
def embed(texts):
r = requests.post(f"{OLLAMA}/api/embed", json={"model": "bge-m3", "input": texts})
return r.json()["embeddings"]
def ingest(folder):
pts = []
for f in sorted(pathlib.Path(folder).glob("*.md")):
parts = chunks(f.read_text())
for vec, part in zip(embed(parts), parts):
pts.append({"id": str(uuid.uuid4()), "vector": vec, "payload": {"doc": f.stem, "text": part}})
requests.delete(f"{QDRANT}/collections/{COLL}") # re-ingest from scratch
requests.put(f"{QDRANT}/collections/{COLL}", json={"vectors": {"size": len(pts[0]["vector"]), "distance": "Cosine"}})
requests.put(f"{QDRANT}/collections/{COLL}/points?wait=true", json={"points": pts})
print(len(pts), "chunks")
def ask(question, k=5):
hits = requests.post(f"{QDRANT}/collections/{COLL}/points/query",
json={"query": embed([question])[0], "limit": k, "with_payload": True}).json()
ctx = "\n\n".join(f"[{p['payload']['doc']}] {p['payload']['text']}" for p in hits["result"]["points"])
msgs = [{"role": "system", "content": "Answer only from the context. If it is not there, say: I don't know."},
{"role": "user", "content": f"Context:\n{ctx}\n\nQuestion: {question}"}]
r = requests.post(f"{LLM}/chat/completions", json={"model": LLM_MODEL, "messages": msgs, "temperature": 0})
print(r.json()["choices"][0]["message"]["content"])
if __name__ == "__main__":
ingest(sys.argv[2]) if sys.argv[1] == "ingest" else ask(sys.argv[2])For a very large folder, send the points to Qdrant in batches of a few hundred instead of one request.
Step 3: ingest and ask
python3 rag_local.py ingest ./my-docs
# 34 chunks
python3 rag_local.py ask "¿Cuánto daba el Kit Digital a una microempresa?"
# El Kit Digital proporcionaba un bono de 6.000 EUR a una microempresa, ...That output is from our smoke test with three posts on 2026-11-02. On 2026-11-03 we reran the script unchanged with qwen2.5:7b-instruct on Ollama (the 4-bit Q4_K_M build) over six posts: it indexed 70 chunks and answered “6,000 EUR” to the same question. Each chunk reaches the model with the name of its document, so you can open the source and check it.
Step 4: measure it before you trust it
A RAG that “seems fine” fails on the question nobody tried. Write questions the way your colleagues would ask them, and for each one write down which document answers it. That is the gold. Then score the retriever on its own:
- hit@5: share of questions whose gold document is among the first five documents returned.
- MRR: the average of 1 / (rank of the first gold document). Rank 1 scores 1, rank 2 scores 0.5, a miss scores 0.
We wrote 60 questions by hand over 50 posts and froze them in rag-embeddings-es-questions-2026-11-02.json. No model wrote a question or a gold id. If you want to practise the ranking step first, our top-k retrieval exercise runs in the browser. For the wider method, read AI evaluations: test your RAG before production.
What we measured
Measured 2026-11-02. Embeddings: bge-m3 on Ollama 0.34.0 on our second DGX Spark (GB10, 128 GB). Qdrant 1.18.2 and the reranker (BAAI/bge-reranker-v2-m3) on the first Spark. Answers: Qwen2.5-7B-Instruct in BF16 on vLLM, temperature 0, top 5 chunks. The step 2 script uses Ollama’s 4-bit build instead; the tables below were not measured with it. Corpus: 50 Spanish posts, 501,917 characters. Chunks overlap by 15 %. Raw file: rag-embeddings-es-2026-11-02.json.
python3 scripts/bench/rag_embeddings_es.py --ollama http://<second-box>:11434 \
--qdrant http://localhost:6333 --reranker http://localhost:8201 --llm http://localhost:8200/v1 \
--out docs/measurements/rag-embeddings-es-2026-11-02.jsonRetrieval, 60 questions (a document counts once, at its best chunk; the reranker re-scores the top 40 chunks):
| Chunk size | Chunks | hit@1 | hit@5 | MRR | hit@5 + reranker | MRR + reranker |
|---|---|---|---|---|---|---|
| 500 characters | 1,229 | 81.7 % | 96.7 % | 0.885 | 100 % | 0.908 |
| 1,000 characters | 610 | 78.3 % | 96.7 % | 0.862 | 100 % | 0.928 |
| 2,000 characters | 310 | 83.3 % | 100 % | 0.895 | 100 % | 0.947 |
What the 7B model paid for it (medians over 60 answers, after reranking):
| Chunk size | Prompt tokens | Answer time | Grounding | ”I don’t know” |
|---|---|---|---|---|
| 500 characters | 839 | 3.6 s | 0.87 | 4 of 60 |
| 1,000 characters | 1,637 | 4.0 s | 0.93 | 3 of 60 |
| 2,000 characters | 3,178 | 5.2 s | 0.94 | 2 of 60 |
Grounding is the share of answer sentences that the reranker scores at 0.35 or more against the five chunks (mean over answers). It is a machine check, not a human one.
Three things the tables say.
With 60 questions, small gaps are noise. The 95 % margin on a hit@5 of 96.7 % is about ±4.5 points. The three sizes differ by one or two questions; we would not pick a winner from the first table alone.
The reranker was the bigger lever. It put every gold document in the top five at all three sizes and raised MRR by 0.02 to 0.07. A cross-encoder reads the question and the chunk together, which is slower per chunk but only runs on 40 of them.
Bigger chunks cost the model, not the retriever. Going from 1,000 to 2,000 characters nearly doubled the prompt (1,637 to 3,178 tokens) and added about 1.3 seconds per answer. On a small box with a short context window, that is the number that decides.
What the spec sheet won’t tell you
- A hit is not an answer. Even with the right document in the top five, the 7B said “I don’t know” two to four times in 60. The model reads five chunks, not five documents, so a document can rank high while its useful chunk stays out.
- Tables are hard to find. One of the two questions missed most often across the 11 runs with all three embedding models (6 of 11 left it out of the top five) was “what do I buy for 1,000 euros?”: the answer sits in one row of a hardware table. Our reading is that a chunk of table rows says little that looks like a question; we did not test that further.
- The grounding check has blind spots. One answer quoted its source almost word for word and still scored 0. Use it to find answers to read, not to grade them.
- Our set is easier than your folder. 50 clean posts and questions written by the person who read them. A shared drive with scanned PDFs and five versions of the same contract will score lower. Measure yours.
Verdict
- Start at 1,000 to 2,000 characters with 15 % overlap, then measure on your own questions.
- Add a reranker before you tune anything else. It was the cheapest gain we measured.
- Keep the gold file. Twenty questions with their documents is enough to catch a regression when you change a model or a setting.
When not to do this
If your documents fit in the model’s context (a handful of policies, one manual), skip retrieval and paste them in. If you need a visual workflow that other people will edit, the n8n version is easier to hand over. And if nobody will maintain the index when documents change, a RAG goes stale quietly; plan who re-runs the ingest.
Next steps
- Pick the embedding model with the same 60 questions: best local embedding model for Spanish, measured.
- Put the answers in front of your office: Open WebUI for a 10-person office.
- Pull fields out of your documents as JSON before you index them: Ollama structured output, 40 invoices measured.
- Let an agent call your RAG as a tool: n8n and MCP, or start with three local agents for an SME.
Work with us
We size the model and the machine by measuring, not by guessing. If you want to see your own documents answered on real hardware, book a free 15-minute call or see how we work in consulting.