dbgraph 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dbgraph-0.1.0/.gitignore +13 -0
- dbgraph-0.1.0/.idea/.gitignore +5 -0
- dbgraph-0.1.0/.idea/dbgraph.iml +14 -0
- dbgraph-0.1.0/.idea/inspectionProfiles/profiles_settings.xml +6 -0
- dbgraph-0.1.0/.idea/misc.xml +4 -0
- dbgraph-0.1.0/.idea/modules.xml +8 -0
- dbgraph-0.1.0/.idea/vcs.xml +6 -0
- dbgraph-0.1.0/.idea/workspace.xml +165 -0
- dbgraph-0.1.0/.python-version +1 -0
- dbgraph-0.1.0/PKG-INFO +165 -0
- dbgraph-0.1.0/README.md +136 -0
- dbgraph-0.1.0/data/northwind-desc.md +1722 -0
- dbgraph-0.1.0/data/northwind-graph-v2.json +4787 -0
- dbgraph-0.1.0/data/northwind-graph-v4.json +3574 -0
- dbgraph-0.1.0/data/northwind-graph.db +0 -0
- dbgraph-0.1.0/data/northwind-graph.json +3680 -0
- dbgraph-0.1.0/data/northwind-graph.png +0 -0
- dbgraph-0.1.0/data/northwind-index/corpus.jsonl +101 -0
- dbgraph-0.1.0/data/northwind-index/corpus.mmindex.json +1 -0
- dbgraph-0.1.0/data/northwind-index/data.csc.index.npy +0 -0
- dbgraph-0.1.0/data/northwind-index/indices.csc.index.npy +0 -0
- dbgraph-0.1.0/data/northwind-index/indptr.csc.index.npy +0 -0
- dbgraph-0.1.0/data/northwind-index/params.index.json +12 -0
- dbgraph-0.1.0/data/northwind-index/vocab.index.json +1 -0
- dbgraph-0.1.0/data/northwind-semantic-v5.json +1 -0
- dbgraph-0.1.0/data/northwind.db +0 -0
- dbgraph-0.1.0/data/time-results.txt +2 -0
- dbgraph-0.1.0/dbgraph/__init__.py +21 -0
- dbgraph-0.1.0/dbgraph/application.py +70 -0
- dbgraph-0.1.0/dbgraph/builder/__init__.py +0 -0
- dbgraph-0.1.0/dbgraph/builder/graph_builder.py +22 -0
- dbgraph-0.1.0/dbgraph/builder/sql_graph_builder.py +245 -0
- dbgraph-0.1.0/dbgraph/descriptor/__init__.py +0 -0
- dbgraph-0.1.0/dbgraph/descriptor/graph_descriptor.py +68 -0
- dbgraph-0.1.0/dbgraph/descriptor/langchain_graph_descriptor.py +74 -0
- dbgraph-0.1.0/dbgraph/descriptor/prompt_templates.py +80 -0
- dbgraph-0.1.0/dbgraph/entity/__init__.py +0 -0
- dbgraph-0.1.0/dbgraph/entity/aspect.py +153 -0
- dbgraph-0.1.0/dbgraph/entity/asset.py +26 -0
- dbgraph-0.1.0/dbgraph/entity/asset_type.py +13 -0
- dbgraph-0.1.0/dbgraph/entity/dbgraph.py +152 -0
- dbgraph-0.1.0/dbgraph/entity/link.py +37 -0
- dbgraph-0.1.0/dbgraph/entity/link_type.py +13 -0
- dbgraph-0.1.0/dbgraph/entity/rdbgraph.py +76 -0
- dbgraph-0.1.0/dbgraph/event/__init__.py +0 -0
- dbgraph-0.1.0/dbgraph/event/event.py +20 -0
- dbgraph-0.1.0/dbgraph/event/event_bus.py +61 -0
- dbgraph-0.1.0/dbgraph/event/event_handler.py +11 -0
- dbgraph-0.1.0/dbgraph/io/__init__.py +0 -0
- dbgraph-0.1.0/dbgraph/io/graph_loader.py +11 -0
- dbgraph-0.1.0/dbgraph/io/graph_writer.py +11 -0
- dbgraph-0.1.0/dbgraph/io/json_graph_loader.py +160 -0
- dbgraph-0.1.0/dbgraph/io/json_graph_writer.py +17 -0
- dbgraph-0.1.0/dbgraph/persistent/__init__.py +0 -0
- dbgraph-0.1.0/dbgraph/persistent/graph_persistent.py +98 -0
- dbgraph-0.1.0/dbgraph/persistent/models.py +222 -0
- dbgraph-0.1.0/dbgraph/persistent/sql_graph_persistent.py +388 -0
- dbgraph-0.1.0/dbgraph/render/__init__.py +0 -0
- dbgraph-0.1.0/dbgraph/render/graph_renderer.py +11 -0
- dbgraph-0.1.0/dbgraph/render/markdown_renderer.py +111 -0
- dbgraph-0.1.0/dbgraph/render/text_renderer.py +11 -0
- dbgraph-0.1.0/dbgraph/search/__init__.py +0 -0
- dbgraph-0.1.0/dbgraph/search/bm25_search_engine.py +33 -0
- dbgraph-0.1.0/dbgraph/search/search_engine.py +15 -0
- dbgraph-0.1.0/dbgraph/utils/__init__.py +0 -0
- dbgraph-0.1.0/dbgraph/utils/singleton.py +37 -0
- dbgraph-0.1.0/diagrams/entity.png +0 -0
- dbgraph-0.1.0/diagrams/entity.txt +103 -0
- dbgraph-0.1.0/diagrams/usecase.png +0 -0
- dbgraph-0.1.0/diagrams/usecase.txt +30 -0
- dbgraph-0.1.0/docs/index.md +17 -0
- dbgraph-0.1.0/docs/refs/aspect.md +22 -0
- dbgraph-0.1.0/docs/refs/graph.md +14 -0
- dbgraph-0.1.0/main.py +6 -0
- dbgraph-0.1.0/mkdocs.yml +24 -0
- dbgraph-0.1.0/pyproject.toml +37 -0
- dbgraph-0.1.0/tests/__init__.py +0 -0
- dbgraph-0.1.0/tests/test_application.py +56 -0
- dbgraph-0.1.0/tests/test_bm25s_search_engine.py +31 -0
- dbgraph-0.1.0/tests/test_dbgraph.py +136 -0
- dbgraph-0.1.0/tests/test_json_graph_loader.py +31 -0
- dbgraph-0.1.0/tests/test_json_graph_writer.py +21 -0
- dbgraph-0.1.0/tests/test_langchain_graph_descriptor.py +60 -0
- dbgraph-0.1.0/tests/test_markdown_renderer.py +20 -0
- dbgraph-0.1.0/tests/test_rdbgraph.py +118 -0
- dbgraph-0.1.0/tests/test_sql_graph_builder.py +68 -0
- dbgraph-0.1.0/tests/test_sql_graph_persistent.py +450 -0
- dbgraph-0.1.0/uv.lock +2956 -0
dbgraph-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module external.system.id="pyproject.toml" type="PYTHON_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<sourceFolder url="file://$MODULE_DIR$/dbgraph" isTestSource="false" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
|
7
|
+
</content>
|
|
8
|
+
<orderEntry type="jdk" jdkName="~\Projects\dbgraph\.venv" jdkType="Python SDK" />
|
|
9
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
10
|
+
</component>
|
|
11
|
+
<component name="PyDocumentationSettings">
|
|
12
|
+
<option name="format" value="PLAIN" />
|
|
13
|
+
</component>
|
|
14
|
+
</module>
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="AutoImportSettings">
|
|
4
|
+
<option name="autoReloadType" value="SELECTIVE" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ChangeListManager">
|
|
7
|
+
<list default="true" id="263a96da-9a82-40fd-89b2-ba71dd2c194d" name="Changes" comment="update packaging" />
|
|
8
|
+
<option name="SHOW_DIALOG" value="false" />
|
|
9
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
10
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
11
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
12
|
+
</component>
|
|
13
|
+
<component name="FileTemplateManagerImpl">
|
|
14
|
+
<option name="RECENT_TEMPLATES">
|
|
15
|
+
<list>
|
|
16
|
+
<option value="Python Script" />
|
|
17
|
+
</list>
|
|
18
|
+
</option>
|
|
19
|
+
</component>
|
|
20
|
+
<component name="Git.Settings">
|
|
21
|
+
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
|
22
|
+
<map>
|
|
23
|
+
<entry key="$PROJECT_DIR$" value="packaging" />
|
|
24
|
+
</map>
|
|
25
|
+
</option>
|
|
26
|
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
27
|
+
</component>
|
|
28
|
+
<component name="GitHubPullRequestSearchHistory">{
|
|
29
|
+
"lastFilter": {
|
|
30
|
+
"state": "OPEN",
|
|
31
|
+
"assignee": "minhdenthedev"
|
|
32
|
+
}
|
|
33
|
+
}</component>
|
|
34
|
+
<component name="GithubPullRequestsUISettings"><![CDATA[{
|
|
35
|
+
"selectedUrlAndAccountId": {
|
|
36
|
+
"url": "https://github.com/minhdenthedev/dbgraph.git",
|
|
37
|
+
"accountId": "6c0b7cdc-aa0d-4999-86e3-e6f0a1d74a10"
|
|
38
|
+
},
|
|
39
|
+
"recentNewPullRequestHead": {
|
|
40
|
+
"server": {
|
|
41
|
+
"useHttp": false,
|
|
42
|
+
"host": "github.com",
|
|
43
|
+
"port": null,
|
|
44
|
+
"suffix": null
|
|
45
|
+
},
|
|
46
|
+
"owner": "minhdenthedev",
|
|
47
|
+
"repository": "dbgraph"
|
|
48
|
+
}
|
|
49
|
+
}]]></component>
|
|
50
|
+
<component name="ProjectColorInfo">{
|
|
51
|
+
"associatedIndex": 0,
|
|
52
|
+
"fromUser": false
|
|
53
|
+
}</component>
|
|
54
|
+
<component name="ProjectId" id="3IdnkFbc3mGdbjiFJYWIoYOgRXM" />
|
|
55
|
+
<component name="ProjectLevelVcsManager">
|
|
56
|
+
<ConfirmationsSetting value="2" id="Add" />
|
|
57
|
+
</component>
|
|
58
|
+
<component name="ProjectViewState">
|
|
59
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
|
60
|
+
<option name="showLibraryContents" value="true" />
|
|
61
|
+
</component>
|
|
62
|
+
<component name="PropertiesComponent">{
|
|
63
|
+
"keyToString": {
|
|
64
|
+
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
|
65
|
+
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
|
66
|
+
"Python tests.Python tests for tests.test_dbgraph.TestDBGraph.executor": "Run",
|
|
67
|
+
"Python tests.Python tests in tests.executor": "Run",
|
|
68
|
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
69
|
+
"RunOnceActivity.git.unshallow": "true",
|
|
70
|
+
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
|
71
|
+
"codeWithMe.voiceChat.enabledByDefault": "false",
|
|
72
|
+
"git-widget-placeholder": "main",
|
|
73
|
+
"ignore.virus.scanning.warn.message": "true",
|
|
74
|
+
"nodejs_package_manager_path": "npm"
|
|
75
|
+
}
|
|
76
|
+
}</component>
|
|
77
|
+
<component name="RunManager" selected="Python tests.Python tests for tests.test_dbgraph.TestDBGraph">
|
|
78
|
+
<configuration name="Python tests for tests.test_dbgraph.TestDBGraph" type="tests" factoryName="Autodetect" temporary="true" nameIsGenerated="true">
|
|
79
|
+
<module name="dbgraph" />
|
|
80
|
+
<option name="ENV_FILES" value="" />
|
|
81
|
+
<option name="INTERPRETER_OPTIONS" value="" />
|
|
82
|
+
<option name="PARENT_ENVS" value="true" />
|
|
83
|
+
<option name="SDK_HOME" value="" />
|
|
84
|
+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
|
85
|
+
<option name="IS_MODULE_SDK" value="true" />
|
|
86
|
+
<option name="ADD_CONTENT_ROOTS" value="true" />
|
|
87
|
+
<option name="ADD_SOURCE_ROOTS" value="true" />
|
|
88
|
+
<option name="DEBUG_JUST_MY_CODE" value="false" />
|
|
89
|
+
<option name="RUN_TOOL" value="" />
|
|
90
|
+
<option name="_new_additionalArguments" value="""" />
|
|
91
|
+
<option name="_new_target" value=""tests.test_dbgraph.TestDBGraph"" />
|
|
92
|
+
<option name="_new_targetType" value=""PYTHON"" />
|
|
93
|
+
<method v="2" />
|
|
94
|
+
</configuration>
|
|
95
|
+
<configuration name="Python tests in tests" type="tests" factoryName="Autodetect" temporary="true" nameIsGenerated="true">
|
|
96
|
+
<module name="dbgraph" />
|
|
97
|
+
<option name="ENV_FILES" value="" />
|
|
98
|
+
<option name="INTERPRETER_OPTIONS" value="" />
|
|
99
|
+
<option name="PARENT_ENVS" value="true" />
|
|
100
|
+
<option name="SDK_HOME" value="" />
|
|
101
|
+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/tests" />
|
|
102
|
+
<option name="IS_MODULE_SDK" value="true" />
|
|
103
|
+
<option name="ADD_CONTENT_ROOTS" value="true" />
|
|
104
|
+
<option name="ADD_SOURCE_ROOTS" value="true" />
|
|
105
|
+
<option name="DEBUG_JUST_MY_CODE" value="false" />
|
|
106
|
+
<option name="RUN_TOOL" value="" />
|
|
107
|
+
<option name="_new_additionalArguments" value="""" />
|
|
108
|
+
<option name="_new_target" value=""$PROJECT_DIR$/tests"" />
|
|
109
|
+
<option name="_new_targetType" value=""PATH"" />
|
|
110
|
+
<method v="2" />
|
|
111
|
+
</configuration>
|
|
112
|
+
<recent_temporary>
|
|
113
|
+
<list>
|
|
114
|
+
<item itemvalue="Python tests.Python tests in tests" />
|
|
115
|
+
<item itemvalue="Python tests.Python tests for tests.test_dbgraph.TestDBGraph" />
|
|
116
|
+
<item itemvalue="Python tests.Python tests for tests.test_dbgraph.TestDBGraph" />
|
|
117
|
+
<item itemvalue="Python tests.Python tests in tests" />
|
|
118
|
+
</list>
|
|
119
|
+
</recent_temporary>
|
|
120
|
+
</component>
|
|
121
|
+
<component name="SharedIndexes">
|
|
122
|
+
<attachedChunks>
|
|
123
|
+
<set>
|
|
124
|
+
<option value="bundled-python-sdk-821f704e66d9-5bd6d13a2a75-com.jetbrains.pycharm.pro.sharedIndexes.bundled-PY-262.9437.214" />
|
|
125
|
+
</set>
|
|
126
|
+
</attachedChunks>
|
|
127
|
+
</component>
|
|
128
|
+
<component name="TaskManager">
|
|
129
|
+
<task active="true" id="Default" summary="Default task">
|
|
130
|
+
<changelist id="263a96da-9a82-40fd-89b2-ba71dd2c194d" name="Changes" comment="" />
|
|
131
|
+
<created>1788103453676</created>
|
|
132
|
+
<option name="number" value="Default" />
|
|
133
|
+
<option name="presentableId" value="Default" />
|
|
134
|
+
<updated>1788103453676</updated>
|
|
135
|
+
</task>
|
|
136
|
+
<task id="LOCAL-00001" summary="update packaging">
|
|
137
|
+
<option name="closed" value="true" />
|
|
138
|
+
<created>1788163967330</created>
|
|
139
|
+
<option name="number" value="00001" />
|
|
140
|
+
<option name="presentableId" value="LOCAL-00001" />
|
|
141
|
+
<option name="project" value="LOCAL" />
|
|
142
|
+
<updated>1788163967330</updated>
|
|
143
|
+
</task>
|
|
144
|
+
<option name="localTasksCounter" value="2" />
|
|
145
|
+
<servers />
|
|
146
|
+
</component>
|
|
147
|
+
<component name="TypeScriptGeneratedFilesManager">
|
|
148
|
+
<option name="version" value="3" />
|
|
149
|
+
</component>
|
|
150
|
+
<component name="Vcs.Log.Tabs.Properties">
|
|
151
|
+
<option name="TAB_STATES">
|
|
152
|
+
<map>
|
|
153
|
+
<entry key="MAIN">
|
|
154
|
+
<value>
|
|
155
|
+
<State />
|
|
156
|
+
</value>
|
|
157
|
+
</entry>
|
|
158
|
+
</map>
|
|
159
|
+
</option>
|
|
160
|
+
</component>
|
|
161
|
+
<component name="VcsManagerConfiguration">
|
|
162
|
+
<MESSAGE value="update packaging" />
|
|
163
|
+
<option name="LAST_COMMIT_MESSAGE" value="update packaging" />
|
|
164
|
+
</component>
|
|
165
|
+
</project>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.11
|
dbgraph-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dbgraph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: dbgraph is a database profiling tool which model the database as a graph
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: bm25s[all]>=0.3.9
|
|
7
|
+
Requires-Dist: build>=1.6.0
|
|
8
|
+
Requires-Dist: grip>=4.6.2
|
|
9
|
+
Requires-Dist: langchain-openai>=1.6.0
|
|
10
|
+
Requires-Dist: langchain>=1.3.16
|
|
11
|
+
Requires-Dist: matplotlib>=3.11.0
|
|
12
|
+
Requires-Dist: mkdocs-gen-files>=0.6.1
|
|
13
|
+
Requires-Dist: mkdocs-material>=9.7.7
|
|
14
|
+
Requires-Dist: mkdocs>=1.6.1
|
|
15
|
+
Requires-Dist: mkdocstrings[python]>=1.0.6
|
|
16
|
+
Requires-Dist: openai>=2.45.0
|
|
17
|
+
Requires-Dist: psutil>=7.2.2
|
|
18
|
+
Requires-Dist: pydantic>=2.13.4
|
|
19
|
+
Requires-Dist: pydot>=4.0.1
|
|
20
|
+
Requires-Dist: pympler>=1.1
|
|
21
|
+
Requires-Dist: pystemmer>=3.1.0
|
|
22
|
+
Requires-Dist: pytest>=9.1.1
|
|
23
|
+
Requires-Dist: python-dotenv>=1.2.2
|
|
24
|
+
Requires-Dist: rustworkx>=0.18.0
|
|
25
|
+
Requires-Dist: sqlalchemy>=2.0.52
|
|
26
|
+
Requires-Dist: tqdm>=4.68.4
|
|
27
|
+
Requires-Dist: trino>=0.339.0
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# DBGraph - Building schema graph with LLM Assistance
|
|
31
|
+
|
|
32
|
+
**DBGraph** aims to help data scientist with exploring and finding relevant data assets in a huge and complex database.
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
Here is a quick example of how to build and query a schema graph with DBGraph:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
# imports
|
|
40
|
+
from dbgraph.builder.sqlite.sqlite_graph_builder import SQLiteGraphBuilder
|
|
41
|
+
from dbgraph.io.json_graph_writer import JSONGraphWriter
|
|
42
|
+
from dbgraph.io.json_graph_loader import JSONGraphLoader
|
|
43
|
+
from dbgraph.search.bm25_search_engine import BM25SearchEngine
|
|
44
|
+
|
|
45
|
+
# initiate GraphBuilder on an SQLite database
|
|
46
|
+
graph_builder = SQLiteGraphBuilder(Path("data/northwind.db"))
|
|
47
|
+
|
|
48
|
+
# build the schema graph (include profiling databases)
|
|
49
|
+
graph = graph_builder.build_graph()
|
|
50
|
+
|
|
51
|
+
# generate descriptions for assets
|
|
52
|
+
graph_descriptor = GraphDescriptorV1(
|
|
53
|
+
llm=OAICompatibleLLM(
|
|
54
|
+
model=...,
|
|
55
|
+
base_url=...,
|
|
56
|
+
api_key=...,
|
|
57
|
+
),
|
|
58
|
+
system_prompt=...,
|
|
59
|
+
formating_prompt=...,
|
|
60
|
+
target_prompt=...
|
|
61
|
+
)
|
|
62
|
+
graph = graph_descriptor.rfill_semantic_aspects(graph)
|
|
63
|
+
|
|
64
|
+
# save the graph
|
|
65
|
+
graph_writer = JSONGraphWriter(
|
|
66
|
+
json_path=Path("data/northwind-graph.json"), indent=2
|
|
67
|
+
)
|
|
68
|
+
graph_writer.write()
|
|
69
|
+
|
|
70
|
+
# load the graph
|
|
71
|
+
graph_loader = JSONGraphLoader(json_path=Path("data/northwind-graph.json"))
|
|
72
|
+
graph = self.graph_loader.load()
|
|
73
|
+
|
|
74
|
+
# index the graph using BM25
|
|
75
|
+
search_engine = BM25SearchEngine(Path("data/northwind-index"))
|
|
76
|
+
semantic_aspects = {
|
|
77
|
+
a.asset_id: cast(SemanticAspect, a.aspects["semantic_properties"])
|
|
78
|
+
for a in graph.assets
|
|
79
|
+
}
|
|
80
|
+
search_engine.index(semantic_aspects)
|
|
81
|
+
|
|
82
|
+
# retrieve assets using BM25
|
|
83
|
+
assets_ids = search_engine.search(
|
|
84
|
+
"Give me the total count of orders in each categories"
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
For visualization purpose, this is the graph saved in JSON:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"assets": [
|
|
93
|
+
{
|
|
94
|
+
"asset_id": "8ab5a624-0596-497e-a0ee-3996d95dbe63",
|
|
95
|
+
"name": "Categories",
|
|
96
|
+
"type": "table",
|
|
97
|
+
"aspects": {
|
|
98
|
+
"schema_properties": {
|
|
99
|
+
"name": "Categories_table_schema",
|
|
100
|
+
"pks": ["CategoryID"],
|
|
101
|
+
"indices": {}
|
|
102
|
+
},
|
|
103
|
+
"statistical_properties": {
|
|
104
|
+
"name": "Categories_table_stats",
|
|
105
|
+
"num_columns": 4,
|
|
106
|
+
"num_rows": 8
|
|
107
|
+
},
|
|
108
|
+
"semantic_properties": {
|
|
109
|
+
"name": "Categories_semantic",
|
|
110
|
+
"description": "Stores product category definitions and metadata, serving as a lookup table for classifying products in the inventory system.",
|
|
111
|
+
"keywords": [
|
|
112
|
+
"categories",
|
|
113
|
+
"product classification",
|
|
114
|
+
"category definitions",
|
|
115
|
+
"inventory groups",
|
|
116
|
+
"product types"
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
...
|
|
122
|
+
],
|
|
123
|
+
"links": [
|
|
124
|
+
{
|
|
125
|
+
"link_id": "db6bea93-a02c-4426-a2db-449e4a7bba8f",
|
|
126
|
+
"name": "Categories_CategoryID",
|
|
127
|
+
"type": "contain",
|
|
128
|
+
"source_id": "8ab5a624-0596-497e-a0ee-3996d95dbe63",
|
|
129
|
+
"destination_id": "04c20046-2808-4021-bbf1-99876e0eea6e",
|
|
130
|
+
"aspects": {}
|
|
131
|
+
},
|
|
132
|
+
...
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Usecases
|
|
138
|
+
|
|
139
|
+

|
|
140
|
+
There are 4 main groups of usecases where DBGraph is applicable:
|
|
141
|
+
|
|
142
|
+
- **Manipulating database schema**: Build the schema graph, store it, and use it to traverse around the database, find JOIN path, get references tables, ...
|
|
143
|
+
- **Profiling database**: Use the concept of `Aspect` to represent different types of properties attached to a single data asset.
|
|
144
|
+
Each data asset can have a statistics aspects, semantical aspects, ...
|
|
145
|
+
- **Render graph**: Output schema graph to Markdown or text as context for LLM
|
|
146
|
+
- **LLM Assistance**: Leverage LLM to generate data assets' descriptions and tags. Furthermore, LLM could also be used in the process of SQL generation.
|
|
147
|
+
- **Search for data assets**: Search for wanted data assets based on their descriptions. The descriptions are indexed and retrieved with BM25 algorithms.
|
|
148
|
+
|
|
149
|
+
## Architecture
|
|
150
|
+
|
|
151
|
+

|
|
152
|
+
|
|
153
|
+
To encourage open-ness and extension, DBGraph is designed in a way that is very easy to extend.
|
|
154
|
+
|
|
155
|
+
1. **The core classes** (_entities_) define the shared business logic of database graphs (traversal, neighborhoods, ...) and core operations
|
|
156
|
+
within the application (building graphs, profiling databases, ...). The prefix _"R..."_ stands for _"Relational"_, as the class is dedicated
|
|
157
|
+
Relational databases only. The same stands for _"D.."_ (Document), _"V..."_ (Vector), _"G..."_ (Graph). However, at this point, the only supported
|
|
158
|
+
paradigm is Relational database.
|
|
159
|
+
2. **The interfaces** (_extensions_) define a part of the system that should be **pluggable**. For example:
|
|
160
|
+
|
|
161
|
+
- `RProfiler` and `RGraphBuilder` should works on multiple types of RDBMS, not just SQLite. Hence the abstraction of `RDataGateway`.
|
|
162
|
+
- We want to support multiple LLM providers. Hence the abstraction of `LLM`.
|
|
163
|
+
- There are many ways to render a graph into Markdown or text. Hence the abstraction of `RGraphRenderer`.
|
|
164
|
+
- To store and load the graph's data from some storages, we have multiple options. Hence the abstraction of `GraphGateway`.
|
|
165
|
+
- To index and retrieve graph's data from some search engines, we also have multiple options. Hence the abstraction of `SearchEngine`
|
dbgraph-0.1.0/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# DBGraph - Building schema graph with LLM Assistance
|
|
2
|
+
|
|
3
|
+
**DBGraph** aims to help data scientist with exploring and finding relevant data assets in a huge and complex database.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
Here is a quick example of how to build and query a schema graph with DBGraph:
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
# imports
|
|
11
|
+
from dbgraph.builder.sqlite.sqlite_graph_builder import SQLiteGraphBuilder
|
|
12
|
+
from dbgraph.io.json_graph_writer import JSONGraphWriter
|
|
13
|
+
from dbgraph.io.json_graph_loader import JSONGraphLoader
|
|
14
|
+
from dbgraph.search.bm25_search_engine import BM25SearchEngine
|
|
15
|
+
|
|
16
|
+
# initiate GraphBuilder on an SQLite database
|
|
17
|
+
graph_builder = SQLiteGraphBuilder(Path("data/northwind.db"))
|
|
18
|
+
|
|
19
|
+
# build the schema graph (include profiling databases)
|
|
20
|
+
graph = graph_builder.build_graph()
|
|
21
|
+
|
|
22
|
+
# generate descriptions for assets
|
|
23
|
+
graph_descriptor = GraphDescriptorV1(
|
|
24
|
+
llm=OAICompatibleLLM(
|
|
25
|
+
model=...,
|
|
26
|
+
base_url=...,
|
|
27
|
+
api_key=...,
|
|
28
|
+
),
|
|
29
|
+
system_prompt=...,
|
|
30
|
+
formating_prompt=...,
|
|
31
|
+
target_prompt=...
|
|
32
|
+
)
|
|
33
|
+
graph = graph_descriptor.rfill_semantic_aspects(graph)
|
|
34
|
+
|
|
35
|
+
# save the graph
|
|
36
|
+
graph_writer = JSONGraphWriter(
|
|
37
|
+
json_path=Path("data/northwind-graph.json"), indent=2
|
|
38
|
+
)
|
|
39
|
+
graph_writer.write()
|
|
40
|
+
|
|
41
|
+
# load the graph
|
|
42
|
+
graph_loader = JSONGraphLoader(json_path=Path("data/northwind-graph.json"))
|
|
43
|
+
graph = self.graph_loader.load()
|
|
44
|
+
|
|
45
|
+
# index the graph using BM25
|
|
46
|
+
search_engine = BM25SearchEngine(Path("data/northwind-index"))
|
|
47
|
+
semantic_aspects = {
|
|
48
|
+
a.asset_id: cast(SemanticAspect, a.aspects["semantic_properties"])
|
|
49
|
+
for a in graph.assets
|
|
50
|
+
}
|
|
51
|
+
search_engine.index(semantic_aspects)
|
|
52
|
+
|
|
53
|
+
# retrieve assets using BM25
|
|
54
|
+
assets_ids = search_engine.search(
|
|
55
|
+
"Give me the total count of orders in each categories"
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
For visualization purpose, this is the graph saved in JSON:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"assets": [
|
|
64
|
+
{
|
|
65
|
+
"asset_id": "8ab5a624-0596-497e-a0ee-3996d95dbe63",
|
|
66
|
+
"name": "Categories",
|
|
67
|
+
"type": "table",
|
|
68
|
+
"aspects": {
|
|
69
|
+
"schema_properties": {
|
|
70
|
+
"name": "Categories_table_schema",
|
|
71
|
+
"pks": ["CategoryID"],
|
|
72
|
+
"indices": {}
|
|
73
|
+
},
|
|
74
|
+
"statistical_properties": {
|
|
75
|
+
"name": "Categories_table_stats",
|
|
76
|
+
"num_columns": 4,
|
|
77
|
+
"num_rows": 8
|
|
78
|
+
},
|
|
79
|
+
"semantic_properties": {
|
|
80
|
+
"name": "Categories_semantic",
|
|
81
|
+
"description": "Stores product category definitions and metadata, serving as a lookup table for classifying products in the inventory system.",
|
|
82
|
+
"keywords": [
|
|
83
|
+
"categories",
|
|
84
|
+
"product classification",
|
|
85
|
+
"category definitions",
|
|
86
|
+
"inventory groups",
|
|
87
|
+
"product types"
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
...
|
|
93
|
+
],
|
|
94
|
+
"links": [
|
|
95
|
+
{
|
|
96
|
+
"link_id": "db6bea93-a02c-4426-a2db-449e4a7bba8f",
|
|
97
|
+
"name": "Categories_CategoryID",
|
|
98
|
+
"type": "contain",
|
|
99
|
+
"source_id": "8ab5a624-0596-497e-a0ee-3996d95dbe63",
|
|
100
|
+
"destination_id": "04c20046-2808-4021-bbf1-99876e0eea6e",
|
|
101
|
+
"aspects": {}
|
|
102
|
+
},
|
|
103
|
+
...
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Usecases
|
|
109
|
+
|
|
110
|
+

|
|
111
|
+
There are 4 main groups of usecases where DBGraph is applicable:
|
|
112
|
+
|
|
113
|
+
- **Manipulating database schema**: Build the schema graph, store it, and use it to traverse around the database, find JOIN path, get references tables, ...
|
|
114
|
+
- **Profiling database**: Use the concept of `Aspect` to represent different types of properties attached to a single data asset.
|
|
115
|
+
Each data asset can have a statistics aspects, semantical aspects, ...
|
|
116
|
+
- **Render graph**: Output schema graph to Markdown or text as context for LLM
|
|
117
|
+
- **LLM Assistance**: Leverage LLM to generate data assets' descriptions and tags. Furthermore, LLM could also be used in the process of SQL generation.
|
|
118
|
+
- **Search for data assets**: Search for wanted data assets based on their descriptions. The descriptions are indexed and retrieved with BM25 algorithms.
|
|
119
|
+
|
|
120
|
+
## Architecture
|
|
121
|
+
|
|
122
|
+

|
|
123
|
+
|
|
124
|
+
To encourage open-ness and extension, DBGraph is designed in a way that is very easy to extend.
|
|
125
|
+
|
|
126
|
+
1. **The core classes** (_entities_) define the shared business logic of database graphs (traversal, neighborhoods, ...) and core operations
|
|
127
|
+
within the application (building graphs, profiling databases, ...). The prefix _"R..."_ stands for _"Relational"_, as the class is dedicated
|
|
128
|
+
Relational databases only. The same stands for _"D.."_ (Document), _"V..."_ (Vector), _"G..."_ (Graph). However, at this point, the only supported
|
|
129
|
+
paradigm is Relational database.
|
|
130
|
+
2. **The interfaces** (_extensions_) define a part of the system that should be **pluggable**. For example:
|
|
131
|
+
|
|
132
|
+
- `RProfiler` and `RGraphBuilder` should works on multiple types of RDBMS, not just SQLite. Hence the abstraction of `RDataGateway`.
|
|
133
|
+
- We want to support multiple LLM providers. Hence the abstraction of `LLM`.
|
|
134
|
+
- There are many ways to render a graph into Markdown or text. Hence the abstraction of `RGraphRenderer`.
|
|
135
|
+
- To store and load the graph's data from some storages, we have multiple options. Hence the abstraction of `GraphGateway`.
|
|
136
|
+
- To index and retrieve graph's data from some search engines, we also have multiple options. Hence the abstraction of `SearchEngine`
|