Add doc meta data. (#4442)

### What problem does this PR solve?

#3690

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
Kevin Hu
2025-01-10 19:06:59 +08:00
committed by GitHub
parent 4dde73f897
commit 7d909d4d1b
5 changed files with 56 additions and 13 deletions

View File

@ -122,15 +122,17 @@ def kb_prompt(kbinfos, max_tokens):
knowledges = knowledges[:i]
break
#docs = DocumentService.get_by_ids([ck["doc_id"] for ck in kbinfos["chunks"][:chunks_num]])
#docs = {d.id: d.meta_fields for d in docs}
doc2chunks = defaultdict(list)
for i, ck in enumerate(kbinfos["chunks"]):
if i >= chunks_num:
break
for ck in kbinfos["chunks"][:chunks_num]:
doc2chunks[ck["docnm_kwd"]].append(ck["content_with_weight"])
knowledges = []
for nm, chunks in doc2chunks.items():
txt = f"Document: {nm} \nContains the following relevant fragments:\n"
txt = f"Document: {nm} \n"
txt += "Contains the following relevant fragments:\n"
for i, chunk in enumerate(chunks, 1):
txt += f"{i}. {chunk}\n"
knowledges.append(txt)