Client Referenceindex
semantic_router.index.hybrid_local
HybridLocalIndex Objects
class HybridLocalIndex(LocalIndex)add
def add(embeddings: List[List[float]],
routes: List[str],
utterances: List[Any],
metadata_list: Optional[List[Dict[str, Any]]] = None,
sparse_embeddings: Optional[List[SparseEmbedding]] = None,
**kwargs)Upsert records into the index, one per (route, utterance) pair. A pair
that is already stored has its embeddings and metadata replaced.
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.metadata_list(Optional[List[Dict[str, Any]]]): List of metadata to add to the index.sparse_embeddings(Optional[List[SparseEmbedding]]): List of sparse embeddings to add to the index.
query
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 and return top_k results.
Arguments:
vector(np.ndarray): The query vector to search for.top_k(int, optional): The number of top results to return, defaults to 5.route_filter(Optional[List[str]], optional): A list of route names to filter the search results, defaults to None.sparse_vector(dict[int, float]): The sparse vector to search for, must be provided.
aquery
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 and return top_k results. This method calls the
sync query method as everything uses numpy computations which is CPU-bound
and so no benefit can be gained from making this async.
Arguments:
vector(np.ndarray): The query vector to search for.top_k(int, optional): The number of top results to return, defaults to 5.route_filter(Optional[List[str]], optional): A list of route names to filter the search results, defaults to None.sparse_vector(dict[int, float]): The sparse vector to search for, must be provided.
delete_index
def delete_index()Deletes the index, effectively clearing it and setting it to None.
Returns:
None: None