Skip to content

Issue with MultiRetrievalQAChain when using returnSourceDocuments option #2355

Closed

Description

@ashbuilds

Hi, Im trying to implement MultiRetrievalQAChain which works as expected without the option returnSourceDocuments but as I need source documents to further generate referral links or to analyse what has been retrieved, Im unable to do so because it seems passing this option is breaking some lc function that does not have info of passed parameter returnSourceDocuments

return MultiRetrievalQAChain.fromLLMAndRetrievers(chatGPT3Model, {
			retrieverNames,
			retrieverDescriptions,
			retrievers,
			retrievalQAChainOpts: {
			        // Enabling below breaks the chain and unable to produce output
			 	returnSourceDocuments: true, 
			 },
		});

Activity

  1. dosubot commented on Aug 21, 2023

    @dosubot

    🤖

    Hi there,

    Based on the information you've provided and the context from the LangChain repository, it seems that the MultiRetrievalQAChain class does support the returnSourceDocuments option. However, there might be some confusion about how to access the returned source documents.

    In LangChain, the source documents are returned in the sourceDocuments property, not the source property. Here's how you can modify your function to return the source documents:

    async function converse(prompt, chatHistory, senderId) {
        const followUpRes = await chain.call({
            question: prompt,
            chat_history: chatHistory,
            search: false,
            returnSourceDocuments: true
        });
        chatHistory = `${prompt}${followUpRes.text}`;
        console.log(followUpRes);
        return { text: followUpRes.text, source: followUpRes.sourceDocuments };
    }

    In your function, you should also adjust the console log to handle the source as an array, as sourceDocuments is an array of source documents:

    const { text, source } = await converse(prompt, chatHistory, 1);
    if (source && source.length > 0) {
        console.log(`\nSource: ${source[0].pageContent}`);
    }

    This will print the pageContent of the first source document. If you want to print all source documents, you can loop over the source array.

    If you're still encountering issues, could you please provide the exact error message or describe the behavior you're observing when the returnSourceDocuments option is set to true? This will help me better understand the problem and provide a more accurate solution.

    Best,
    Dosu

    Sources


    This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

    Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

    If you want to continue the conversation, start your reply with Dosu Bot (@dosu-bot).

  2. ashbuilds commented on Aug 21, 2023

    @ashbuilds
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions