Understanding Indexes
In Semantic Router, an index serves several key purposes:- Store embeddings of route utterances
- Search for similar vectors when routing queries
- Persist route configurations across sessions
- Scale to handle large numbers of routes and utterances
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
Index | Description | Installation |
---|---|---|
LocalIndex | In-memory index for development and testing | pip install -qU semantic-router |
HybridLocalIndex | In-memory index supporting hybrid search | pip install -qU "semantic-router[hybrid]" |
PineconeIndex | Pinecone vector database integration | pip install -qU "semantic-router[pinecone]" |
QdrantIndex | Qdrant vector database integration | pip install -qU "semantic-router[qdrant]" |
PostgresIndex | PostgreSQL with pgvector extension | pip install -qU "semantic-router[postgres]" |
Auto-Sync Feature
Semantic Router provides an auto-sync feature that keeps your routes in sync between local and remote indexes:"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:- Persistence: Local indexes are lost when your application restarts; remote indexes persist
- Scalability: Remote indexes can handle millions of vectors; local indexes are limited by memory
- Latency: Local indexes have lower latency; remote indexes add network overhead
- Setup complexity: Local indexes require no setup; remote indexes require account creation and configuration
- Cost: Local indexes are free; remote indexes may incur usage costs
- Hybrid search: Only certain indexes support combined dense and sparse search
Index Methods
All indexes in Semantic Router inherit fromBaseIndex
and implement these key methods:
add()
: Add embeddings to the indexquery()
: Search for similar vectorsdelete()
: Remove routes from the indexdescribe()
: Get information about the indexis_ready()
: Check if the index is initialized and ready for use