Build a Semantic Search Engine in 20 Minutes

📘 Tutorials 2026-07-19 · Updated 2026-11-27 5 min read

Build a Semantic Search Engine in 20 Minutes: Chroma and Qdrant, Step by Step

Keyword search has an obvious failure mode: a user searches "how do I get my money back" while the document says "refund procedure". No shared tokens, no results. Semantic search compares meaning instead of characters.

📜 Table of Contents

📖 Keep reading

Build a Semantic Search Engine in 20 Minutes: Chroma and Qdrant, Step by Step

Keyword search has an obvious failure mode: a user searches "how do I get my money back" while the document says "refund procedure". No shared tokens, no results. Semantic search compares meaning instead of characters. This runs the same document set through Chroma and Qdrant, covering ingest, chunking, retrieval, and recall measurement, with runnable code. It ends with a selection table and a hybrid retrieval pattern, because pure vector search is rarely enough in production.

Three Steps Before You Pick a Database

documents -> chunk -> embed -> store
question  -> embed -> similarity search -> fetch text -> (optional) rerank

The vector database only owns storage and nearest-neighbour search. Chunking and the embedding model decide quality. A wrong database is an inconvenience; wrong chunking means nothing is findable.

Chroma: Ten Minutes to Validate

pip install chromadb
import chromadb

client = chromadb.PersistentClient(path="./chroma_db")
col = client.get_or_create_collection("docs")

col.add(
    documents=[
        "Refunds must be requested within 7 days of delivery, item intact.",
        "Member points can offset checkout, 100 points = 1 unit of currency.",
        "Electronic invoices are issued within 48 hours if selected at checkout.",
    ],
    ids=["refund-1", "points-1", "invoice-1"],
    metadatas=[{"type": "policy"}, {"type": "benefit"}, {"type": "finance"}],
)

res = col.query(query_texts=["how do I get my money back"], n_results=2)
print(res["documents"])

chromadb.Client() is in-memory and loses everything on exit. Use PersistentClient for durability; that is pitfall one. The default embedder is all-MiniLM-L6-v2 running locally, which is free and keyless but weak on Chinese, so swap in a multilingual model or your own embedding service before production.

n_results is not a quality dial. Three to five chunks is plenty for an LLM; twenty drags noise into context, costing more and answering worse.

Qdrant: One Service, Many Capabilities

docker run -d -p 6333:6333 -p 6334:6334 \
  -v $(pwd)/qdrant_storage:/qdrant/storage \
  qdrant/qdrant
from qdrant_client import QdrantClient, models

client = QdrantClient(url="http://localhost:6333")
client.recreate_collection(
    collection_name="docs",
    vectors_config=models.VectorParams(size=384, distance=models.Distance.COSINE),
)

client.upsert(
    collection_name="docs",
    points=[
        models.PointStruct(
            id=1,
            vector=[0.01] * 384,
            payload={"text": "Refunds within 7 days of delivery", "type": "policy"},
        )
    ],
)

hits = client.query_points(
    collection_name="docs",
    query=[0.01] * 384,
    limit=3,
    query_filter=models.Filter(
        must=[models.FieldCondition(key="type", match=models.MatchValue(value="policy"))]
    ),
).points

size must match your embedder's output dimension. Getting it wrong either errors loudly or, worse, silently ruins similarity. That is the most common initialisation bug.

What Qdrant adds over Chroma is exactly what production needs: payload filtering (tenant, date, category before vector search), quantisation (float32 to int8, roughly a quarter of the memory), distributed mode, and snapshots. At tens of thousands of rows you need none of it; at millions you cannot live without it.

Chunking Parameters

Content Chunk size Overlap Note
Chinese docs 400-700 chars 50-80 One idea per chunk, no mid-sentence cuts
Contracts 300-500 chars ~100 Many cross-references; overlap generously
Code Per function 0 Split by syntax, not length
Tables One row plus header 0 Every chunk needs the header or numbers lose meaning
FAQ One Q&A 0 Naturally aligned, best results

Chunking is the first lever. Rewriting 2000-character hard cuts into 500-character paragraph cuts visibly lifts recall with zero model changes.

Measuring Whether It Works

Prepare 30 real questions, label the document each should hit, then compute two numbers. Recall@3: share of questions whose answer appears in the top three; below 70 percent points at chunking or embeddings. MRR: rewards correct results ranked higher, useful for comparing two configurations. An hour here saves days of blind tuning: low recall means fix chunking; high recall with bad ordering means change the embedder or add reranking.

Pure Vectors Are Not Enough

Vectors capture meaning but miss exact strings. Searching a model number A1001 or an error code ERR_2048 often returns semantically adjacent nonsense. Hybrid retrieval: take top 20 by vector plus top 20 by BM25, fuse with reciprocal rank fusion (score = sum 1/(60 + rank)), pass the top five to the model. RRF needs no weight tuning, which is why it is the pragmatic default. Qdrant supports sparse vectors natively for in-database hybrid; with Chroma you fuse BM25 in application code.

Which One

Situation Choice Why
Local prototype, notebook Chroma pip install, no service
Single-host production, hundreds of thousands Chroma can cope Concurrency and filtering are limited
Filter by tenant or date Qdrant Native payload filters
Millions of rows, replicas Qdrant or Milvus Distribution, quantisation, snapshots
No ops appetite Managed service Pay per use, no maintenance

FAQ

Do I need a vector database at all? Not under a few tens of thousands of rows. Storing vectors as blobs and computing cosine in memory answers in milliseconds. A vector DB buys filtering, durability, and scale.

Which embedding model? For Chinese, pick multilingual models and check the Chinese MTEB subsets, then validate on your own 30 questions. Leaderboard rank and your corpus often disagree.

Should I add BM25? If the domain has model numbers, IDs, error codes, or names, yes. Pure vectors fail those regularly.

Retrieval is right but answers are wrong? That is generation, not retrieval. Check that the prompt says "answer only from the supplied context" and gives an explicit "say you don't know" path.

Note: client APIs change between releases (Qdrant's retrieval method names, for example). Follow the official docs.

Related Articles
2026-07-19
AnythingLLM Tutorial: Manage All AI Models in One Interface
2026-08-06
Prompt Injection Detector: Catch Attacks Before They Reach Your LLM
2026-07-10
I used AI as a Rust mentor - it taught better than any textbook
2026-08-05
AI Meeting Notes App in 2026: faster-whisper (25k Stars) + WhisperX Local Pipeline - Free Transcription with Speaker Labels
2026-07-16
Prompt Engineering Techniques 2026
2026-08-06
Nanobrowser (13,530 Stars) 2026: The Open-Source Chrome Extension for AI-Powered Web Research

Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.

💬 Comments (0)

No comments yet. Be the first!

Login to comment