Give an agent a tool that is itself a retriever. The agent can then call this tool and get back a list of documents
This allows the agent to decide when it wants to do retrieval - could do it once, twice, or not at all
We've also added a new type of memory
This type of memory allows for using the results of previous tool invocations in future agent interactions
This means if you ask a follow up question, you don't have to do retrieval all over again
The benefits over normal retrieval include:
- You don't do retrieval if the question isn't about the topic
- You don't do retrieval if the question is about previously mentioned topics
- You can do multiple retrieval steps
- You can retrieve from multiple sources
The downsides include:
- This type of memory takes up more space
- Sometimes the agent doesn't realize it needs to do retrieval
As models get better, and as context windows get longer, we expect these downsides to matter less!
We've included a really simple example of this setup in an example repo
Uses @streamlit for the UI, and LangSmith for feedback collection and monitoringgithub.com/hwchase17/conv…
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Combining documents with LLMs is a key part of retrieval and chaining
We've improved our @LangChainAI reference documentation across the 5 major CombineDocumentsChains and helper functions to help with clarity and understanding of how these work
🧵
📄 `format_document`
Want to control which metadata keys show up in the prompt?
This helper function is rarely exposed, but is key to combining documents with LLMs
It takes a Document and formats it into a string using a PromptTemplate
The most basic CombineDocumentsChain, this takes N documents, formats them into a string using a PromptTemplate and `format_document`, and then combines them into a single prompt and passes them to an LLM
Specify a schema and tag a document with those attributes
As opposed to Extraction, this extracts only one instance of that schema so its more useful for classification of attributes pertaining to the text as a whole
Wouldn't it be nice if there was a way to compose prompts together, reusing pieces across prompts?
In the newest Python and JS release there now is with `Pipeline Prompt`!
Links 👇
The way this works is you define a `PipelinePrompt` with two components:
- FinalPrompt: the final prompt template to be formatted
- PipelinePrompts: a sequence of tuples of (name, PromptTemplate)
The `name` argument is how the formatted prompt will be passed to future prompts
When `.format` is called, the PipelinePrompts are first formatted in order, and are then used in future formatting steps with their respective `name` arguments
Finally, the FinalPrompt.format is called using any previously formatted values as neccesary