Indexes
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:
- 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
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
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:
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:
- 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 from BaseIndex
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
For detailed information on specific indexes and their configuration options, refer to their respective documentation pages.