mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-06-04 11:24:00 +08:00
Edit chunk shall update instead of insert it (#3709)
### What problem does this PR solve? Edit chunk shall update instead of insert it. Close #3679 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
9f57534843
commit
bc701d7b4c
@ -155,7 +155,7 @@ def set():
|
|||||||
v, c = embd_mdl.encode([doc.name, req["content_with_weight"]])
|
v, c = embd_mdl.encode([doc.name, req["content_with_weight"]])
|
||||||
v = 0.1 * v[0] + 0.9 * v[1] if doc.parser_id != ParserType.QA else v[1]
|
v = 0.1 * v[0] + 0.9 * v[1] if doc.parser_id != ParserType.QA else v[1]
|
||||||
d["q_%d_vec" % len(v)] = v.tolist()
|
d["q_%d_vec" % len(v)] = v.tolist()
|
||||||
settings.docStoreConn.insert([d], search.index_name(tenant_id), doc.kb_id)
|
settings.docStoreConn.update({"id": req["chunk_id"]}, d, search.index_name(tenant_id), doc.kb_id)
|
||||||
return get_json_result(data=True)
|
return get_json_result(data=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return server_error_response(e)
|
return server_error_response(e)
|
||||||
|
@ -168,7 +168,9 @@ def rm():
|
|||||||
if not KnowledgebaseService.delete_by_id(req["kb_id"]):
|
if not KnowledgebaseService.delete_by_id(req["kb_id"]):
|
||||||
return get_data_error_result(
|
return get_data_error_result(
|
||||||
message="Database error (Knowledgebase removal)!")
|
message="Database error (Knowledgebase removal)!")
|
||||||
settings.docStoreConn.delete({"kb_id": req["kb_id"]}, search.index_name(kbs[0].tenant_id), req["kb_id"])
|
for kb in kbs:
|
||||||
|
settings.docStoreConn.delete({"kb_id": kb.id}, search.index_name(kb.tenant_id), kb.id)
|
||||||
|
settings.docStoreConn.deleteIdx(search.index_name(kb.tenant_id), kb.id)
|
||||||
return get_json_result(data=True)
|
return get_json_result(data=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return server_error_response(e)
|
return server_error_response(e)
|
||||||
|
@ -252,7 +252,7 @@ def feishu_callback():
|
|||||||
if res["code"] != 0:
|
if res["code"] != 0:
|
||||||
return redirect("/?error=%s" % res["message"])
|
return redirect("/?error=%s" % res["message"])
|
||||||
|
|
||||||
if "contact:user.email:readonly" not in res["data"]["scope"].split(" "):
|
if "contact:user.email:readonly" not in res["data"]["scope"].split():
|
||||||
return redirect("/?error=contact:user.email:readonly not in scope")
|
return redirect("/?error=contact:user.email:readonly not in scope")
|
||||||
session["access_token"] = res["data"]["access_token"]
|
session["access_token"] = res["data"]["access_token"]
|
||||||
session["access_token_from"] = "feishu"
|
session["access_token_from"] = "feishu"
|
||||||
|
@ -47,7 +47,7 @@ class RAGFlowDocxParser:
|
|||||||
for p, n in patt:
|
for p, n in patt:
|
||||||
if re.search(p, b):
|
if re.search(p, b):
|
||||||
return n
|
return n
|
||||||
tks = [t for t in rag_tokenizer.tokenize(b).split(" ") if len(t) > 1]
|
tks = [t for t in rag_tokenizer.tokenize(b).split() if len(t) > 1]
|
||||||
if len(tks) > 3:
|
if len(tks) > 3:
|
||||||
if len(tks) < 12:
|
if len(tks) < 12:
|
||||||
return "Tx"
|
return "Tx"
|
||||||
|
@ -108,13 +108,13 @@ class RAGFlowPdfParser:
|
|||||||
h = max(self.__height(up), self.__height(down))
|
h = max(self.__height(up), self.__height(down))
|
||||||
y_dis = self._y_dis(up, down)
|
y_dis = self._y_dis(up, down)
|
||||||
LEN = 6
|
LEN = 6
|
||||||
tks_down = rag_tokenizer.tokenize(down["text"][:LEN]).split(" ")
|
tks_down = rag_tokenizer.tokenize(down["text"][:LEN]).split()
|
||||||
tks_up = rag_tokenizer.tokenize(up["text"][-LEN:]).split(" ")
|
tks_up = rag_tokenizer.tokenize(up["text"][-LEN:]).split()
|
||||||
tks_all = up["text"][-LEN:].strip() \
|
tks_all = up["text"][-LEN:].strip() \
|
||||||
+ (" " if re.match(r"[a-zA-Z0-9]+",
|
+ (" " if re.match(r"[a-zA-Z0-9]+",
|
||||||
up["text"][-1] + down["text"][0]) else "") \
|
up["text"][-1] + down["text"][0]) else "") \
|
||||||
+ down["text"][:LEN].strip()
|
+ down["text"][:LEN].strip()
|
||||||
tks_all = rag_tokenizer.tokenize(tks_all).split(" ")
|
tks_all = rag_tokenizer.tokenize(tks_all).split()
|
||||||
fea = [
|
fea = [
|
||||||
up.get("R", -1) == down.get("R", -1),
|
up.get("R", -1) == down.get("R", -1),
|
||||||
y_dis / h,
|
y_dis / h,
|
||||||
@ -565,13 +565,13 @@ class RAGFlowPdfParser:
|
|||||||
if i >= len(self.boxes):
|
if i >= len(self.boxes):
|
||||||
break
|
break
|
||||||
prefix = self.boxes[i]["text"].strip()[:3] if not eng else " ".join(
|
prefix = self.boxes[i]["text"].strip()[:3] if not eng else " ".join(
|
||||||
self.boxes[i]["text"].strip().split(" ")[:2])
|
self.boxes[i]["text"].strip().split()[:2])
|
||||||
while not prefix:
|
while not prefix:
|
||||||
self.boxes.pop(i)
|
self.boxes.pop(i)
|
||||||
if i >= len(self.boxes):
|
if i >= len(self.boxes):
|
||||||
break
|
break
|
||||||
prefix = self.boxes[i]["text"].strip()[:3] if not eng else " ".join(
|
prefix = self.boxes[i]["text"].strip()[:3] if not eng else " ".join(
|
||||||
self.boxes[i]["text"].strip().split(" ")[:2])
|
self.boxes[i]["text"].strip().split()[:2])
|
||||||
self.boxes.pop(i)
|
self.boxes.pop(i)
|
||||||
if i >= len(self.boxes) or not prefix:
|
if i >= len(self.boxes) or not prefix:
|
||||||
break
|
break
|
||||||
|
@ -47,7 +47,7 @@ def corpNorm(nm, add_region=True):
|
|||||||
nm = re.sub(r"(计算机|技术|(技术|科技|网络)*有限公司|公司|有限|研发中心|中国|总部)$", "", nm, 10000, re.IGNORECASE)
|
nm = re.sub(r"(计算机|技术|(技术|科技|网络)*有限公司|公司|有限|研发中心|中国|总部)$", "", nm, 10000, re.IGNORECASE)
|
||||||
if not nm or (len(nm)<5 and not regions.isName(nm[0:2])):return nm
|
if not nm or (len(nm)<5 and not regions.isName(nm[0:2])):return nm
|
||||||
|
|
||||||
tks = rag_tokenizer.tokenize(nm).split(" ")
|
tks = rag_tokenizer.tokenize(nm).split()
|
||||||
reg = [t for i,t in enumerate(tks) if regions.isName(t) and (t != "中国" or i > 0)]
|
reg = [t for i,t in enumerate(tks) if regions.isName(t) and (t != "中国" or i > 0)]
|
||||||
nm = ""
|
nm = ""
|
||||||
for t in tks:
|
for t in tks:
|
||||||
|
@ -44,7 +44,7 @@ loadRank(os.path.join(current_file_path, "res/school.rank.csv"))
|
|||||||
|
|
||||||
def split(txt):
|
def split(txt):
|
||||||
tks = []
|
tks = []
|
||||||
for t in re.sub(r"[ \t]+", " ",txt).split(" "):
|
for t in re.sub(r"[ \t]+", " ",txt).split():
|
||||||
if tks and re.match(r".*[a-zA-Z]$", tks[-1]) and \
|
if tks and re.match(r".*[a-zA-Z]$", tks[-1]) and \
|
||||||
re.match(r"[a-zA-Z]", t) and tks:
|
re.match(r"[a-zA-Z]", t) and tks:
|
||||||
tks[-1] = tks[-1] + " " + t
|
tks[-1] = tks[-1] + " " + t
|
||||||
|
@ -80,7 +80,7 @@ def refactor(df):
|
|||||||
def loadjson(line):
|
def loadjson(line):
|
||||||
try:
|
try:
|
||||||
return json.loads(line)
|
return json.loads(line)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@ -183,4 +183,4 @@ def refactor(df):
|
|||||||
"\r",
|
"\r",
|
||||||
"\\n"))
|
"\\n"))
|
||||||
# print(df.values.tolist())
|
# print(df.values.tolist())
|
||||||
return dict(zip([n.split(" ")[0] for n in FIELDS], df.values.tolist()[0]))
|
return dict(zip([n.split()[0] for n in FIELDS], df.values.tolist()[0]))
|
||||||
|
@ -100,7 +100,7 @@ def forEdu(cv):
|
|||||||
if n.get("school_name") and isinstance(n["school_name"], str):
|
if n.get("school_name") and isinstance(n["school_name"], str):
|
||||||
sch.append(re.sub(r"(211|985|重点大学|[,&;;-])", "", n["school_name"]))
|
sch.append(re.sub(r"(211|985|重点大学|[,&;;-])", "", n["school_name"]))
|
||||||
e["sch_nm_kwd"] = sch[-1]
|
e["sch_nm_kwd"] = sch[-1]
|
||||||
fea.append(rag_tokenizer.fine_grained_tokenize(rag_tokenizer.tokenize(n.get("school_name", ""))).split(" ")[-1])
|
fea.append(rag_tokenizer.fine_grained_tokenize(rag_tokenizer.tokenize(n.get("school_name", ""))).split()[-1])
|
||||||
|
|
||||||
if n.get("discipline_name") and isinstance(n["discipline_name"], str):
|
if n.get("discipline_name") and isinstance(n["discipline_name"], str):
|
||||||
maj.append(n["discipline_name"])
|
maj.append(n["discipline_name"])
|
||||||
@ -485,7 +485,7 @@ def parse(cv):
|
|||||||
nm = re.sub(r"[\n——\-\((\+].*", "", cv["name"].strip())
|
nm = re.sub(r"[\n——\-\((\+].*", "", cv["name"].strip())
|
||||||
nm = re.sub(r"[ \t ]+", " ", nm)
|
nm = re.sub(r"[ \t ]+", " ", nm)
|
||||||
if re.match(r"[a-zA-Z ]+$", nm):
|
if re.match(r"[a-zA-Z ]+$", nm):
|
||||||
if len(nm.split(" ")) > 1:
|
if len(nm.split()) > 1:
|
||||||
cv["name"] = nm
|
cv["name"] = nm
|
||||||
else:
|
else:
|
||||||
nm = ""
|
nm = ""
|
||||||
@ -503,7 +503,7 @@ def parse(cv):
|
|||||||
for py in PY.get_pinyins(nm[:20], ''):
|
for py in PY.get_pinyins(nm[:20], ''):
|
||||||
for i in range(2, len(py) + 1): cv["name_py_pref_tks"] += " " + py[:i]
|
for i in range(2, len(py) + 1): cv["name_py_pref_tks"] += " " + py[:i]
|
||||||
for py in PY.get_pinyins(nm[:20], ' '):
|
for py in PY.get_pinyins(nm[:20], ' '):
|
||||||
py = py.split(" ")
|
py = py.split()
|
||||||
for i in range(1, len(py) + 1): cv["name_py_pref0_tks"] += " " + "".join(py[:i])
|
for i in range(1, len(py) + 1): cv["name_py_pref0_tks"] += " " + "".join(py[:i])
|
||||||
|
|
||||||
cv["name_kwd"] = name
|
cv["name_kwd"] = name
|
||||||
|
@ -117,7 +117,7 @@ class TableStructureRecognizer(Recognizer):
|
|||||||
for p, n in patt:
|
for p, n in patt:
|
||||||
if re.search(p, b["text"].strip()):
|
if re.search(p, b["text"].strip()):
|
||||||
return n
|
return n
|
||||||
tks = [t for t in rag_tokenizer.tokenize(b["text"]).split(" ") if len(t) > 1]
|
tks = [t for t in rag_tokenizer.tokenize(b["text"]).split() if len(t) > 1]
|
||||||
if len(tks) > 3:
|
if len(tks) > 3:
|
||||||
if len(tks) < 12:
|
if len(tks) < 12:
|
||||||
return "Tx"
|
return "Tx"
|
||||||
|
@ -99,11 +99,11 @@ class Pdf(PdfParser):
|
|||||||
i += 1
|
i += 1
|
||||||
txt = b["text"].lower().strip()
|
txt = b["text"].lower().strip()
|
||||||
if re.match("(abstract|摘要)", txt):
|
if re.match("(abstract|摘要)", txt):
|
||||||
if len(txt.split(" ")) > 32 or len(txt) > 64:
|
if len(txt.split()) > 32 or len(txt) > 64:
|
||||||
abstr = txt + self._line_tag(b, zoomin)
|
abstr = txt + self._line_tag(b, zoomin)
|
||||||
break
|
break
|
||||||
txt = self.boxes[i]["text"].lower().strip()
|
txt = self.boxes[i]["text"].lower().strip()
|
||||||
if len(txt.split(" ")) > 32 or len(txt) > 64:
|
if len(txt.split()) > 32 or len(txt) > 64:
|
||||||
abstr = txt + self._line_tag(self.boxes[i], zoomin)
|
abstr = txt + self._line_tag(self.boxes[i], zoomin)
|
||||||
i += 1
|
i += 1
|
||||||
break
|
break
|
||||||
|
@ -33,7 +33,7 @@ def chunk(filename, binary, tenant_id, lang, callback=None, **kwargs):
|
|||||||
txt = "\n".join([t[0] for _, t in bxs if t[0]])
|
txt = "\n".join([t[0] for _, t in bxs if t[0]])
|
||||||
eng = lang.lower() == "english"
|
eng = lang.lower() == "english"
|
||||||
callback(0.4, "Finish OCR: (%s ...)" % txt[:12])
|
callback(0.4, "Finish OCR: (%s ...)" % txt[:12])
|
||||||
if (eng and len(txt.split(" ")) > 32) or len(txt) > 32:
|
if (eng and len(txt.split()) > 32) or len(txt) > 32:
|
||||||
tokenize(doc, txt, eng)
|
tokenize(doc, txt, eng)
|
||||||
callback(0.8, "OCR results is too long to use CV LLM.")
|
callback(0.8, "OCR results is too long to use CV LLM.")
|
||||||
return [doc]
|
return [doc]
|
||||||
|
@ -325,12 +325,12 @@ def remove_contents_table(sections, eng=False):
|
|||||||
sections.pop(i)
|
sections.pop(i)
|
||||||
if i >= len(sections):
|
if i >= len(sections):
|
||||||
break
|
break
|
||||||
prefix = get(i)[:3] if not eng else " ".join(get(i).split(" ")[:2])
|
prefix = get(i)[:3] if not eng else " ".join(get(i).split()[:2])
|
||||||
while not prefix:
|
while not prefix:
|
||||||
sections.pop(i)
|
sections.pop(i)
|
||||||
if i >= len(sections):
|
if i >= len(sections):
|
||||||
break
|
break
|
||||||
prefix = get(i)[:3] if not eng else " ".join(get(i).split(" ")[:2])
|
prefix = get(i)[:3] if not eng else " ".join(get(i).split()[:2])
|
||||||
sections.pop(i)
|
sections.pop(i)
|
||||||
if i >= len(sections) or not prefix:
|
if i >= len(sections) or not prefix:
|
||||||
break
|
break
|
||||||
@ -389,7 +389,7 @@ def title_frequency(bull, sections):
|
|||||||
def not_title(txt):
|
def not_title(txt):
|
||||||
if re.match(r"第[零一二三四五六七八九十百0-9]+条", txt):
|
if re.match(r"第[零一二三四五六七八九十百0-9]+条", txt):
|
||||||
return False
|
return False
|
||||||
if len(txt.split(" ")) > 12 or (txt.find(" ") < 0 and len(txt) >= 32):
|
if len(txt.split()) > 12 or (txt.find(" ") < 0 and len(txt) >= 32):
|
||||||
return True
|
return True
|
||||||
return re.search(r"[,;,。;!!]", txt)
|
return re.search(r"[,;,。;!!]", txt)
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class FulltextQueryer:
|
|||||||
|
|
||||||
if not self.isChinese(txt):
|
if not self.isChinese(txt):
|
||||||
txt = FulltextQueryer.rmWWW(txt)
|
txt = FulltextQueryer.rmWWW(txt)
|
||||||
tks = rag_tokenizer.tokenize(txt).split(" ")
|
tks = rag_tokenizer.tokenize(txt).split()
|
||||||
keywords = [t for t in tks if t]
|
keywords = [t for t in tks if t]
|
||||||
tks_w = self.tw.weights(tks, preprocess=False)
|
tks_w = self.tw.weights(tks, preprocess=False)
|
||||||
tks_w = [(re.sub(r"[ \\\"'^]", "", tk), w) for tk, w in tks_w]
|
tks_w = [(re.sub(r"[ \\\"'^]", "", tk), w) for tk, w in tks_w]
|
||||||
@ -83,7 +83,7 @@ class FulltextQueryer:
|
|||||||
syns = []
|
syns = []
|
||||||
for tk, w in tks_w:
|
for tk, w in tks_w:
|
||||||
syn = self.syn.lookup(tk)
|
syn = self.syn.lookup(tk)
|
||||||
syn = rag_tokenizer.tokenize(" ".join(syn)).split(" ")
|
syn = rag_tokenizer.tokenize(" ".join(syn)).split()
|
||||||
keywords.extend(syn)
|
keywords.extend(syn)
|
||||||
syn = ["\"{}\"^{:.4f}".format(s, w / 4.) for s in syn]
|
syn = ["\"{}\"^{:.4f}".format(s, w / 4.) for s in syn]
|
||||||
syns.append(" ".join(syn))
|
syns.append(" ".join(syn))
|
||||||
@ -114,7 +114,7 @@ class FulltextQueryer:
|
|||||||
|
|
||||||
txt = FulltextQueryer.rmWWW(txt)
|
txt = FulltextQueryer.rmWWW(txt)
|
||||||
qs, keywords = [], []
|
qs, keywords = [], []
|
||||||
for tt in self.tw.split(txt)[:256]: # .split(" "):
|
for tt in self.tw.split(txt)[:256]: # .split():
|
||||||
if not tt:
|
if not tt:
|
||||||
continue
|
continue
|
||||||
keywords.append(tt)
|
keywords.append(tt)
|
||||||
@ -125,7 +125,7 @@ class FulltextQueryer:
|
|||||||
tms = []
|
tms = []
|
||||||
for tk, w in sorted(twts, key=lambda x: x[1] * -1):
|
for tk, w in sorted(twts, key=lambda x: x[1] * -1):
|
||||||
sm = (
|
sm = (
|
||||||
rag_tokenizer.fine_grained_tokenize(tk).split(" ")
|
rag_tokenizer.fine_grained_tokenize(tk).split()
|
||||||
if need_fine_grained_tokenize(tk)
|
if need_fine_grained_tokenize(tk)
|
||||||
else []
|
else []
|
||||||
)
|
)
|
||||||
@ -194,7 +194,7 @@ class FulltextQueryer:
|
|||||||
def toDict(tks):
|
def toDict(tks):
|
||||||
d = {}
|
d = {}
|
||||||
if isinstance(tks, str):
|
if isinstance(tks, str):
|
||||||
tks = tks.split(" ")
|
tks = tks.split()
|
||||||
for t, c in self.tw.weights(tks, preprocess=False):
|
for t, c in self.tw.weights(tks, preprocess=False):
|
||||||
if t not in d:
|
if t not in d:
|
||||||
d[t] = 0
|
d[t] = 0
|
||||||
|
@ -192,7 +192,7 @@ class RagTokenizer:
|
|||||||
|
|
||||||
# if split chars is part of token
|
# if split chars is part of token
|
||||||
res = []
|
res = []
|
||||||
tks = re.sub(r"[ ]+", " ", tks).split(" ")
|
tks = re.sub(r"[ ]+", " ", tks).split()
|
||||||
s = 0
|
s = 0
|
||||||
while True:
|
while True:
|
||||||
if s >= len(tks):
|
if s >= len(tks):
|
||||||
@ -329,7 +329,7 @@ class RagTokenizer:
|
|||||||
return self.merge_(res)
|
return self.merge_(res)
|
||||||
|
|
||||||
def fine_grained_tokenize(self, tks):
|
def fine_grained_tokenize(self, tks):
|
||||||
tks = tks.split(" ")
|
tks = tks.split()
|
||||||
zh_num = len([1 for c in tks if c and is_chinese(c[0])])
|
zh_num = len([1 for c in tks if c and is_chinese(c[0])])
|
||||||
if zh_num < len(tks) * 0.2:
|
if zh_num < len(tks) * 0.2:
|
||||||
res = []
|
res = []
|
||||||
@ -393,7 +393,7 @@ def is_alphabet(s):
|
|||||||
|
|
||||||
def naiveQie(txt):
|
def naiveQie(txt):
|
||||||
tks = []
|
tks = []
|
||||||
for t in txt.split(" "):
|
for t in txt.split():
|
||||||
if tks and re.match(r".*[a-zA-Z]$", tks[-1]
|
if tks and re.match(r".*[a-zA-Z]$", tks[-1]
|
||||||
) and re.match(r".*[a-zA-Z]$", t):
|
) and re.match(r".*[a-zA-Z]$", t):
|
||||||
tks.append(" ")
|
tks.append(" ")
|
||||||
|
@ -114,7 +114,7 @@ class Dealer:
|
|||||||
|
|
||||||
for k in keywords:
|
for k in keywords:
|
||||||
kwds.add(k)
|
kwds.add(k)
|
||||||
for kk in rag_tokenizer.fine_grained_tokenize(k).split(" "):
|
for kk in rag_tokenizer.fine_grained_tokenize(k).split():
|
||||||
if len(kk) < 2:
|
if len(kk) < 2:
|
||||||
continue
|
continue
|
||||||
if kk in kwds:
|
if kk in kwds:
|
||||||
@ -186,7 +186,7 @@ class Dealer:
|
|||||||
assert len(ans_v[0]) == len(chunk_v[0]), "The dimension of query and chunk do not match: {} vs. {}".format(
|
assert len(ans_v[0]) == len(chunk_v[0]), "The dimension of query and chunk do not match: {} vs. {}".format(
|
||||||
len(ans_v[0]), len(chunk_v[0]))
|
len(ans_v[0]), len(chunk_v[0]))
|
||||||
|
|
||||||
chunks_tks = [rag_tokenizer.tokenize(self.qryr.rmWWW(ck)).split(" ")
|
chunks_tks = [rag_tokenizer.tokenize(self.qryr.rmWWW(ck)).split()
|
||||||
for ck in chunks]
|
for ck in chunks]
|
||||||
cites = {}
|
cites = {}
|
||||||
thr = 0.63
|
thr = 0.63
|
||||||
@ -195,7 +195,7 @@ class Dealer:
|
|||||||
sim, tksim, vtsim = self.qryr.hybrid_similarity(ans_v[i],
|
sim, tksim, vtsim = self.qryr.hybrid_similarity(ans_v[i],
|
||||||
chunk_v,
|
chunk_v,
|
||||||
rag_tokenizer.tokenize(
|
rag_tokenizer.tokenize(
|
||||||
self.qryr.rmWWW(pieces_[i])).split(" "),
|
self.qryr.rmWWW(pieces_[i])).split(),
|
||||||
chunks_tks,
|
chunks_tks,
|
||||||
tkweight, vtweight)
|
tkweight, vtweight)
|
||||||
mx = np.max(sim) * 0.99
|
mx = np.max(sim) * 0.99
|
||||||
@ -244,8 +244,8 @@ class Dealer:
|
|||||||
sres.field[i]["important_kwd"] = [sres.field[i]["important_kwd"]]
|
sres.field[i]["important_kwd"] = [sres.field[i]["important_kwd"]]
|
||||||
ins_tw = []
|
ins_tw = []
|
||||||
for i in sres.ids:
|
for i in sres.ids:
|
||||||
content_ltks = sres.field[i][cfield].split(" ")
|
content_ltks = sres.field[i][cfield].split()
|
||||||
title_tks = [t for t in sres.field[i].get("title_tks", "").split(" ") if t]
|
title_tks = [t for t in sres.field[i].get("title_tks", "").split() if t]
|
||||||
important_kwd = sres.field[i].get("important_kwd", [])
|
important_kwd = sres.field[i].get("important_kwd", [])
|
||||||
tks = content_ltks + title_tks + important_kwd
|
tks = content_ltks + title_tks + important_kwd
|
||||||
ins_tw.append(tks)
|
ins_tw.append(tks)
|
||||||
@ -265,8 +265,8 @@ class Dealer:
|
|||||||
sres.field[i]["important_kwd"] = [sres.field[i]["important_kwd"]]
|
sres.field[i]["important_kwd"] = [sres.field[i]["important_kwd"]]
|
||||||
ins_tw = []
|
ins_tw = []
|
||||||
for i in sres.ids:
|
for i in sres.ids:
|
||||||
content_ltks = sres.field[i][cfield].split(" ")
|
content_ltks = sres.field[i][cfield].split()
|
||||||
title_tks = [t for t in sres.field[i].get("title_tks", "").split(" ") if t]
|
title_tks = [t for t in sres.field[i].get("title_tks", "").split() if t]
|
||||||
important_kwd = sres.field[i].get("important_kwd", [])
|
important_kwd = sres.field[i].get("important_kwd", [])
|
||||||
tks = content_ltks + title_tks + important_kwd
|
tks = content_ltks + title_tks + important_kwd
|
||||||
ins_tw.append(tks)
|
ins_tw.append(tks)
|
||||||
@ -279,8 +279,8 @@ class Dealer:
|
|||||||
def hybrid_similarity(self, ans_embd, ins_embd, ans, inst):
|
def hybrid_similarity(self, ans_embd, ins_embd, ans, inst):
|
||||||
return self.qryr.hybrid_similarity(ans_embd,
|
return self.qryr.hybrid_similarity(ans_embd,
|
||||||
ins_embd,
|
ins_embd,
|
||||||
rag_tokenizer.tokenize(ans).split(" "),
|
rag_tokenizer.tokenize(ans).split(),
|
||||||
rag_tokenizer.tokenize(inst).split(" "))
|
rag_tokenizer.tokenize(inst).split())
|
||||||
|
|
||||||
def retrieval(self, question, embd_mdl, tenant_ids, kb_ids, page, page_size, similarity_threshold=0.2,
|
def retrieval(self, question, embd_mdl, tenant_ids, kb_ids, page, page_size, similarity_threshold=0.2,
|
||||||
vector_similarity_weight=0.3, top=1024, doc_ids=None, aggs=True, rerank_mdl=None, highlight=False):
|
vector_similarity_weight=0.3, top=1024, doc_ids=None, aggs=True, rerank_mdl=None, highlight=False):
|
||||||
|
@ -99,7 +99,7 @@ class Dealer:
|
|||||||
txt = re.sub(p, r, txt)
|
txt = re.sub(p, r, txt)
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
for t in rag_tokenizer.tokenize(txt).split(" "):
|
for t in rag_tokenizer.tokenize(txt).split():
|
||||||
tk = t
|
tk = t
|
||||||
if (stpwd and tk in self.stop_words) or (
|
if (stpwd and tk in self.stop_words) or (
|
||||||
re.match(r"[0-9]$", tk) and not num):
|
re.match(r"[0-9]$", tk) and not num):
|
||||||
@ -150,7 +150,7 @@ class Dealer:
|
|||||||
|
|
||||||
def split(self, txt):
|
def split(self, txt):
|
||||||
tks = []
|
tks = []
|
||||||
for t in re.sub(r"[ \t]+", " ", txt).split(" "):
|
for t in re.sub(r"[ \t]+", " ", txt).split():
|
||||||
if tks and re.match(r".*[a-zA-Z]$", tks[-1]) and \
|
if tks and re.match(r".*[a-zA-Z]$", tks[-1]) and \
|
||||||
re.match(r".*[a-zA-Z]$", t) and tks and \
|
re.match(r".*[a-zA-Z]$", t) and tks and \
|
||||||
self.ne.get(t, "") != "func" and self.ne.get(tks[-1], "") != "func":
|
self.ne.get(t, "") != "func" and self.ne.get(tks[-1], "") != "func":
|
||||||
@ -198,7 +198,7 @@ class Dealer:
|
|||||||
s = 0
|
s = 0
|
||||||
|
|
||||||
if not s and len(t) >= 4:
|
if not s and len(t) >= 4:
|
||||||
s = [tt for tt in rag_tokenizer.fine_grained_tokenize(t).split(" ") if len(tt) > 1]
|
s = [tt for tt in rag_tokenizer.fine_grained_tokenize(t).split() if len(tt) > 1]
|
||||||
if len(s) > 1:
|
if len(s) > 1:
|
||||||
s = np.min([freq(tt) for tt in s]) / 6.
|
s = np.min([freq(tt) for tt in s]) / 6.
|
||||||
else:
|
else:
|
||||||
@ -214,7 +214,7 @@ class Dealer:
|
|||||||
elif re.match(r"[a-z. -]+$", t):
|
elif re.match(r"[a-z. -]+$", t):
|
||||||
return 300
|
return 300
|
||||||
elif len(t) >= 4:
|
elif len(t) >= 4:
|
||||||
s = [tt for tt in rag_tokenizer.fine_grained_tokenize(t).split(" ") if len(tt) > 1]
|
s = [tt for tt in rag_tokenizer.fine_grained_tokenize(t).split() if len(tt) > 1]
|
||||||
if len(s) > 1:
|
if len(s) > 1:
|
||||||
return max(3, np.min([df(tt) for tt in s]) / 6.)
|
return max(3, np.min([df(tt) for tt in s]) / 6.)
|
||||||
|
|
||||||
|
@ -85,6 +85,9 @@ class ESConnection(DocStoreConnection):
|
|||||||
logging.exception("ESConnection.createIndex error %s" % (indexName))
|
logging.exception("ESConnection.createIndex error %s" % (indexName))
|
||||||
|
|
||||||
def deleteIdx(self, indexName: str, knowledgebaseId: str):
|
def deleteIdx(self, indexName: str, knowledgebaseId: str):
|
||||||
|
if len(knowledgebaseId) > 0:
|
||||||
|
# The index need to be alive after any kb deletion since all kb under this tenant are in one index.
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
self.es.indices.delete(index=indexName, allow_no_indices=True)
|
self.es.indices.delete(index=indexName, allow_no_indices=True)
|
||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
@ -400,7 +403,7 @@ class ESConnection(DocStoreConnection):
|
|||||||
if not hlts:
|
if not hlts:
|
||||||
continue
|
continue
|
||||||
txt = "...".join([a for a in list(hlts.items())[0][1]])
|
txt = "...".join([a for a in list(hlts.items())[0][1]])
|
||||||
if not is_english(txt.split(" ")):
|
if not is_english(txt.split()):
|
||||||
ans[d["_id"]] = txt
|
ans[d["_id"]] = txt
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ class InfinityConnection(DocStoreConnection):
|
|||||||
v = list(v)
|
v = list(v)
|
||||||
elif fieldnm == "important_kwd":
|
elif fieldnm == "important_kwd":
|
||||||
assert isinstance(v, str)
|
assert isinstance(v, str)
|
||||||
v = v.split(" ")
|
v = v.split()
|
||||||
else:
|
else:
|
||||||
if not isinstance(v, str):
|
if not isinstance(v, str):
|
||||||
v = str(v)
|
v = str(v)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user