Paj Digital Labs
All articles
AI & Automation

Embeddings in Practice: Chunking, Dimensions and Why Your Search Still Feels Dumb

Vector search is easy to set up and hard to make good. The chunking choices, hybrid ranking and evaluation habits that turn a demo-quality semantic search into one people actually trust.

Paj Digital Labs 3 min read
Robotic gripper sorting components on a laboratory workbench
Editorial illustration · AI & Automation

You embedded your docs, dropped them into a vector database, and wired up a search box. Someone types "how do I cancel" and gets back a paragraph about cancelling a webhook subscription instead of the account cancellation page. The vectors are working perfectly. The search is still dumb.

Semantic search quality comes from the boring decisions around the embeddings, not the embeddings themselves.

Chunking decides everything

An embedding represents a chunk of text as a single point. If the chunk covers three topics, the point lands somewhere in the middle of all three and matches none of them well.

What has worked for me:

  • Split on structure first. Headings, sections, list boundaries. A section under "Cancelling your account" should be its own chunk.
  • Target 200–500 tokens. Smaller chunks match precisely but lose context; larger ones blur.
  • Overlap 10–15%. So a sentence that bridges two sections is findable from either side.
  • Prepend the title path. Embed "Billing > Cancelling your account > Refunds" along with the chunk text. This one change often fixes more ranking problems than switching models.
python
def chunk_text(doc):
    for section in split_by_headings(doc):
        prefix = class="text-code-string">" > ".join(section.heading_path)
        for piece in window(section.text, size=400, overlap=50):
            yield fclass="text-code-string">"{prefix}\n\n{piece}"

Dimensions and model choice matter less than you think

Teams spend weeks benchmarking embedding models and then chunk their content by fixed character count. Pick a well-regarded current model, use its default dimensions, and spend your time on chunking and evaluation. If storage cost matters, many models support truncated dimensions with modest quality loss — measure it on your own data before deciding.

Go hybrid

Pure vector search is bad at exact terms: error codes, product names, SKUs, function names. Someone searching for ERR_SSL_PROTOCOL_ERROR wants the page with that exact string, not a page about TLS in general.

Hybrid search combines keyword (BM25) and vector results. The simplest merge that works well is reciprocal rank fusion:

python
def rrf(rankings, k=60):
    scores = {}
    for ranking in rankings:
        for rank, doc_id in enumerate(ranking):
            scores[doc_id] = scores.get(doc_id, 0) + 1 / (k + rank)
    return sorted(scores, key=scores.get, reverse=True)

No tuning of score scales, no weights to argue about. It just works surprisingly well.

Add a reranker for the top results

Retrieve 50 candidates cheaply, then run a cross-encoder reranker over them to pick the top 5. Rerankers read the query and document together, which makes them far more accurate than comparing two independent vectors. The latency cost is real but small when limited to a few dozen candidates.

Build an evaluation set before tuning anything

Collect 50–100 real queries from your search logs and mark the correct result for each. Then measure:

| Metric | What it tells you | |---|---| | Recall@10 | Is the right answer anywhere in the top 10? | | MRR | How high does the right answer usually rank? | | Zero-result rate | How often search finds nothing useful |

Every change — chunk size, hybrid weights, a new model — gets run against this set. Without it you are tuning by vibes, and vibes are biased toward whatever query you tested last.

Keep the index fresh

Stale embeddings are a silent failure. When a doc changes, its chunks must be re-embedded and the old ones deleted. I store a content hash per chunk and re-embed only what changed, which keeps nightly sync jobs cheap.

Show your work in the UI

Display the matched section heading and a highlighted snippet, not just a page title. Users judge relevance in a second when they can see why a result matched, and they forgive an imperfect ranking much faster.

Good semantic search is about 20% embeddings and 80% chunking, hybrid ranking, evaluation and freshness. Do the boring parts and the dumb search gets smart.

Paj Digital Labs

The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.

Related reading