BUAADreamer / EasyRAG

Easy-to-Use RAG Framework; CCF AIOps International Challenge 2024 Top3 Solution; CCF AIOps 国际挑战赛 2024 季军方案
https://arxiv.org/abs/2410.10315
MIT License
182 stars 23 forks source link

Add hyde implementation to pipeline #4

Closed Kuangdd01 closed 1 month ago

Kuangdd01 commented 1 month ago

I tried this test code, and it worked well.

def _test_hyde():
    llm = OpenAI(
        api_key="",
        model="glm-4-plus",
        api_base="",
        is_chat_model=True,
    )
    from src.easyrag.custom.template import HYDE_PROMPT_MODIFIED_MERGING, HYDE_PROMPT_MODIFIED_V2
    hyde_merging_prompt = PromptTemplate(HYDE_PROMPT_MODIFIED_MERGING)
    hyde_prompt = PromptTemplate(HYDE_PROMPT_MODIFIED_V2)
    hyde_transform_merging = HyDEQueryTransform(
        llm=llm, hyde_prompt=hyde_merging_prompt, include_original=True)
    hyde_transform = HyDEQueryTransform(
        llm=llm, hyde_prompt=hyde_prompt, include_original=True)

    query = "通信是什么?"
    hyde_query = hyde_transform(query)
    retrived_chunk = "通信是指信息的传递。"
    merging_template = f'问题:{hyde_query.query_str},\n可能有效的文档:' \
                       f'{hyde_query.custom_embedding_strs[0]},\n参考上下文:{retrived_chunk}'
    hyde_query_merging = hyde_transform_merging(merging_template)
    import pdb; pdb.set_trace()
    after_merging_query = query + hyde_query_merging.custom_embedding_strs[0]
    print(after_merging_query)