Skip to content
Discussion options

You must be logged in to vote

🤖

To add document sources to your code without modifying the context, you can create a new function that formats the documents along with their sources. This function can then be used in the RunnablePassthrough.assign method. Here's an example of how you can do this:

First, modify your format_docs function to include the document sources:

def format_docs_with_sources(docs):
    return "\n\n".join(f"{doc.page_content} (Source: {doc.source})" for doc in docs)

In this function, doc.source should contain the source of the document. You'll need to ensure that your documents have a source attribute that contains this information.

Next, use this new function in your RunnablePassthrough.assign call:

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@joshuafernandes
Comment options

@dosubot
Comment options

Answer selected by joshuafernandes
@joshuafernandes
Comment options

@dosubot
Comment options

@heroobo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants