Find answers from the community

Updated 3 weeks ago

Addressing Abrupt Topic Switches in Conversational AI

I am using condenseQuestionChatEngine for conversations. However, when the user abruptly switches topics, it sometimes condenses the question into an incoherent or nonsensical standalone question. How can I address this issue effectively?
L
r
9 comments
customizing the condense prompt?
tbh this is why i prefer the CondensePlusContext chat engine (condenses and calls retrieve for every user message, inserts the retrieved text as context into the system prompt)
What do you mean by 'every user message'? I only want it to retrieve the context for latest user message. I already have a query engine that I’m passing to condenseQuestionChatEngine, but the CondensePlusContext function doesn’t accept a query engine as a parameter. Instead, it requires a response synthesizer. How can I handle this situation?

Plain Text
 def initialize_query_engine(vector_index, docstore, top_k_context):
    try:
        custom_retriever = QueryFusionRetriever(
            [
                vector_index.as_retriever(similarity_top_k=top_k_context),
                BM25Retriever.from_defaults(docstore=docstore, similarity_top_k=int(top_k_context))
            ],
            similarity_top_k=12,
            mode='reciprocal_rerank',
            use_async=True,
            verbose=True,
            query_gen_prompt=query_gen_str,
        )
        
        response_synthesizer = get_response_synthesizer(
            response_mode="compact", 
            text_qa_template=custom_qa_prompt, 
            verbose=True,
            use_async=True,
            streaming=False
            
        )
        
        custom_query_engine = RetrieverQueryEngine.from_args(
            retriever=custom_retriever,
            node_postprocessors=[
                MetadataReplacementPostProcessor(target_metadata_key="table_df"),
                reranker,
                PrevNextNodePostprocessor(docstore=docstore, num_nodes=1)
            ],
            response_synthesizer=response_synthesizer,
            verbose=True,
            use_async = True
        )
        return custom_query_engine 
Yea latest user message is what I meant, same thing 🙂
CondensePlusContext uses a retriver
CondensePlusContextChatEngine.from_defaults(custom_retriever, node_postprocessors=node_postprocessors)
In your case, itd be the above
how do i add the response synthesizer in the above code ?
There is no response synthesizer (or there is, but it's not meant to be set by the user)

Just set the condense and context prompts as needed
Add a reply
Sign up and join the conversation on Discord