BM25 begrijpen
Voordat je een BM25-sparse retriever in je RAG-architectuur integreert, is het slim om hem eerst te testen op korte strings, zodat je gevoel krijgt voor hoe de retriever documenten selecteert.
Je hebt drie strings gekregen die je als basis voor je BM25-retriever gebruikt. De functionaliteit die je voor deze oefening nodig hebt, is al voor je geladen.
Deze oefening maakt deel uit van de cursus
Retrieval Augmented Generation (RAG) met LangChain
Oefeninstructies
- Initialiseer de BM25-retriever vanuit de documenten en stel hem zo in dat hij telkens drie documenten ophaalt.
- Roep de retriever aan met de gegeven query.
- Print de page content van het eerste resultaat.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
chunks = [
"RAG stands for Retrieval Augmented Generation.",
"Graph Retrieval Augmented Generation uses graphs to store and utilize relationships between documents in the retrieval process.",
"There are different types of RAG architectures; for example, Graph RAG."
]
# Initialize the BM25 retriever
bm25_retriever = ____.from_texts(____)
# Invoke the retriever
results = bm25_retriever.____("Graph RAG")
# Extract the page content from the first result
print("Most Relevant Document:")
print(____)