Find answers from the community

Updated last year

hey jerryjliu0 Logan M ravitheja

hey @jerryjliu0 @Logan M @ravitheja ,
I tried to add parallelize the evaluation under the llama_index>evaluation>base.py> QueryResponseEvaluator
the code is in the attachment
The code is working but then I notice in the debug mode that we are sending the same context for checking multiple times.
can you please help?
L
S
3 comments
Are you sure it's the same context?

context_list = self.get_context(response) just grabs the text from each source node

Plain Text
context = []
for context_info in response.source_nodes:
    context.append(Document(text=context_info.node.get_content()))


Not totally sure how it can repeat context πŸ€”

An easier implementation might look like this though. Asyncio is concurrancy, not multithreading, so this should have about the same speed running on every response no?

Plain Text
async def aevaluate_response(self, query: str, response: Response) -> Evaluation:
    """Evaluate the response from an index.
    
    Args:
        query: Query for which response is generated from index.
        response: Response object from an index based on the query.
    Returns:
        Evaluation object with passing boolean and feedback "YES" or "NO".
    """
    answer = str(response)
    
    context = self.get_context(response)
    index = SummaryIndex.from_documents(
        context, service_context=self.service_context
    )
    
    QUERY_RESPONSE_EVAL_PROMPT_TMPL = PromptTemplate(QUERY_RESPONSE_EVAL_PROMPT)
    QUERY_RESPONSE_REFINE_PROMPT_TMPL = PromptTemplate(QUERY_RESPONSE_REFINE_PROMPT)
    
    query_response = f"Question: {query}\nResponse: {answer}"
    
    query_engine = index.as_query_engine(
        text_qa_template=QUERY_RESPONSE_EVAL_PROMPT_TMPL,
        refine_template=QUERY_RESPONSE_REFINE_PROMPT_TMPL,
    )
    # JUST ADDED AWAIT AQUERY HERE
    response_obj = await query_engine.aquery(query_response) 
    
    raw_response_txt = str(response_obj)
    
    if "yes" in raw_response_txt.lower():
        return Evaluation(query, response, True, "YES")
    else:
        if self.raise_error:
            raise ValueError("The response is invalid")
        return Evaluation(query, response, False, "NO")
got it fixed,
was able to figure out the bug
An easier implementation might look like this though. Asyncio is concurrancy, not multithreading, so this should have about the same speed running on every response no?
yes we are using asyncio, asyncio is concurrency, since these are network calls and does not require processing, so using asyncio to not wait for response and do the pending call too.
Add a reply
Sign up and join the conversation on Discord