Manejo de documentos
驴Qu茅 es context aware splitting?
Obtenci贸n de datos de la web con LangChain: Context aware data extraction
Context aware data extraction: PDF, XML, DOCX
Context aware splitting de documentos
Quiz: Manejo de documentos
Indexaci贸n de vectores
Evitar duplicidad de datos con indexaci贸n de vectores
Tipos de indexaci贸n de vectores: incremental, full y con BaseLoader
Quiz: Indexaci贸n de vectores
Recuperaci贸n de documentos
Parent Retriever
Parent Retriever: recuperaci贸n de fragmentos largos en lugar de documentos completos
Self-retriever: etiquetado de documentos
Self-retriever: ejecuci贸n de recuperaci贸n
MultiQuery retriever
Ensemble retriever
Quiz: Recuperaci贸n de documentos
Re-ranking sem谩ntico
Semantic re-ranking
DiversityRanker (MMR)
LostInTheMiddleRanker
Quiz: Re-ranking sem谩ntico
RAG
Integraci贸n de retrieval-augmented generation (RAG)
Ejecuci贸n del buscador con Streamlit
You don't have access to this class
Keep learning! Join and start boosting your career
A MultiQuery Retriever is an advanced technique used to improve the accuracy of retrieving relevant documents in a search system. It works by generating multiple queries from an initial one, allowing queries to be approached from different angles and capturing a broader context. This method is similar to the human process of rephrasing questions for better understanding and more accurate answers.
The process begins with the submission of an initial query, which is processed by a language model such as OpenAI. This model generates several new queries related to the original one. From these queries, the system searches a VectorStore for documents that best match each generated query. Finally, the relevant documents are combined into a complete set that provides a more detailed and contextualized answer to the user's original question.
To implement a MultiQuery Retriever, you must import the corresponding module. You will also need a VectorStore and an embedding system, as well as a language model (LLM). Here's how to do it:
from langchain.retrievers.multiquery import MultiQueryRetriever
# Setting up the VectorStore and language model modelmodel = chatOpenAI(temperature=0) # Adjusting the temperature to get consistent responsesretriever = MultiQueryRetriever(model, vectorStore).
Once the environment is set up, a basic retriever is created using a converted VectorStore using the asRetriever
method. The language model generates the questions and the retriever uses them to retrieve the relevant documents.
To customize the question generation process, LangChain offers the option to define an output schema using Pydantic. This is achieved by creating an output parser:
from pydantic import BaseModel
class lineList(BaseModel): lines: list[str] # List of generated questions
class lineListsOutputParser(PydanticOutputParser): def parse(self, text: str)-> lineList: lines = text.strip().split('\n') return lineList(lines=lines).
This definition allows structuring the data in such a way that it is iterable and easily manageable within the application.
Once the parser is defined, a specific prompt is constructed to guide the generation of questions. This is encapsulated in an LLM string:
prompt = "Generate multiple queries from an initial query..."output_parser = lineListsOutputParser().
Finally, the functionality is tested by executing the configured action string. This method invokes the language model, generating multiple queries and consolidating the results for the user's query:
result = retriever.invoke({ " question": "How to create a retriever with LangChain?"})print(result).
When executed, the system returns a structured set of questions, resulting in more accurate and complete answers. This process is critical for applications where the accuracy and detail of the answer is crucial.
Use low temperature: Set the language model to a low temperature to ensure consistency in the generated answers.
Customize the prompt: Tailor the prompt to the specific needs of the use case to ensure that the generated questions cover all necessary angles.
Check question consistency: Ensure that the generated questions are consistent and relevant to the context of the original query.
Optimize response time: Although the process may be slower due to multiple queries, finding a balance between the quality of responses and processing time is vital.
Incorporating these techniques into document search and retrieval systems not only improves the accuracy of responses, but also optimizes the user experience by providing richer and more detailed context. Continue to explore these tools and hone your ability to deliver accurate and valuable responses.
Contributions 3
Questions 0
Want to see more contributions, questions and answers from the community?