MCPcopy Create free account
hub / github.com/SmartFlowAI/EmoLLM / encode_qa

Function encode_qa

careyou/rag/src/util/encode.py:43–57  ·  view source on GitHub ↗
(file_path: str, store_path: str)

Source from the content-addressed store, hash-verified

41暂时只实现了加载 json,csv和txt先没写
42"""
43def 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)

Callers

nothing calls this directly

Calls 2

load_embeddingFunction · 0.70
encodeMethod · 0.45

Tested by

no test coverage detected