RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
add README to graph (#1211)
KevinHuShfe1805fa0ef6
diff --git a/graph/README.md b/graph/README.mdnew file mode 100644index 0000000000..71e654f033--- /dev/null+++ b/graph/README.md@@ -0,0 +1,45 @@+English | [简体中文](./README_zh.md)++# *Graph*+++## Introduction++*Graph* is a mathematical concept which is composed of nodes and edges.+It is used to compose a complex work flow or agent.+And this graph is beyond the DAG that we can use circles to describe our agent or work flow.+Under this folder, we propose a test tool ./test/client.py which can test the DSLs such as json files in folder ./test/dsl_examples.+Please use this client at the same folder you start RAGFlow. If it's ran by docker, please go into the container before running the client.+Otherwise, correct configurations in conf/service_conf.yaml is essential.++```bash+PYTHONPATH=path/to/ragflow python graph/test/client.py -h+usage: client.py [-h] -s DSL -t TENANT_ID -m++options:+ -h, --help show this help message and exit+ -s DSL, --dsl DSL input dsl+ -t TENANT_ID, --tenant_id TENANT_ID+ Tenant ID+ -m, --stream Stream output+```+<div align="center" style="margin-top:20px;margin-bottom:20px;">+<img src="https://github.com/infiniflow/ragflow/assets/12318111/79179c5e-d4d6-464a-b6c4-5721cb329899" width="1000"/>+</div>+++## How to gain a TENANT_ID in command line?+<div align="center" style="margin-top:20px;margin-bottom:20px;">+<img src="https://github.com/infiniflow/ragflow/assets/12318111/419d8588-87b1-4ab8-ac49-2d1f047a4b97" width="600"/>+</div>+💡 We plant to display it here in the near future.+<div align="center" style="margin-top:20px;margin-bottom:20px;">+<img src="https://github.com/infiniflow/ragflow/assets/12318111/c97915de-0091-46a5-afd9-e278946e5fe3" width="600"/>+</div>+++## How to set 'kb_ids' for component 'Retrieval' in DSL?+<div align="center" style="margin-top:20px;margin-bottom:20px;">+<img src="https://github.com/infiniflow/ragflow/assets/12318111/0a731534-cac8-49fd-8a92-ca247eeef66d" width="600"/>+</div>+diff --git a/graph/README_zh.md b/graph/README_zh.mdnew file mode 100644index 0000000000..003ff4b7a4--- /dev/null+++ b/graph/README_zh.md@@ -0,0 +1,46 @@+[English](./README.md) | 简体中文++# *Graph*+++## 简介++"Graph"是一个由节点和边组成的数学概念。+它被用来构建复杂的工作流或代理。+这个图超越了有向无环图(DAG),我们可以使用循环来描述我们的代理或工作流。+在这个文件夹下,我们提出了一个测试工具 ./test/client.py,+它可以测试像文件夹./test/dsl_examples下一样的DSL文件。+请在启动 RAGFlow 的同一文件夹中使用此客户端。如果它是通过 Docker 运行的,请在运行客户端之前进入容器。+否则,正确配置 conf/service_conf.yaml 文件是必不可少的。++```bash+PYTHONPATH=path/to/ragflow python graph/test/client.py -h+usage: client.py [-h] -s DSL -t TENANT_ID -m++options:+ -h, --help show this help message and exit+ -s DSL, --dsl DSL input dsl+ -t TENANT_ID, --tenant_id TENANT_ID+ Tenant ID+ -m, --stream Stream output+```+<div align="center" style="margin-top:20px;margin-bottom:20px;">+<img src="https://github.com/infiniflow/ragflow/assets/12318111/05924730-c427-495b-8ee4-90b8b2250681" width="1000"/>+</div>+++## 命令行中的TENANT_ID如何获得?+<div align="center" style="margin-top:20px;margin-bottom:20px;">+<img src="https://github.com/infiniflow/ragflow/assets/12318111/419d8588-87b1-4ab8-ac49-2d1f047a4b97" width="600"/>+</div>+💡 后面会展示在这里:+<div align="center" style="margin-top:20px;margin-bottom:20px;">+<img src="https://github.com/infiniflow/ragflow/assets/12318111/c97915de-0091-46a5-afd9-e278946e5fe3" width="600"/>+</div>+++## DSL里面的Retrieval组件的kb_ids怎么填?+<div align="center" style="margin-top:20px;margin-bottom:20px;">+<img src="https://github.com/infiniflow/ragflow/assets/12318111/0a731534-cac8-49fd-8a92-ca247eeef66d" width="600"/>+</div>+diff --git a/graph/canvas.py b/graph/canvas.pyindex 08b842b76d..c5b122fbcc 100644--- a/graph/canvas.py+++ b/graph/canvas.py@@ -24,7 +24,7 @@ import pandas as pdfrom graph.component import component_classfrom graph.component.base import ComponentBase-from graph.settings import flow_logger+from graph.settings import flow_logger, DEBUGclass Canvas(ABC):@@ -170,14 +170,14 @@ class Canvas(ABC):if cpn.component_name == "Answer":self.answer.append(c)else:- print("RUN: ", c)+ if DEBUG: print("RUN: ", c)ans = cpn.run(self.history, **kwargs)self.path[-1].append(c)ran += 1prepare2run(self.components[self.path[-2][-1]]["downstream"])while ran < len(self.path[-1]):- print(ran, self.path)+ if DEBUG: print(ran, self.path)cpn_id = self.path[-1][ran]cpn = self.get_component(cpn_id)if not cpn["downstream"]: breakdiff --git a/graph/component/base.py b/graph/component/base.pyindex 904072d251..76d3e07660 100644--- a/graph/component/base.py+++ b/graph/component/base.py@@ -24,7 +24,7 @@ from typing import List, Dictimport pandas as pdfrom graph import settings-from graph.settings import flow_logger+from graph.settings import flow_logger, DEBUG_FEEDED_DEPRECATED_PARAMS = "_feeded_deprecated_params"_DEPRECATED_PARAMS = "_deprecated_params"@@ -428,7 +428,7 @@ class ComponentBase(ABC):reversed_cpnts.extend(self._canvas.path[-2])reversed_cpnts.extend(self._canvas.path[-1])- print(self.component_name, reversed_cpnts[::-1])+ if DEBUG: print(self.component_name, reversed_cpnts[::-1])for u in reversed_cpnts[::-1]:if self.get_component_name(u) in ["switch"]: continueif self.component_name.lower().find("switch") < 0 \diff --git a/graph/component/categorize.py b/graph/component/categorize.pyindex 2ab5bc5a59..8a7f90e705 100644--- a/graph/component/categorize.py+++ b/graph/component/categorize.py@@ -20,6 +20,7 @@ import pandas as pdfrom api.db import LLMTypefrom api.db.services.llm_service import LLMBundlefrom graph.component import GenerateParam, Generate+from graph.settings import DEBUGclass CategorizeParam(GenerateParam):@@ -72,12 +73,11 @@ class Categorize(Generate, ABC):def _run(self, history, **kwargs):input = self.get_input()- print(input, "DDDDDDDDDDDDDDDDDDDDDDDDDDDDD")input = "Question: " + ("; ".join(input["content"]) if "content" in input else "") + "Category: "chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id)ans = chat_mdl.chat(self._param.get_prompt(), [{"role": "user", "content": input}],self._param.gen_conf())- print(ans, ":::::::::::::::::::::::::::::::::")+ if DEBUG: print(ans, ":::::::::::::::::::::::::::::::::", input)for c in self._param.category_description.keys():if ans.lower().find(c.lower()) >= 0:return Categorize.be_output(self._param.category_description[c]["to"])diff --git a/graph/settings.py b/graph/settings.pyindex e0cd1144ed..f6fec1075f 100644--- a/graph/settings.py+++ b/graph/settings.py@@ -19,6 +19,7 @@ import osfrom api.utils.file_utils import get_project_base_directoryfrom api.utils.log_utils import LoggerFactory, getLogger+DEBUG = 0LoggerFactory.set_directory(os.path.join(get_project_base_directory(),@@ -30,4 +31,4 @@ LoggerFactory.LEVEL = 30flow_logger = getLogger("flow")database_logger = getLogger("database")FLOAT_ZERO = 1e-8-PARAM_MAXDEPTH = 5\ No newline at end of file+PARAM_MAXDEPTH = 5diff --git a/graph/test/client.py b/graph/test/client.pyindex 1f93382da3..3682a51721 100644--- a/graph/test/client.py+++ b/graph/test/client.py@@ -18,6 +18,7 @@ import osfrom functools import partialimport readlinefrom graph.canvas import Canvas+from graph.settings import DEBUGif __name__ == '__main__':parser = argparse.ArgumentParser()@@ -28,21 +29,21 @@ if __name__ == '__main__':)parser.add_argument('-s', '--dsl', default=dsl_default_path, help="input dsl", action='store', required=True)parser.add_argument('-t', '--tenant_id', default=False, help="Tenant ID", action='store', required=True)- parser.add_argument('-m', '--stream', default=False, help="Stream output", action='store_true', required=True)+ parser.add_argument('-m', '--stream', default=False, help="Stream output", action='store_true', required=False)args = parser.parse_args()canvas = Canvas(open(args.dsl, "r").read(), args.tenant_id)while True:ans = canvas.run(stream=args.stream)- print("==================== Bot =====================\n> ")+ print("==================== Bot =====================\n> ", end='')if args.stream and isinstance(ans, partial):cont = ""for an in ans():- print(an["content"][len(cont):], end='')+ print(an["content"][len(cont):], end='', flush=True)cont = an["content"]else:print(ans["content"])- print(canvas.path)- question = input("==================== User =====================\n> ")+ if DEBUG: print(canvas.path)+ question = input("\n==================== User =====================\n> ")canvas.add_user_input(question)diff --git a/graph/test/dsl_examples/customer_service.json b/graph/test/dsl_examples/customer_service.jsonindex bda69c636b..11b8460b80 100644--- a/graph/test/dsl_examples/customer_service.json+++ b/graph/test/dsl_examples/customer_service.json@@ -4,7 +4,7 @@"obj":{"component_name": "Begin","params": {- "prologue": "Hi there!"+ "prologue": "Hi! How can I help you?"}},"downstream": ["answer:0"],