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
Fix some bugs in text2sql.(#4279)(#4281) (#4280)
TeslaZYdd13a5d05c3e
diff --git a/agent/component/exesql.py b/agent/component/exesql.pyindex 1b48b6b600..253dac5afb 100644--- a/agent/component/exesql.py+++ b/agent/component/exesql.py@@ -65,20 +65,16 @@ class ExeSQL(ComponentBase, ABC):self._loop += 1ans = self.get_input()--ans = "".join([str(a) for a in ans["content"]]) if "content" in ans else ""- if self._param.db_type == 'mssql':- # improve the information extraction, most llm return results in markdown format ```sql query ```- match = re.search(r"```sql\s*(.*?)\s*```", ans, re.DOTALL)- if match:- ans = match.group(1) # Query content- print(ans)- else:- print("no markdown")- ans = re.sub(r'^.*?SELECT ', 'SELECT ', (ans), flags=re.IGNORECASE)++ # improve the information extraction, most llm return results in markdown format ```sql query ```+ match = re.search(r"```sql\s*(.*?)\s*```", ans, re.DOTALL)+ if match:+ ans = match.group(1) # Query content+ print(ans)else:- ans = re.sub(r'^.*?SELECT ', 'SELECT ', repr(ans), flags=re.IGNORECASE)+ print("no markdown")+ ans = re.sub(r'^.*?SELECT ', 'SELECT ', (ans), flags=re.IGNORECASE)ans = re.sub(r';.*?SELECT ', '; SELECT ', ans, flags=re.IGNORECASE)ans = re.sub(r';[^;]*$', r';', ans)if not ans:diff --git a/rag/app/qa.py b/rag/app/qa.pyindex d77daebd64..824a398bd3 100644--- a/rag/app/qa.py+++ b/rag/app/qa.py@@ -12,6 +12,7 @@#import loggingimport re+import csvfrom copy import deepcopyfrom io import BytesIOfrom timeit import default_timer as timer@@ -25,7 +26,6 @@ from docx import Documentfrom PIL import Imagefrom markdown import markdown-class Excel(ExcelParser):def __call__(self, fnm, binary=None, callback=None):if not binary:@@ -320,7 +320,7 @@ def chunk(filename, binary=None, lang="Chinese", callback=None, **kwargs):res.append(beAdoc(deepcopy(doc), q, a, eng))return res- elif re.search(r"\.(txt|csv)$", filename, re.IGNORECASE):+ elif re.search(r"\.(txt)$", filename, re.IGNORECASE):callback(0.1, "Start to parse.")txt = get_text(filename, binary)lines = txt.split("\n")@@ -359,6 +359,38 @@ def chunk(filename, binary=None, lang="Chinese", callback=None, **kwargs):return res+ elif re.search(r"\.(csv)$", filename, re.IGNORECASE):+ callback(0.1, "Start to parse.")+ txt = get_text(filename, binary)+ lines = txt.split("\n")+ delimiter = "\t" if any("\t" in line for line in lines) else ","++ fails = []+ question, answer = "", ""+ res = []+ reader = csv.reader(lines, delimiter=delimiter)++ for i, row in enumerate(reader):+ if len(row) != 2:+ if question:+ answer += "\n" + lines[i]+ else:+ fails.append(str(i + 1))+ elif len(row) == 2:+ if question and answer:+ res.append(beAdoc(deepcopy(doc), question, answer, eng))+ question, answer = row+ if len(res) % 999 == 0:+ callback(len(res) * 0.6 / len(lines), ("Extract Q&A: {}".format(len(res)) + (+ f"{len(fails)} failure, line: %s..." % (",".join(fails[:3])) if fails else "")))++ if question:+ res.append(beAdoc(deepcopy(doc), question, answer, eng))++ callback(0.6, ("Extract Q&A: {}".format(len(res)) + (+ f"{len(fails)} failure, line: %s..." % (",".join(fails[:3])) if fails else "")))+ return res+elif re.search(r"\.pdf$", filename, re.IGNORECASE):callback(0.1, "Start to parse.")pdf_parser = Pdf()