Retrieval and generation
In the code, the retrieval and generation stages are combined within the chain we set up to represent the entire RAG process. This leverages pre-built components from the LangChain Hub, such as prompt templates, and integrates them with a selected LLM. We will also utilize the LangChain Expression Language (LCEL) to define a chain of operations that retrieves relevant documents based on an input question, formats the retrieved content, and feeds it into the LLM to generate a response. Overall, the steps we take in retrieval and generation are as follows:
- Take in a user query.
- Vectorize that user query.
- Perform a similarity search of the vector store to find the closest vectors to the user query vector, as well as their associated content.
- Pass the retrieved content into a prompt template, a process known as hydrating.
- Pass that hydrated prompt to the LLM.
- Once you receive a response from the LLM, present it to the user.
From...