Wednesday, May 6, 2026

Topic Routing in RAG Pipelines

In older RAG systems, topic routing was used to narrow down area to be searched for similarity. Today it has been largely become redundant due to popular use of hierarchical clustering techniques. But still when you progress to  RAG systems with huge, multidomain datasets as inputs, topic routing can be of immense help. In any retrieval pipeline, topic routing will be come high in the hierarchy, typically it will be the second step, even before chunking. 


Essence: Instead of searching all knowledge, route the query to the right retriever.

Example:

User Query:
"How many PTO days do employees get?"

Router decides:
→ HR retriever

Another query:

"How do Kubernetes taints work?"

Router decides:
→ Engineering retriever



Algorithms for Topic Routing


A. Classification Models

Train a classifier:

query → topic label

Algorithms:

  • Logistic Regression
  • SVM
  • Random Forest
  • small transformer classifiers
  • BERT classifiers

Example:

"leave policy"
→ HR

"invoice tax"
→ Finance

B. Embedding-based Routing

No classifier needed.

You maintain topic embeddings:

HR centroid
Finance centroid
Engineering centroid

Then:

query embedding

nearest topic centroid

This is lightweight and common.


C. LLM Routing

Modern systems use an LLM itself:

Classify this query into:
- HR
- Legal
- Engineering
- Finance

This is flexible but slower and costlier.

No comments:

Post a Comment

LangChain and LlamaIndex

  Aspect LangChain LlamaIndex Winner / Notes Primary Strength Orchestration, Agents & Workflows Data Indexing & Advanced RAG LlamaIn...