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
Long contexts in language models often create a significant challenge. Regardless of the model architecture, performance can degrade considerably when attempting to incorporate more than ten retrieved documents. A common phenomenon is "loss in the middle", where key information in the middle of documents may be ignored by the model. To address this problem, an effective technique is to rearrange the documents so that the most relevant is in the corners and the least important in the middle.
Implementing this concept in code can significantly improve the performance of language models. To do so, it is vital to use specific libraries and components that help in this process:
# initial setup and document fragmentationimport required librariesimport vector store, text splittercreate smaller document fragments
# create a 'Retriever' using MMR method or preferredcreate retriever with relevant documents.
It is recommended to import a document transformer called long context reorder
. This component is key as it reorganizes the documents in a way that the language model can process efficiently, minimizing the problem of loss in the middle:
# Initialize document transformerreordering = long context reorder()
# Function to reorder documentsreordered_docs = reordering.transform_documents(reordered_documents)
# Convert result to a listlist_documents = list(reordered_docs)
# Print reordered documentsprint(list_documents).
A Retrieval Augmented Generation pipeline combines information retrieval and text generation to answer user queries efficiently. The key is how the context is structured before being processed by the language model. Let's see how it is constructed:
retriever
to select the most relevant documents.transform documents
function to ensure that the most important documents are in key positions.# Code implementation of the pipelineuser_question = "Your question here"retriever = define_retriever()
# Get relevant documents and reorder themrelevant_documents = retriever.get_relevant_documents(user_question)reordered_documents = reordering.transform_documents(relevant_documents)
# Combination of documents into a single stringcontext = "join(reordered_documents)
# Call to language model to generate answer answer = language_model.invoke(user_question, context)print(answer)
The approach, by combining reordering with generation, not only improves the capture of relevant information but also optimizes the answers generated by the model. Implementing these steps, from using the appropriate libraries to effectively reordering and combining documents, ensures a marked improvement in the model's ability to interact with complex data.
Some recommendations to take your implementation to another level are:
And remember, never stop refining and adjusting your tools to maintain optimal information processing results. Constant practice and incremental learning will allow you to stay ahead in this field - keep going and don't lose motivation!
Contributions 3
Questions 1
Want to see more contributions, questions and answers from the community?