(file_path: str, store_path: str)
| 41 | 暂时只实现了加载 json,csv和txt先没写 |
| 42 | """ |
| 43 | def encode_qa(file_path: str, store_path: str) -> None: |
| 44 | emb = load_embedding() |
| 45 | with open(file_path, 'r', encoding='utf-8') as f: |
| 46 | qa_list = json.load(f) |
| 47 | |
| 48 | # 将 QA 对拼起来作为完整一句来编码,也可以只编码 Q |
| 49 | lines = [] |
| 50 | for qa in qa_list: |
| 51 | question = qa['question'] |
| 52 | answer = qa['answer'] |
| 53 | lines.append(question + answer) |
| 54 | |
| 55 | encoded_knowledge = emb.encode(lines) |
| 56 | with open(store_path, 'wb') as f: |
| 57 | pickle.dump(encoded_knowledge, f) |
nothing calls this directly
no test coverage detected