KevinHuSh commited on
Commit
390a40a
·
1 Parent(s): 5245317

fix disabled doc is still retreivalable (#695)

Browse files

### What problem does this PR solve?

Fix that disabled doc is still retreivalable

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Files changed (1) hide show
  1. rag/nlp/search.py +16 -12
rag/nlp/search.py CHANGED
@@ -52,16 +52,21 @@ class Dealer:
52
  def search(self, req, idxnm, emb_mdl=None):
53
  qst = req.get("question", "")
54
  bqry, keywords = self.qryr.question(qst)
55
- if req.get("kb_ids"):
56
- bqry.filter.append(Q("terms", kb_id=req["kb_ids"]))
57
- if req.get("doc_ids"):
58
- bqry.filter.append(Q("terms", doc_id=req["doc_ids"]))
59
- if "available_int" in req:
60
- if req["available_int"] == 0:
61
- bqry.filter.append(Q("range", available_int={"lt": 1}))
62
- else:
63
- bqry.filter.append(
64
- Q("bool", must_not=Q("range", available_int={"lt": 1})))
 
 
 
 
 
65
  bqry.boost = 0.05
66
 
67
  s = Search()
@@ -117,8 +122,7 @@ class Dealer:
117
  es_logger.info("TOTAL: {}".format(self.es.getTotal(res)))
118
  if self.es.getTotal(res) == 0 and "knn" in s:
119
  bqry, _ = self.qryr.question(qst, min_match="10%")
120
- if req.get("kb_ids"):
121
- bqry.filter.append(Q("terms", kb_id=req["kb_ids"]))
122
  s["query"] = bqry.to_dict()
123
  s["knn"]["filter"] = bqry.to_dict()
124
  s["knn"]["similarity"] = 0.17
 
52
  def search(self, req, idxnm, emb_mdl=None):
53
  qst = req.get("question", "")
54
  bqry, keywords = self.qryr.question(qst)
55
+ def add_filters(bqry):
56
+ nonlocal req
57
+ if req.get("kb_ids"):
58
+ bqry.filter.append(Q("terms", kb_id=req["kb_ids"]))
59
+ if req.get("doc_ids"):
60
+ bqry.filter.append(Q("terms", doc_id=req["doc_ids"]))
61
+ if "available_int" in req:
62
+ if req["available_int"] == 0:
63
+ bqry.filter.append(Q("range", available_int={"lt": 1}))
64
+ else:
65
+ bqry.filter.append(
66
+ Q("bool", must_not=Q("range", available_int={"lt": 1})))
67
+ return bqry
68
+
69
+ bqry = add_filters(bqry)
70
  bqry.boost = 0.05
71
 
72
  s = Search()
 
122
  es_logger.info("TOTAL: {}".format(self.es.getTotal(res)))
123
  if self.es.getTotal(res) == 0 and "knn" in s:
124
  bqry, _ = self.qryr.question(qst, min_match="10%")
125
+ bqry = add_filters(bqry)
 
126
  s["query"] = bqry.to_dict()
127
  s["knn"]["filter"] = bqry.to_dict()
128
  s["knn"]["similarity"] = 0.17