Skip to main content
Indexes are critical components in Semantic Router that store and retrieve embeddings efficiently. They act as the search backend that enables Semantic Router to find the most relevant routes for incoming queries.

Understanding Indexes

In Semantic Router, an index serves several key purposes:
  1. Store embeddings of route utterances
  2. Search for similar vectors when routing queries
  3. Persist route configurations across sessions
  4. Scale to handle large numbers of routes and utterances
The choice of index can significantly impact the performance, scalability, and persistence capabilities of your semantic routing system.

Local vs. Remote Indexes

Semantic Router supports both local (in-memory) and remote (cloud-based) indexes:

Local Indexes

Local indexes store embeddings in memory, making them fast but ephemeral. They’re perfect for development, testing, or applications with a small number of routes. Example usage:

Remote Indexes

Remote indexes store embeddings in cloud-based vector databases, making them persistent and scalable. They’re ideal for production applications or systems with many routes. Example usage with Pinecone:

Hybrid Indexes

For advanced use cases, Semantic Router also provides a hybrid index that combines both dense and sparse embeddings:

Supported Indexes

Auto-Sync Feature

Semantic Router provides an auto-sync feature that keeps your routes in sync between local and remote indexes:
Auto-sync modes:
  • "local": Sync from remote to local (pull)
  • "remote": Sync from local to remote (push)
  • None: No automatic syncing

Considerations for Choosing an Index

When selecting an index for your application, consider:
  1. Persistence: Local indexes are lost when your application restarts; remote indexes persist
  2. Scalability: Remote indexes can handle millions of vectors; local indexes are limited by memory
  3. Latency: Local indexes have lower latency; remote indexes add network overhead
  4. Setup complexity: Local indexes require no setup; remote indexes require account creation and configuration
  5. Cost: Local indexes are free; remote indexes may incur usage costs
  6. Hybrid search: Only certain indexes support combined dense and sparse search

Index Methods

All indexes in Semantic Router inherit from BaseIndex and implement these key methods:
  • add(): Add embeddings to the index
  • query(): Search for similar vectors
  • delete(): Remove routes from the index
  • describe(): Get information about the index
  • is_ready(): Check if the index is initialized and ready for use
For detailed information on specific indexes and their configuration options, refer to their respective documentation pages.