A(nother) semantic routing system that classifies user queries into hierarchical categories using OpenAI embeddings and cosine similarity.
- Hierarchical intent routing with configurable similarity thresholds
- Automatic embedding caching for performance optimization
- YAML-based configuration for routing tree structure
- Transactional updates to routing configuration
- OpenAI embedding model integration
- Python 3.12 and up.
- Access to any Open AI compatible endpoint (Ollama, LiteLLM, ...) with some embeddings model available.
- Install it with
pip install .
- Setup the
.env
file (start with the providedenv_template
one). - Optionally, edit the
router_example.yaml
to define your routes. - Play with the routes using the
asero
CLI command. - That's all!
- Install development dependencies:
pip install .[dev]
- Enable up pre-commit hooks:
pre-commit install
- Setup the
.env
file (start with the providedenv_template
one). - Hack, hack, hack (the
asero
CLI command, that runsmain.py
, should be enough) - Test, test, test. Try to cover as much as possible always.
(see the Contributing section for more details)
Don't forget to configure the .env
file (see "Quick start" above).
from asero import config as asero_config
from asero.router import SemanticRouter
# Load the configuration from a YAML file (see router_example.yaml)
config = asero_config.get_config("path/to/valid/router.yaml")
# Create a router instance
router = SemanticRouter(config)
# Start making queries (explore options in the SemanticRouter class)
matches = router.top_n_routes(query="Hi!")
# Print the top matches (route, score, depth, leaf)
[print(match) for match in matches]
Will output something like:
('router_example/greetings/neutral', 0.9999999999999999, 3, True)
('router_example/chitchat', 0.48668323180162615, 2, True)
This project is licensed under the BSD 3-Clause License. See the LICENSE file for more information.
We welcome contributions! Please see our Contributing Guidelines for more details.
Please note that this project adheres to a Code of Conduct. By participating, you agree to uphold this code.
© 2025 Moodle Research Team