> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aurelio.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# semantic_router.index.base

## BaseIndex Objects

```python theme={null}
class BaseIndex(BaseModel)
```

Base class for indices using Pydantic's BaseModel.
This class outlines the expected interface for index classes.
Actual method implementations should be provided in subclasses.

#### add

```python theme={null}
def add(embeddings: List[List[float]],
        routes: List[str],
        utterances: List[Any],
        function_schemas: Optional[List[Dict[str, Any]]] = None,
        metadata_list: List[Dict[str, Any]] = [],
        **kwargs)
```

Add embeddings to the index.

This method should be implemented by subclasses.

**Arguments**:

* `embeddings` (`List[List[float]]`): List of embeddings to add to the index.
* `routes` (`List[str]`): List of routes to add to the index.
* `utterances` (`List[str]`): List of utterances to add to the index.
* `function_schemas` (`Optional[List[Dict[str, Any]]]`): List of function schemas to add to the index.
* `metadata_list` (`List[Dict[str, Any]]`): List of metadata to add to the index.

#### aadd

```python theme={null}
async def aadd(embeddings: List[List[float]],
               routes: List[str],
               utterances: List[str],
               function_schemas: Optional[Optional[List[Dict[str,
                                                             Any]]]] = None,
               metadata_list: List[Dict[str, Any]] = [],
               **kwargs)
```

Add vectors to the index asynchronously.

This method should be implemented by subclasses.

**Arguments**:

* `embeddings` (`List[List[float]]`): List of embeddings to add to the index.
* `routes` (`List[str]`): List of routes to add to the index.
* `utterances` (`List[str]`): List of utterances to add to the index.
* `function_schemas` (`Optional[List[Dict[str, Any]]]`): List of function schemas to add to the index.
* `metadata_list` (`List[Dict[str, Any]]`): List of metadata to add to the index.

#### get\_utterances

```python theme={null}
def get_utterances(include_metadata: bool = False) -> List[Utterance]
```

Gets a list of route and utterance objects currently stored in the

index, including additional metadata.

**Arguments**:

* `include_metadata` (`bool`): Whether to include function schemas and metadata in
  the returned Utterance objects.

**Returns**:

`List[Utterance]`: A list of Utterance objects.

#### aget\_utterances

```python theme={null}
async def aget_utterances(include_metadata: bool = False) -> List[Utterance]
```

Gets a list of route and utterance objects currently stored in the

index, including additional metadata.

**Arguments**:

* `include_metadata` (`bool`): Whether to include function schemas and metadata in
  the returned Utterance objects.

**Returns**:

`List[Utterance]`: A list of Utterance objects.

#### get\_routes

```python theme={null}
def get_routes() -> List[Route]
```

Gets a list of route objects currently stored in the index.

**Returns**:

`List[Route]`: A list of Route objects.

#### delete

```python theme={null}
def delete(route_name: str)
```

Deletes route by route name.

This method should be implemented by subclasses.

**Arguments**:

* `route_name` (`str`): Name of the route to delete.

#### adelete

```python theme={null}
async def adelete(route_name: str) -> list[str]
```

Asynchronously delete specified route from index if it exists. Returns the IDs

of the vectors deleted.
This method should be implemented by subclasses.

**Arguments**:

* `route_name` (`str`): Name of the route to delete.

**Returns**:

`list[str]`: List of IDs of the vectors deleted.

#### describe

```python theme={null}
def describe() -> IndexConfig
```

Returns an IndexConfig object with index details such as type, dimensions,

and total vector count.
This method should be implemented by subclasses.

**Returns**:

`IndexConfig`: An IndexConfig object.

#### is\_ready

```python theme={null}
def is_ready() -> bool
```

Checks if the index is ready to be used.

This method should be implemented by subclasses.

**Returns**:

`bool`: True if the index is ready, False otherwise.

#### ais\_ready

```python theme={null}
async def ais_ready() -> bool
```

Checks if the index is ready to be used asynchronously.

This method should be implemented by subclasses.

**Returns**:

`bool`: True if the index is ready, False otherwise.

#### query

```python theme={null}
def query(
    vector: np.ndarray,
    top_k: int = 5,
    route_filter: Optional[List[str]] = None,
    sparse_vector: dict[int, float] | SparseEmbedding | None = None
) -> Tuple[np.ndarray, List[str]]
```

Search the index for the query\_vector and return top\_k results.

This method should be implemented by subclasses.

**Arguments**:

* `vector` (`np.ndarray`): The vector to search for.
* `top_k` (`int`): The number of results to return.
* `route_filter` (`Optional[List[str]]`): The routes to filter the search by.
* `sparse_vector` (`dict[int, float] | SparseEmbedding | None`): The sparse vector to search for.

**Returns**:

`Tuple[np.ndarray, List[str]]`: A tuple containing the query vector and a list of route names.

#### aquery

```python theme={null}
async def aquery(
    vector: np.ndarray,
    top_k: int = 5,
    route_filter: Optional[List[str]] = None,
    sparse_vector: dict[int, float] | SparseEmbedding | None = None
) -> Tuple[np.ndarray, List[str]]
```

Search the index for the query\_vector and return top\_k results.

This method should be implemented by subclasses.

**Arguments**:

* `vector` (`np.ndarray`): The vector to search for.
* `top_k` (`int`): The number of results to return.
* `route_filter` (`Optional[List[str]]`): The routes to filter the search by.
* `sparse_vector` (`dict[int, float] | SparseEmbedding | None`): The sparse vector to search for.

**Returns**:

`Tuple[np.ndarray, List[str]]`: A tuple containing the query vector and a list of route names.

#### aget\_routes

```python theme={null}
def aget_routes()
```

Asynchronously get a list of route and utterance objects currently stored in the index.

This method should be implemented by subclasses.

**Raises**:

* `NotImplementedError`: If the method is not implemented by the subclass.

**Returns**:

`list[tuple]`: A list of tuples, each containing a route name and an associated utterance.

#### delete\_all

```python theme={null}
def delete_all()
```

Deletes all records from the index.

This method should be implemented by subclasses.

**Raises**:

* `NotImplementedError`: If the method is not implemented by the subclass.

#### delete\_index

```python theme={null}
def delete_index()
```

Deletes or resets the index.

This method should be implemented by subclasses.

**Raises**:

* `NotImplementedError`: If the method is not implemented by the subclass.

#### adelete\_index

```python theme={null}
async def adelete_index()
```

Deletes or resets the index asynchronously.
This method should be implemented by subclasses.

#### lock

```python theme={null}
def lock(value: bool,
         wait: int = 0,
         scope: str | None = None) -> ConfigParameter
```

Lock/unlock the index for a given scope (if applicable). If index

already locked/unlocked, raises ValueError.

**Arguments**:

* `scope` (`str | None`): The scope to lock.
* `wait` (`int`): The number of seconds to wait for the index to be unlocked, if
  set to 0, will raise an error if index is already locked/unlocked.

**Returns**:

`ConfigParameter`: The config parameter that was locked.

#### alock

```python theme={null}
async def alock(value: bool,
                wait: int = 0,
                scope: str | None = None) -> ConfigParameter
```

Lock/unlock the index for a given scope (if applicable). If index
already locked/unlocked, raises ValueError.

#### \_\_len\_\_

```python theme={null}
def __len__()
```

Returns the total number of vectors in the index. If the index is not initialized

returns 0.

**Returns**:

`int`: The total number of vectors.

#### alen

```python theme={null}
async def alen()
```

Async version of **len**. Returns the total number of vectors in the index.

Default implementation just calls the sync version.

**Returns**:

`int`: The total number of vectors.

#### parse\_route\_info

```python theme={null}
def parse_route_info(metadata: List[Dict[str, Any]]) -> List[Tuple]
```

Parses metadata from index to extract route, utterance, function

schema and additional metadata.

**Arguments**:

* `metadata` (`List[Dict[str, Any]]`): List of metadata dictionaries.

**Returns**:

`List[Tuple]`: A list of tuples, each containing route, utterance, function schema and additional metadata.
