Skip to content

Commit

Permalink
fix disabled doc is still retreivalable (infiniflow#695)
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
KevinHuSh committed May 9, 2024
1 parent 9392b8b commit 648a2ba
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions rag/nlp/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@ def _vector(self, txt, emb_mdl, sim=0.8, topk=10):
def search(self, req, idxnm, emb_mdl=None):
qst = req.get("question", "")
bqry, keywords = self.qryr.question(qst)
if req.get("kb_ids"):
bqry.filter.append(Q("terms", kb_id=req["kb_ids"]))
if req.get("doc_ids"):
bqry.filter.append(Q("terms", doc_id=req["doc_ids"]))
if "available_int" in req:
if req["available_int"] == 0:
bqry.filter.append(Q("range", available_int={"lt": 1}))
else:
bqry.filter.append(
Q("bool", must_not=Q("range", available_int={"lt": 1})))
def add_filters(bqry):
nonlocal req
if req.get("kb_ids"):
bqry.filter.append(Q("terms", kb_id=req["kb_ids"]))
if req.get("doc_ids"):
bqry.filter.append(Q("terms", doc_id=req["doc_ids"]))
if "available_int" in req:
if req["available_int"] == 0:
bqry.filter.append(Q("range", available_int={"lt": 1}))
else:
bqry.filter.append(
Q("bool", must_not=Q("range", available_int={"lt": 1})))
return bqry

bqry = add_filters(bqry)
bqry.boost = 0.05

s = Search()
Expand Down Expand Up @@ -117,8 +122,7 @@ def search(self, req, idxnm, emb_mdl=None):
es_logger.info("TOTAL: {}".format(self.es.getTotal(res)))
if self.es.getTotal(res) == 0 and "knn" in s:
bqry, _ = self.qryr.question(qst, min_match="10%")
if req.get("kb_ids"):
bqry.filter.append(Q("terms", kb_id=req["kb_ids"]))
bqry = add_filters(bqry)
s["query"] = bqry.to_dict()
s["knn"]["filter"] = bqry.to_dict()
s["knn"]["similarity"] = 0.17
Expand Down

0 comments on commit 648a2ba

Please sign in to comment.