Tutorial

llamaAIvllmmachine-learningend-to-end-use-casesContextual-Chunking-RAGllama2LLMllama-cookbookPythonfinetuningpytorchlangchain

Tutorial

In this tutorial, we'll break a sample text document into chunks and generate contextual keywords for each one using Llama 3.1.

Let's start by installing the important packages. For Llama model inference, we use DeepInfra here, but you can use any inference service provider

[ ]

First, obtain your document content. For this tutorial, the recommended document size ranges from 2,000 to 20,000 tokens.

[ ]

We will then split the document content into chunks of 300-1000 tokens

[ ]

Now your chunked_content looks like

### Chunk 1 ###
{chunk1}

### Chunk 2 ###
{chunk2}

..

Next, generate contextual keywords to have better chunk representation for embeddings. Here, we use DeepInfra servers for inference

[ ]

Next, we need to parse the generated keywords into array

[ ]

Now you can modify the chunks using the generated keywords.

For example,
chunk1 = #{keywords1}\n{chunk1}