mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-28 04:51:29 +00:00
feat: add GraphRAG framework and integrate TuGraph (#1506)
Co-authored-by: KingSkyLi <15566300566@163.com> Co-authored-by: aries_ckt <916701291@qq.com> Co-authored-by: Fangyin Cheng <staneyffer@gmail.com>
This commit is contained in:
42
dbgpt/storage/graph_store/factory.py
Normal file
42
dbgpt/storage/graph_store/factory.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Connector for vector store."""
|
||||
import logging
|
||||
from typing import Tuple, Type
|
||||
|
||||
from dbgpt.storage import graph_store
|
||||
from dbgpt.storage.graph_store.base import GraphStoreBase, GraphStoreConfig
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GraphStoreFactory:
|
||||
"""Factory for graph store."""
|
||||
|
||||
@staticmethod
|
||||
def create(graph_store_type: str, graph_store_configure=None) -> GraphStoreBase:
|
||||
"""Create a GraphStore instance.
|
||||
|
||||
Args:
|
||||
- graph_store_type: graph store type Memory, TuGraph, Neo4j
|
||||
- graph_store_config: graph store config
|
||||
"""
|
||||
store_cls, cfg_cls = GraphStoreFactory.__find_type(graph_store_type)
|
||||
|
||||
try:
|
||||
config = cfg_cls()
|
||||
if graph_store_configure:
|
||||
graph_store_configure(config)
|
||||
return store_cls(config)
|
||||
except Exception as e:
|
||||
logger.error("create graph store failed: %s", e)
|
||||
raise e
|
||||
|
||||
@staticmethod
|
||||
def __find_type(graph_store_type: str) -> Tuple[Type, Type]:
|
||||
for t in graph_store.__all__:
|
||||
if t.lower() == graph_store_type.lower():
|
||||
store_cls, cfg_cls = getattr(graph_store, t)
|
||||
if issubclass(store_cls, GraphStoreBase) and issubclass(
|
||||
cfg_cls, GraphStoreConfig
|
||||
):
|
||||
return store_cls, cfg_cls
|
||||
raise Exception(f"Graph store {graph_store_type} not supported")
|
Reference in New Issue
Block a user