Skip to content

Commit

Permalink
add doc ids to chat (#1944)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

### Type of change

- [x] Performance Improvement
  • Loading branch information
KevinHuSh authored Aug 14, 2024
1 parent 853aa12 commit 78ed8fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/db/services/dialog_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def chat(dialog, messages, stream=True, **kwargs):
attachments = kwargs["doc_ids"].split(",") if "doc_ids" in kwargs else None
if "doc_ids" in messages[-1]:
attachments = messages[-1]["doc_ids"]
for m in messages[:-1]:
if "doc_ids" in m:
attachments.extend(m["doc_ids"])

embd_mdl = LLMBundle(dialog.tenant_id, LLMType.EMBEDDING, embd_nms[0])
if llm_id2llm_type(dialog.llm_id) == "image2text":
Expand Down
2 changes: 2 additions & 0 deletions rag/nlp/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ 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("doc_ids"):
bqry = Q("bool", must=[])
bqry = self._add_filters(bqry, req)
s["query"] = bqry.to_dict()
s["knn"]["filter"] = bqry.to_dict()
Expand Down

0 comments on commit 78ed8fe

Please sign in to comment.