Skip to content

Commit 0fe1e53

Browse files
author
zhangping24
committed
support baidu vdb as doc engine and field weight assignments
1 parent 5ac7f59 commit 0fe1e53

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ dependencies = [
126126
"debugpy>=1.8.13",
127127
"mcp>=1.9.4",
128128
"opensearch-py==2.7.1",
129-
"pymochow==2.2.4"
129+
"pymochow==2.2.9"
130130
"pluginlib==0.9.4",
131131
"click>=8.1.8",
132132
"python-calamine>=0.4.0",

rag/utils/baidu_vdb_conn.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def __init__(self):
7575
raise Exception(f"Mapping file not found at {fp_mapping}")
7676
self.mapping = json.load(open(fp_mapping))
7777
healthy = self.health()
78+
self.query_fields_boosts = {
79+
"title_tks": 10,
80+
"title_sm_tks": 5,
81+
"important_tks": 20,
82+
"question_tks": 20,
83+
"content_ltks": 2,
84+
"content_sm_ltks": 1,
85+
}
7886
if healthy["err"] == "":
7987
logger.info(f"BaiduVDB {settings.BAIDUVDB['endpoint']} is healthy.")
8088
else:
@@ -333,7 +341,13 @@ def _select(self, db: Database, indexNames: list[str], projections: list[str], f
333341
def _matchTextExpr2Bm25SearchReq(self, m: MatchTextExpr, filter: str) -> BM25SearchRequest:
334342
search_text_cond = list()
335343
for field in m.fields:
336-
search_text_cond.append(f"{field}:{m.matching_text}")
344+
boost = 1
345+
if field in self.query_fields_boosts:
346+
boost = self.query_fields_boosts[field]
347+
if boost != 1:
348+
search_text_cond.append(f"{field}:{m.matching_text}^{boost}")
349+
else:
350+
search_text_cond.append(f"{field}:{m.matching_text}")
337351
search_text = " OR ".join(search_text_cond)
338352
return BM25SearchRequest(
339353
index_name=self.tks_inverted_idx,

0 commit comments

Comments
 (0)