diff --git a/semantic_router/index/pinecone.py b/semantic_router/index/pinecone.py index c04cdc9a..a578eb01 100644 --- a/semantic_router/index/pinecone.py +++ b/semantic_router/index/pinecone.py @@ -466,6 +466,23 @@ def query( route_filter: Optional[List[str]] = None, **kwargs: Any, ) -> Tuple[np.ndarray, List[str]]: + """ + Search the index for the query vector and return the top_k results. + + :param vector: The query vector to search for. + :type vector: np.ndarray + :param top_k: The number of top results to return, defaults to 5. + :type top_k: int, optional + :param route_filter: A list of route names to filter the search results, defaults to None. + :type route_filter: Optional[List[str]], optional + :param kwargs: Additional keyword arguments for the query, including sparse_vector. + :type kwargs: Any + :keyword sparse_vector: An optional sparse vector to include in the query. + :type sparse_vector: Optional[dict] + :return: A tuple containing an array of scores and a list of route names. + :rtype: Tuple[np.ndarray, List[str]] + :raises ValueError: If the index is not populated. + """ if self.index is None: raise ValueError("Index is not populated.") query_vector_list = vector.tolist() @@ -492,6 +509,23 @@ async def aquery( route_filter: Optional[List[str]] = None, **kwargs: Any, ) -> Tuple[np.ndarray, List[str]]: + """ + Asynchronously search the index for the query vector and return the top_k results. + + :param vector: The query vector to search for. + :type vector: np.ndarray + :param top_k: The number of top results to return, defaults to 5. + :type top_k: int, optional + :param route_filter: A list of route names to filter the search results, defaults to None. + :type route_filter: Optional[List[str]], optional + :param kwargs: Additional keyword arguments for the query, including sparse_vector. + :type kwargs: Any + :keyword sparse_vector: An optional sparse vector to include in the query. + :type sparse_vector: Optional[dict] + :return: A tuple containing an array of scores and a list of route names. + :rtype: Tuple[np.ndarray, List[str]] + :raises ValueError: If the index is not populated. + """ if self.async_client is None or self.host is None: raise ValueError("Async client or host are not initialized.") query_vector_list = vector.tolist()