AILabs 551fa78b6d detailed - march 5 7 tháng trước cách đây
..
data 551fa78b6d detailed - march 5 7 tháng trước cách đây
Example_FinancialReport_RAG.ipynb 551fa78b6d detailed - march 5 7 tháng trước cách đây
README.md 061da02290 Contextual chunking with keywords for RAG 7 tháng trước cách đây
Tutorial.ipynb 551fa78b6d detailed - march 5 7 tháng trước cách đây
config.py 061da02290 Contextual chunking with keywords for RAG 7 tháng trước cách đây
helper.py 551fa78b6d detailed - march 5 7 tháng trước cách đây

README.md

Contextual keywords generation for RAG using Llama-3.1

Problem: Independent chunking in traditional RAG systems leads to the loss of contextual information between chunks. This makes it difficult for LLMs to retrieve relevant data when context (e.g., the subject or entity being discussed) is not explicitly repeated within individual chunks.

Solution: Generate keywords for each chunk to fulfill missing contextual information. These keywords (e.g., "BMW, X5, pricing") enrich the chunk with necessary context, ensuring better retrieval accuracy. By embedding this enriched metadata, the system bridges gaps between related chunks, enabling effective query matching and accurate answer generation.

This article explains benefits of contextual chunking.

Note This method does not require calling LLM for each chunk separately, which makes it efficient.

Getting started In this cookbook, we’ll use DeepInfra for Llama inference services, so be sure to obtain an API key from https://deepinfra.com/. You'll also need a LlamaParse API key to parse PDF files, which can be obtained from https://www.llamaindex.ai/. Additionally, an OpenAI API key is required for embeddings. Before getting started, update the config.py file as following:

"DEEPINFRA_API_KEY"="<your_api_key>"
"OPENAI_API_KEY"="<your_api_key>"
"LLAMAPARSE_API_KEY"="<your_api_key>"