Skip to content

Commit d13875c

Browse files
authored
fix: rag knowledge process workflow template (#2509)
Close #issue2277 # Description fix rag knowledge process workflow template error # How Has This Been Tested? run rag knowledge process workflow template # Snapshots: Include snapshots for easier review. # Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have already rebased the commits and make the commit message conform to the project standard. - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] Any dependent changes have been merged and published in downstream modules
2 parents bc6983d + 4f2903a commit d13875c

20 files changed

+5805
-6122
lines changed

packages/dbgpt-core/src/dbgpt/storage/knowledge_graph/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pydantic import Field
99

10-
from dbgpt.core import Chunk
10+
from dbgpt.core import Chunk, Embeddings
1111
from dbgpt.storage.base import IndexStoreBase, IndexStoreConfig
1212
from dbgpt.storage.graph_store.graph import Graph
1313
from dbgpt.util import RegisterParameters
@@ -29,6 +29,11 @@ class KnowledgeGraphBase(IndexStoreBase, ABC):
2929
def get_config(self) -> KnowledgeGraphConfig:
3030
"""Get the knowledge graph config."""
3131

32+
@property
33+
def embeddings(self) -> Embeddings:
34+
"""Get the knowledge graph embeddings."""
35+
raise NotImplementedError
36+
3237
@abstractmethod
3338
def query_graph(self, limit: Optional[int] = None) -> Graph:
3439
"""Get graph data."""

packages/dbgpt-core/src/dbgpt/storage/vector_store/base.py

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
logger = logging.getLogger(__name__)
1919

20-
_COMMON_PARAMETERS = [
20+
_VECTOR_STORE_COMMON_PARAMETERS = [
2121
Parameter.build_from(
2222
_("Collection Name"),
2323
"name",
@@ -28,26 +28,6 @@
2828
optional=True,
2929
default="dbgpt_collection",
3030
),
31-
Parameter.build_from(
32-
_("User"),
33-
"user",
34-
str,
35-
description=_(
36-
"The user of vector store, if not set, will use the default user."
37-
),
38-
optional=True,
39-
default=None,
40-
),
41-
Parameter.build_from(
42-
_("Password"),
43-
"password",
44-
str,
45-
description=_(
46-
"The password of vector store, if not set, will use the default password."
47-
),
48-
optional=True,
49-
default=None,
50-
),
5131
Parameter.build_from(
5232
_("Embedding Function"),
5333
"embedding_fn",
@@ -59,28 +39,28 @@
5939
optional=True,
6040
default=None,
6141
),
42+
]
43+
44+
_COMMON_PARAMETERS = [
6245
Parameter.build_from(
63-
_("Max Chunks Once Load"),
64-
"max_chunks_once_load",
65-
int,
46+
_("User"),
47+
"user",
48+
str,
6649
description=_(
67-
"The max number of chunks to load at once. If your document is "
68-
"large, you can set this value to a larger number to speed up the loading "
69-
"process. Default is 10."
50+
"The user of vector store, if not set, will use the default user."
7051
),
7152
optional=True,
72-
default=10,
53+
default=None,
7354
),
7455
Parameter.build_from(
75-
_("Max Threads"),
76-
"max_threads",
77-
int,
56+
_("Password"),
57+
"password",
58+
str,
7859
description=_(
79-
"The max number of threads to use. Default is 1. If you set "
80-
"this bigger than 1, please make sure your vector store is thread-safe."
60+
"The password of vector store, if not set, will use the default password."
8161
),
8262
optional=True,
83-
default=1,
63+
default=None,
8464
),
8565
]
8666

packages/dbgpt-ext/src/dbgpt_ext/rag/operators/knowledge_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(
5858
"""Init the Knowledge Graph operator."""
5959
MapOperator.__init__(self, **kwargs)
6060
self._graph_store = graph_store
61-
self._embeddings = graph_store.get_config().embedding_fn
61+
self._embeddings = graph_store.embeddings
6262
self._max_chunks_once_load = max_chunks_once_load
6363
self.graph_store = graph_store
6464

packages/dbgpt-ext/src/dbgpt_ext/rag/operators/process_branch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,23 @@ async def branches(
8484

8585
async def check_graph_process(r: Knowledge) -> bool:
8686
# If check graph is true, we will run extract knowledge graph triplets.
87-
from dbgpt.rag.operators import KnowledgeGraphOperator
87+
from dbgpt_ext.rag.operators import KnowledgeGraphOperator
8888

8989
if KnowledgeGraphOperator in download_cls_list:
9090
return True
9191
return False
9292

9393
async def check_embedding_process(r: Knowledge) -> bool:
9494
# If check embedding is true, we will run extract document embedding.
95-
from dbgpt.rag.operators import VectorStorageOperator
95+
from dbgpt_ext.rag.operators import VectorStorageOperator
9696

9797
if VectorStorageOperator in download_cls_list:
9898
return True
9999
return False
100100

101101
async def check_full_text_process(r: Knowledge) -> bool:
102102
# If check full text is true, we will run extract document keywords.
103-
from dbgpt.rag.operators.full_text import FullTextStorageOperator
103+
from dbgpt_ext.rag.operators.full_text import FullTextStorageOperator
104104

105105
if FullTextStorageOperator in download_cls_list:
106106
return True

packages/dbgpt-ext/src/dbgpt_ext/rag/operators/vector_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(
5858
"""Init the datasource operator."""
5959
MapOperator.__init__(self, **kwargs)
6060
self._vector_store = vector_store
61-
self._embeddings = vector_store.get_config().embedding_fn
61+
self._embeddings = vector_store.embeddings
6262
self._max_chunks_once_load = max_chunks_once_load
6363
self.vector_store = vector_store
6464

packages/dbgpt-ext/src/dbgpt_ext/storage/graph_store/tugraph_store.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,55 @@
77
from dataclasses import dataclass, field
88
from typing import List
99

10+
from dbgpt.core.awel.flow import Parameter, ResourceCategory, register_resource
1011
from dbgpt.storage.graph_store.base import GraphStoreBase, GraphStoreConfig
1112
from dbgpt.storage.graph_store.graph import GraphElemType
13+
from dbgpt.util.i18n_utils import _
1214
from dbgpt_ext.datasource.conn_tugraph import TuGraphConnector
1315

1416
logger = logging.getLogger(__name__)
1517

1618

19+
@register_resource(
20+
_("TuGraph Graph Config"),
21+
"tugraph_config",
22+
category=ResourceCategory.KNOWLEDGE_GRAPH,
23+
description=_("TuGraph config."),
24+
parameters=[
25+
Parameter.build_from(
26+
_("host"),
27+
"host",
28+
str,
29+
optional=True,
30+
default="127.0.0.1",
31+
description=_("TuGraph host"),
32+
),
33+
Parameter.build_from(
34+
_("port"),
35+
"port",
36+
int,
37+
optional=True,
38+
default="7687",
39+
description=_("TuGraph port"),
40+
),
41+
Parameter.build_from(
42+
_("username"),
43+
"username",
44+
str,
45+
optional=True,
46+
default="admin",
47+
description=_("TuGraph username"),
48+
),
49+
Parameter.build_from(
50+
_("password"),
51+
"password",
52+
str,
53+
optional=True,
54+
default="73@TuGraph",
55+
description=_("TuGraph password"),
56+
),
57+
],
58+
)
1759
@dataclass
1860
class TuGraphStoreConfig(GraphStoreConfig):
1961
"""TuGraph store config."""

packages/dbgpt-ext/src/dbgpt_ext/storage/knowledge_graph/community_summary.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from dbgpt_ext.storage.knowledge_graph.knowledge_graph import (
2323
GRAPH_PARAMETERS,
2424
BuiltinKnowledgeGraph,
25-
BuiltinKnowledgeGraphConfig,
2625
)
2726

2827
logger = logging.getLogger(__name__)
@@ -146,10 +145,30 @@
146145
description=_("Community Summary Knowledge Graph."),
147146
parameters=[
148147
Parameter.build_from(
149-
_("Community Summary Knowledge Graph Config."),
148+
_("Graph Store Config"),
150149
"config",
151-
BuiltinKnowledgeGraphConfig,
152-
description=_("Community Summary Knowledge Graph Config."),
150+
GraphStoreConfig,
151+
description=_("graph store config."),
152+
),
153+
Parameter.build_from(
154+
_("Graph Store Name"),
155+
"name",
156+
str,
157+
optional=True,
158+
default="dbgpt",
159+
description=_("Graph Store Name"),
160+
),
161+
Parameter.build_from(
162+
_("LLM Client"),
163+
"llm_client",
164+
LLMClient,
165+
description=_("llm client for extract graph triplets."),
166+
),
167+
Parameter.build_from(
168+
_("LLM Model Name"),
169+
"llm_model",
170+
str,
171+
description=_("kg extract llm model name."),
153172
optional=True,
154173
default=None,
155174
),
@@ -285,6 +304,11 @@ def get_config(self) -> TuGraphStoreConfig:
285304
"""Get the knowledge graph config."""
286305
return self._config
287306

307+
@property
308+
def embeddings(self) -> Embeddings:
309+
"""Get the knowledge graph config."""
310+
return self._embedding_fn
311+
288312
async def aload_document(self, chunks: List[Chunk]) -> List[str]:
289313
"""Extract and persist graph from the document file."""
290314
if not self.vector_name_exists():

0 commit comments

Comments
 (0)