Skip to content

Aurelio index

Defines a base class for router index to be loaded by the AurelioSemanticRouter.

Authors

Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id) Henry Wicaksono (henry.wicaksono@gdplabs.id) Komang Elang Surya Prawira (komang.e.s.prawira@gdplabs.id)

References

[1] https://github.com/aurelio-labs/semantic-router/blob/main/semantic_router/index/base.py [2] https://github.com/aurelio-labs/semantic-router/blob/main/semantic_router/index/pinecone.py

BaseAurelioIndex

Bases: BaseIndex, ABC

An abstract base class for the router index to be loaded by the AurelioSemanticRouter.

The BaseAurelioIndex extends the BaseIndex class from the semantic router library. It can be used as a base class for a router index implementation that can be used with the assumption that the routes are already in the index. Therefore, the index will solely be used for retrieval purposes.

Attributes:

Name Type Description
sync bool

Flag to indicate that the index should be synchronized with the routes mapping. In this implementation, it's set to True by default to make sure that the RouteLayer object initialized with this index will perform the syncing process instead of blindly adding the routes to the index.

Notes

To use this class, you need to implement the get_routes and query methods: 1. get_routes: Retrieve a list of routes and their associated utterances from the index. 2. query: Search the index for the query_vector and return top_k results.

add(embeddings, routes, utterances)

Add embeddings to the index.

This method doesn't need to add any routes to the index since it's assumed that the routes are already in the index. Therefore, this method is left empty intentionally.

Parameters:

Name Type Description Default
embeddings list[list[float]]

A list of embedded vectors for the documents.

required
routes list[str]

A list of route names for the documents.

required
utterances list[Any]

A list of utterances for the documents.

required

Returns:

Type Description
None

None

get_routes() abstractmethod

Retrieves a dictionary of routes and their associated utterances from the index.

Returns:

Type Description
dict[str, list[str]]

dict[str, list[str]]: A dictionary where the key is the route name and the value is a list of utterances.

Raises:

Type Description
NotImplementedError

If the method is not implemented by the subclass.

query(vector, top_k=5, route_filter=None) abstractmethod

Search the index with the input query vector and return top_k results.

Parameters:

Name Type Description Default
vector ndarray

The input vector to query.

required
top_k int

The number of results to return. Defaults to 5.

5
route_filter list[str] | None

The list of routes to filter the results by. Defaults to None.

None

Returns:

Type Description
tuple[ndarray, list[str]]

tuple[np.ndarray, list[str]]: A tuple containing the query vector and the list of results.

Raises:

Type Description
NotImplementedError

If the method is not implemented by the subclass.