Skip to content

Aurelio semantic router

Defines a router that utilizes the Aurelio Labs library to route the input source to the appropriate path.

Authors

Henry Wicaksono (henry.wicaksono@gdplabs.id) Obryan Ramadhan (obryan.ramadhan@gdplabs.id)

References

[1] https://github.com/aurelio-labs/semantic-router [2] https://docs.google.com/document/d/1HgqpWHnMGQrG8DpCncm1JMWlBzFYviMiyi0r0SRPJ7c/

AurelioSemanticRouter(default_route, valid_routes, encoder, routes=None, index=None, auto_sync='local', **kwargs)

Bases: BaseRouter

A router that utilizes the Aurelio Labs library to route the input source to the appropriate path.

The AurelioSemanticRouter utilizes the Aurelio Labs library to route a given input source to an appropriate path based on the similarity with existing samples. If the determined route is not valid, it defaults to a predefined route.

Attributes:

Name Type Description
route_layer RouteLayer

The Aurelio Labs route layer that handles the routing logic.

default_route str

The default route to be used if the input source is not similar to any of the routes.

valid_routes set[str]

A set of valid routes for the router.

Notes

For more information about the Aurelio Labs library, please refer to https://github.com/aurelio-labs/semantic-router

Initializes a new instance of the AurelioSemanticRouter class.

To define the routes, at least one of the routes or index parameters must be provided. When both parameters are provided, the routes parameter is ignored.

Parameters:

Name Type Description Default
default_route str

The default route to be used if the input source is not similar to any of the routes.

required
valid_routes set[str]

A set of valid routes for the router.

required
encoder DenseEncoder

An Aurelio Labs dense encoder to encode the input source and the samples. The encoded vectors are used to calculate the similarity between the input source and the samples.

required
routes list[Route] | dict[str, list[str | bytes]] | None

A list of Aurelio Labs Routes or a dictionary mapping route names to the list of samples. Ignored if index is provided. Defaults to None.

None
index BaseAurelioIndex | None

A router index to retrieve the routes. If provided, it is prioritized over routes. Defaults to None.

None
auto_sync str

The auto-sync mode for the router. Defaults to "local".

'local'
kwargs Any

Additional keyword arguments to be passed to the Aurelio Labs Route Layer.

{}

Raises:

Type Description
ValueError
  1. If neither routes nor index is provided.
  2. If the parsed routes contains routes that are not in the set of valid routes.
  3. If the provided default route is not in the set of valid routes.

from_file(default_route, valid_routes, file_path) classmethod

Creates a new instance of the AurelioSemanticRouter class from a file.

This method creates a new instance of the AurelioSemanticRouter class from a file. It supports JSON and YAML file extensions.

Parameters:

Name Type Description Default
default_route str

The default route to be used if the input source is not similar to any of the routes.

required
valid_routes set[str]

A set of valid routes for the router.

required
file_path str

The path to the file containing the routes. The file extension must be either JSON or YAML.

required

Returns:

Name Type Description
AurelioSemanticRouter AurelioSemanticRouter

A new instance of the AurelioSemanticRouter class.

Raises:

Type Description
ValueError

If the file extension is not ".json" or ".yaml".