Kevin Hu
commited on
Commit
·
dee924b
1
Parent(s):
8d91371
add doc ids to chat (#1944)
Browse files### What problem does this PR solve?
### Type of change
- [x] Performance Improvement
- api/db/services/dialog_service.py +3 -0
- rag/nlp/search.py +2 -0
api/db/services/dialog_service.py
CHANGED
@@ -108,6 +108,9 @@ def chat(dialog, messages, stream=True, **kwargs):
|
|
108 |
attachments = kwargs["doc_ids"].split(",") if "doc_ids" in kwargs else None
|
109 |
if "doc_ids" in messages[-1]:
|
110 |
attachments = messages[-1]["doc_ids"]
|
|
|
|
|
|
|
111 |
|
112 |
embd_mdl = LLMBundle(dialog.tenant_id, LLMType.EMBEDDING, embd_nms[0])
|
113 |
if llm_id2llm_type(dialog.llm_id) == "image2text":
|
|
|
108 |
attachments = kwargs["doc_ids"].split(",") if "doc_ids" in kwargs else None
|
109 |
if "doc_ids" in messages[-1]:
|
110 |
attachments = messages[-1]["doc_ids"]
|
111 |
+
for m in messages[:-1]:
|
112 |
+
if "doc_ids" in m:
|
113 |
+
attachments.extend(m["doc_ids"])
|
114 |
|
115 |
embd_mdl = LLMBundle(dialog.tenant_id, LLMType.EMBEDDING, embd_nms[0])
|
116 |
if llm_id2llm_type(dialog.llm_id) == "image2text":
|
rag/nlp/search.py
CHANGED
@@ -138,6 +138,8 @@ class Dealer:
|
|
138 |
es_logger.info("TOTAL: {}".format(self.es.getTotal(res)))
|
139 |
if self.es.getTotal(res) == 0 and "knn" in s:
|
140 |
bqry, _ = self.qryr.question(qst, min_match="10%")
|
|
|
|
|
141 |
bqry = self._add_filters(bqry, req)
|
142 |
s["query"] = bqry.to_dict()
|
143 |
s["knn"]["filter"] = bqry.to_dict()
|
|
|
138 |
es_logger.info("TOTAL: {}".format(self.es.getTotal(res)))
|
139 |
if self.es.getTotal(res) == 0 and "knn" in s:
|
140 |
bqry, _ = self.qryr.question(qst, min_match="10%")
|
141 |
+
if req.get("doc_ids"):
|
142 |
+
bqry = Q("bool", must=[])
|
143 |
bqry = self._add_filters(bqry, req)
|
144 |
s["query"] = bqry.to_dict()
|
145 |
s["knn"]["filter"] = bqry.to_dict()
|