Skip to content

BaseView#

Tip

dbally.views.base.BaseView #

Base class for all Views, which are the main building blocks of db-ally. All classes implementing this interface have to be able to execute queries and return the result.

ask abstractmethod async #

ask(query: str, llm: LLM, event_tracker: Optional[EventTracker] = None, n_retries: int = 3, dry_run: bool = False, llm_options: Optional[LLMOptions] = None) -> ViewExecutionResult

Executes the query and returns the result.

PARAMETER DESCRIPTION
query

The natural language query to execute.

TYPE: str

llm

The LLM used to execute the query.

TYPE: LLM

event_tracker

The event tracker used to audit the query execution.

TYPE: Optional[EventTracker] DEFAULT: None

n_retries

The number of retries to execute the query in case of errors.

TYPE: int DEFAULT: 3

dry_run

If True, the query will not be used to fetch data from the datasource.

TYPE: bool DEFAULT: False

llm_options

Options to use for the LLM.

TYPE: Optional[LLMOptions] DEFAULT: None

RETURNS DESCRIPTION
ViewExecutionResult

The result of the query.

Source code in src/dbally/views/base.py
@abc.abstractmethod
async def ask(
    self,
    query: str,
    llm: LLM,
    event_tracker: Optional[EventTracker] = None,
    n_retries: int = 3,
    dry_run: bool = False,
    llm_options: Optional[LLMOptions] = None,
) -> ViewExecutionResult:
    """
    Executes the query and returns the result.

    Args:
        query: The natural language query to execute.
        llm: The LLM used to execute the query.
        event_tracker: The event tracker used to audit the query execution.
        n_retries: The number of retries to execute the query in case of errors.
        dry_run: If True, the query will not be used to fetch data from the datasource.
        llm_options: Options to use for the LLM.

    Returns:
        The result of the query.
    """

list_similarity_indexes #

list_similarity_indexes() -> Dict[AbstractSimilarityIndex, List[IndexLocation]]

Lists all the similarity indexes used by the view.

RETURNS DESCRIPTION
Dict[AbstractSimilarityIndex, List[IndexLocation]]

Mapping of similarity indexes to their locations.

Source code in src/dbally/views/base.py
def list_similarity_indexes(self) -> Dict[AbstractSimilarityIndex, List[IndexLocation]]:
    """
    Lists all the similarity indexes used by the view.

    Returns:
        Mapping of similarity indexes to their locations.
    """
    return {}

list_few_shots #

list_few_shots() -> List[FewShotExample]

List all examples to be injected into few-shot prompt.

RETURNS DESCRIPTION
List[FewShotExample]

List of few-shot examples

Source code in src/dbally/views/base.py
def list_few_shots(self) -> List[FewShotExample]:
    """
    List all examples to be injected into few-shot prompt.

    Returns:
        List of few-shot examples
    """
    return []

dbally.collection.results.ViewExecutionResult dataclass #

ViewExecutionResult(results: List[Dict[str, Any]], context: Dict[str, Any])

Represents the result of the query execution for a single view.

PARAMETER DESCRIPTION
results

List of dictionaries containing the results of the query execution, each dictionary represents a row in the result set with column names as keys.

TYPE: List[Dict[str, Any]]

context

Dictionary containing addtional metadata about the query execution.

TYPE: Dict[str, Any]

results instance-attribute #

results: List[Dict[str, Any]]

context instance-attribute #

context: Dict[str, Any]