Route each question to the right Qdrant collection, with one embedder
+The RAG capstone put the whole docs corpus in one vector collection and searched it for every question. That works until your corpus spans several domains that share vocabulary. Ask "how do I open a firewall port?" against one mixed collection and the top results can include compute or storage chunks that happen to mention ports — noise the generator then has to reason around.
The fix is older than RAG: don't search everything, search the right shelf. Split the corpus into one collection per domain, decide which domain a question belongs to, and search only that one. The twist that makes it cheap: you can do the deciding with the same embedder you already use for retrieval — no second model.
This post builds that on Qdrant and WEC's
bge-m3 embedding endpoint, measures it against the mixed-collection baseline, and is
honest about the query where it falls down — because that failure is the whole reason
to understand when routing helps.
The version of this idea that circulates externally routes between different embedding
models per domain. Don't. WEC Inference serves one embedding model, bge-m3, and vectors
from two different embedders live in different spaces — collections built by them can
never be compared. We route between collections, all built by the same bge-m3.
Prerequisites
- A WEC Inference API key with access to
bge-m3(see the Models Hub and API Keys docs). - Docker, to run Qdrant locally.
- Python 3.10+.
Export your key so the scripts can read it:
export WEC_API_KEY="sk-..."
Step 1 — Confirm the embedder
Everything rests on one embedding model. WEC serves bge-m3 (1024-dim, multilingual)
on /v1/embeddings — the embeddings API reference
has the full schema. Confirm it answers before building anything on it:
curl -s https://inference.wiline.com/v1/embeddings \
-H "Authorization: Bearer $WEC_API_KEY" -H "Content-Type: application/json" \
-d '{"model":"bge-m3","input":["reset my password","what is the refund policy"]}' \
| jq '{model, n: (.data|length), dim: (.data[0].embedding|length)}'
{ "model": "bge-m3", "n": 2, "dim": 1024 }

Two inputs in, two 1024-dim vectors out. That 1024 is the number every collection below is built around.
Step 2 — Start Qdrant
The official Qdrant quickstart runs a single container. Persist its storage so your collections survive a restart:
docker run -d --name qdrant-intent \
-p 6333:6333 -p 6334:6334 \
-v ~/qdrant-intent-storage:/qdrant/storage \
qdrant/qdrant
Open the dashboard at http://<host>:6333/dashboard — it starts empty.

Step 3 — Ingest: one collection per domain
Bucket the corpus by domain, embed each chunk with bge-m3, and write one Qdrant
collection per bucket. Here the "domains" are the four top-level sections of the WEC
docs — compute, storage, networks, inference. The same loop also stores one
centroid per domain (the mean of its vectors) in a small routes collection; that
is what the router matches against in Step 4.
# ingest.py (essential parts)
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct
client = QdrantClient(url="http://127.0.0.1:6333")
DOMAINS, DIM = ["compute", "storage", "networks", "inference"], 1024
def embed(texts): # POST /v1/embeddings, model bge-m3 -> list of 1024-dim vectors
...
route_vecs = []
for d in DOMAINS:
texts = load_and_chunk(d) # read docs/<d>/*.md, strip, chunk
vecs = batched_embed(texts) # bge-m3, 32 at a time
if client.collection_exists(d):
client.delete_collection(d)
client.create_collection(d, vectors_config=VectorParams(size=DIM, distance=Distance.COSINE))
client.upsert(d, points=[
PointStruct(id=i, vector=vecs[i], payload={"text": texts[i], "domain": d})
for i in range(len(vecs))])
route_vecs.append([sum(v[i] for v in vecs)/len(vecs) for i in range(DIM)]) # centroid
# one point per domain = its centroid, for routing
client.create_collection("routes", vectors_config=VectorParams(size=DIM, distance=Distance.COSINE))
client.upsert("routes", points=[
PointStruct(id=i, vector=route_vecs[i], payload={"domain": DOMAINS[i]}) for i in range(len(DOMAINS))])
recreate_collection is deprecated. The pattern above — collection_exists → delete_collection
→ create_collection — is what current Qdrant recommends.
Run it:
compute 45 chunks -> collection 'compute'
storage 31 chunks -> collection 'storage'
networks 36 chunks -> collection 'networks'
inference 47 chunks -> collection 'inference'
routes 4 centroids -> collection 'routes'

The dashboard now shows five collections, all 1024-dim Cosine, with their chunk counts:

Step 4 — Route by centroid
Embed the question once, match it against the four centroids in routes, and the
nearest one names the collection to search. Qdrant's
search does both the routing and
the retrieval — it is the same query_points call, once against routes and once
against the winning domain.
# router.py (essential parts)
def route(vec):
pts = client.query_points("routes", query=vec, limit=4).points
return [(p.payload["domain"], round(p.score, 3)) for p in pts]
def search(domain, vec, k=3):
return client.query_points(domain, query=vec, limit=k).points
vec = embed(question)
ranked = route(vec) # e.g. [('networks', 0.66), ('compute', 0.631), ...]
picked = ranked[0][0]
hits = search(picked, vec)
Q: set up a VPC and a firewall rule
route scores: [('networks', 0.66), ('compute', 0.631), ('inference', 0.517), ('storage', 0.503)]
picked collection: networks
[0.625] subnets.md: ... Network Range: 10.80.4.0/24 ...
[0.621] vpcs.md: ... relationships between VPC components ...
[0.611] vpcs.md: ... Edit Rule — modify protocol, ports, or CIDR ...

Step 5 — Routed vs. one mixed collection
Does routing actually beat searching everything? Build the baseline — one all
collection holding every chunk (copy the points out of the domain collections with
Qdrant's scroll, no
re-embedding) — then run the same questions both ways and count how many of each top-5
come from the wrong domain.
# compare.py (essential parts)
for q, want in QUERIES:
vec = embed(q)
picked = client.query_points("routes", query=vec, limit=1).points[0].payload["domain"]
routed = client.query_points(picked, query=vec, limit=5).points # one domain
mixed = client.query_points("all", query=vec, limit=5).points # everything
routed_wrong = sum(h.payload["domain"] != want for h in routed)
mixed_wrong = sum(h.payload["domain"] != want for h in mixed)
Q: open a firewall port on my VPC subnet
want=networks routed->networks routed wrong: 0 | mixed wrong: 2
mixed domains in top-5: ['compute', 'networks', 'networks', 'networks', 'compute']
Q: give my server a public IP
want=networks routed->networks routed wrong: 0 | mixed wrong: 3
TOTAL wrong-domain hits across 6 queries (top-5):
routed: 5 mixed: 8

Across six questions, routing cut wrong-domain hits from 8 to 5. On the clear cases
the win is total: "open a firewall port" routes to networks and returns five
in-domain chunks, while the mixed collection drags in two compute chunks that mention
ports. The generator never sees the noise because the noise was never retrieved.
Where it breaks — the ambiguous query
Now the honest part. One of the six made routing worse:
Q: how do I resize a running instance?
want=compute routed->inference routed wrong: 5 | mixed wrong: 3
"Resize a running instance" is a compute question, but it routed to inference. Look at
the centroid scores and you see why — it is a genuine tie, not a bug:
inference 0.5840
compute 0.5554
The words instance and running appear in the inference docs (model instances, running a model) often enough that the inference centroid edges out compute by 0.03. When routing is that close, committing to one collection is a coin flip, and here it lost — so every one of the five results came from the wrong shelf.
The tempting fix is a confidence guard: if the top two centroid scores are within a
margin, don't commit — fall back to the mixed collection, or search the top two domains
and merge. We tried both. Each one rescued the resize-instance query and broke
another: "give my server a public IP" routes correctly to networks on its own, but
its margin over compute is also thin, so the guard flagged it ambiguous, mixed in
compute, and turned a clean 0-wrong result into 3. Net across the six, the guard scored
6 — worse than plain routing's 5.
The lesson is not "add a threshold." It is that centroid routing is only as good as the separation between your domains, and a margin heuristic trades one error class for another. Where domains are distinct (networks vs storage), routing is a clean win; where they genuinely overlap (compute vs inference around "instances"), no cheap router saves you, and the margin threshold is a workload-specific dial, not a fix.
What this did and didn't buy you
It bought cheaper, cleaner retrieval on a multi-domain corpus, with one embedder and
no extra model: route in one bge-m3 call, search one collection, and the cross-domain
noise the mixed collection returned (8 hits) drops (to 5). The clear-domain queries went
to zero wrong hits.
It did not buy a free lunch on ambiguous queries. A thin-margin route is a guess, and dressing it up with a confidence threshold just moves the error. Measure the separation between your own domains before trusting the route — and when two domains genuinely overlap, consider merging them into one collection rather than pretending a router can tell them apart.
This is the retrieval-side companion to routing generation by complexity: there you pick the model by how hard the request is; here you pick the collection by what the request is about. Same instinct — don't send every request down one path — one layer earlier.
You can build the stack and measure it — that's stage ④. The last stage makes it safe to run where it matters: start by locking down the Docker networks between your services.
