Skip to content

Commit eae24da

Browse files
authored
refactor: move ExecutionResult to collection (#46)
1 parent 825b8fe commit eae24da

File tree

23 files changed

+89
-52
lines changed

23 files changed

+89
-52
lines changed

benchmark/dbally_benchmark/e2e_benchmark.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
from sqlalchemy import create_engine
2222

2323
import dbally
24-
from dbally.collection import Collection, NoViewFoundError
24+
from dbally.collection import Collection
25+
from dbally.collection.exceptions import NoViewFoundError
2526
from dbally.iql_generator.iql_prompt_template import UnsupportedQueryError, default_iql_template
2627
from dbally.llms.litellm import LiteLLM
2728
from dbally.view_selection.view_selector_prompt_template import default_view_selector_template

docs/concepts/collections.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ my_collection.ask("Find me Italian recipes for soups")
2626
In this scenario, the LLM first determines the most suitable view to address the query, and then that view is used to pull the relevant data.
2727

2828
!!! info
29-
The result of a query is an [`ExecutionResult`][dbally.data_models.execution_result.ExecutionResult] object, which contains the data fetched by the view. It contains a `results` attribute that holds the actual data, structured as a list of dictionaries. The exact structure of these dictionaries depends on the view that was used to fetch the data, which can be obtained by looking at the `view_name` attribute of the `ExecutionResult` object.
29+
The result of a query is an [`ExecutionResult`][dbally.collection.results.ExecutionResult] object, which contains the data fetched by the view. It contains a `results` attribute that holds the actual data, structured as a list of dictionaries. The exact structure of these dictionaries depends on the view that was used to fetch the data, which can be obtained by looking at the `view_name` attribute of the `ExecutionResult` object.
3030

3131
It's possible for projects to feature several collections, each potentially housing a different set of views. Moreover, a single view can be associated with multiple collections, offering versatile usage across various contexts.

docs/how-to/views/custom.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ import abc
154154
from typing import Callable, Any, Iterable
155155

156156
from dbally.iql import IQLQuery
157-
from dbally.data_models.execution_result import ViewExecutionResult
157+
from dbally.collection.results import ViewExecutionResult
158158

159159
@abc.abstractmethod
160160
def get_data(self) -> Iterable:

docs/how-to/views/custom_views_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dbally import decorators, MethodsBaseView
99
from dbally.audit.event_handlers.cli_event_handler import CLIEventHandler
1010
from dbally.iql import IQLQuery, syntax
11-
from dbally.data_models.execution_result import ViewExecutionResult
11+
from dbally.collection.results import ViewExecutionResult
1212
from dbally.llms.litellm import LiteLLM
1313

1414
@dataclass

docs/quickstart/quickstart3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The guide illustrates how to use multiple views to handle queries requiring diff
88

99
You can register multiple views with a collection. When you run a query, the AI model decides which view to use based on the query. This allows for handling diffrent kinds of queries with different views. Those views can be based on data from the same source (e.g., different tables in the same database), or from different sources (e.g. a database and an API).
1010

11-
Upon selecting the view, the AI model uses it to extract the relevant data from its data source. The query result is an [`ExecutionResult`][dbally.data_models.execution_result.ExecutionResult] object. It contains the data extracted by the view, along with other metadata including the name of the view that fetched the data.
11+
Upon selecting the view, the AI model uses it to extract the relevant data from its data source. The query result is an [`ExecutionResult`][dbally.collection.results.ExecutionResult] object. It contains the data extracted by the view, along with other metadata including the name of the view that fetched the data.
1212

1313
## Defining the JobView
1414

docs/reference/collection.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
::: dbally.create_collection
77

8-
::: dbally.Collection
8+
::: dbally.collection.Collection
99

10-
::: dbally.data_models.execution_result.ExecutionResult
10+
::: dbally.collection.results.ExecutionResult
1111

12-
::: dbally.collection.IndexUpdateError
12+
::: dbally.collection.exceptions.IndexUpdateError
13+
14+
::: dbally.collection.exceptions.NoViewFoundError

docs/reference/views/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
::: dbally.views.base.BaseView
88

9-
::: dbally.data_models.execution_result.ViewExecutionResult
9+
::: dbally.collection.results.ViewExecutionResult

src/dbally/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
""" dbally """
22

3-
from dbally.data_models.execution_result import ExecutionResult
3+
from dbally.collection.collection import Collection
4+
from dbally.collection.exceptions import IndexUpdateError, NoViewFoundError
5+
from dbally.collection.results import ExecutionResult
46
from dbally.views import decorators
57
from dbally.views.methods_base import MethodsBaseView
68
from dbally.views.pandas_base import DataFrameBaseView
@@ -10,7 +12,6 @@
1012
from .__version__ import __version__
1113
from ._main import create_collection
1214
from ._types import NOT_GIVEN, NotGiven
13-
from .collection import Collection
1415
from .embeddings.exceptions import (
1516
EmbeddingConnectionError,
1617
EmbeddingError,
@@ -39,6 +40,8 @@
3940
"LLMConnectionError",
4041
"LLMResponseError",
4142
"LLMStatusError",
43+
"NoViewFoundError",
44+
"IndexUpdateError",
4245
"NotGiven",
4346
"NOT_GIVEN",
4447
]

src/dbally/collection/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from dbally.collection.collection import Collection
2+
from dbally.collection.exceptions import IndexUpdateError, NoViewFoundError
3+
from dbally.collection.results import ExecutionResult, ViewExecutionResult
4+
5+
__all__ = [
6+
"Collection",
7+
"ExecutionResult",
8+
"ViewExecutionResult",
9+
"NoViewFoundError",
10+
"IndexUpdateError",
11+
]

src/dbally/collection.py renamed to src/dbally/collection/collection.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
from dbally.audit.event_handlers.base import EventHandler
99
from dbally.audit.event_tracker import EventTracker
10+
from dbally.collection.exceptions import IndexUpdateError, NoViewFoundError
11+
from dbally.collection.results import ExecutionResult
1012
from dbally.data_models.audit import RequestEnd, RequestStart
11-
from dbally.data_models.execution_result import ExecutionResult
12-
from dbally.exceptions import DbAllyError
1313
from dbally.llms.base import LLM
1414
from dbally.llms.clients.base import LLMOptions
1515
from dbally.nl_responder.nl_responder import NLResponder
@@ -18,29 +18,6 @@
1818
from dbally.views.base import BaseView, IndexLocation
1919

2020

21-
class NoViewFoundError(DbAllyError):
22-
"""
23-
Error raised when there is no view with the given name.
24-
"""
25-
26-
27-
class IndexUpdateError(DbAllyError):
28-
"""
29-
Exception for when updating any of the Collection's similarity indexes fails.
30-
31-
Provides a dictionary mapping failed indexes to their
32-
respective exceptions as the `failed_indexes` attribute.
33-
"""
34-
35-
def __init__(self, message: str, failed_indexes: Dict[AbstractSimilarityIndex, Exception]) -> None:
36-
"""
37-
Args:
38-
failed_indexes: Dictionary mapping failed indexes to their respective exceptions.
39-
"""
40-
self.failed_indexes = failed_indexes
41-
super().__init__(message)
42-
43-
4421
class Collection:
4522
"""
4623
Collection is a container for a set of views that can be used by db-ally to answer user questions.
@@ -158,7 +135,7 @@ def get(self, name: str) -> BaseView:
158135
"""
159136

160137
if name not in self._views:
161-
raise NoViewFoundError
138+
raise NoViewFoundError(name)
162139

163140
return self._builders[name]()
164141

@@ -298,5 +275,4 @@ async def update_similarity_indexes(self) -> None:
298275
}
299276
if failed_indexes:
300277
failed_locations = [loc for index in failed_indexes for loc in indexes[index]]
301-
descriptions = ", ".join(".".join(name for name in location) for location in failed_locations)
302-
raise IndexUpdateError(f"Failed to update similarity indexes for {descriptions}", failed_indexes)
278+
raise IndexUpdateError(failed_indexes, failed_locations)

0 commit comments

Comments
 (0)