# Chat with Multiple Documents

Let's build the stack. Create a new project and select Chat stack.&#x20;

### Step-1: Load the Data from different sources and chunk them

The first step is to pick the different loaders needed for your use case. You can also combine PDF, Document, URL, YouTube, subtitles, song lyrics together. Once we load the content, we split the document into smaller chunks. Make sure, to provide meta data when you are working with multiple data loaders.&#x20;

After loading the content, we divide the document into smaller segments. This segmentation is necessary because it enables us to provide users with relevant information from the appropriate chunk when they query any prompt.

<figure><img src="https://lh7-us.googleusercontent.com/Sg8BDIuqSe8oGSCMyakcReA0v3vHhbBl-THsBRDa7COxaslc59wzfq8eZDScf60HeEgPBBkgZmw_U3_mCHIjdpRHP4UA_gnzBH0F7xJN3oll93qknSHmkTg7gvVFqvTGkWgdi3THjWMQBB23ZTrOikY" alt=""><figcaption></figcaption></figure>

Check all the loader list: <https://docs.aiplanet.com/components/document-loaders> and more information on text splitters: <https://docs.aiplanet.com/components/text-splitters>

### S**tep 2: Index your document**

To index a document, it's crucial to generate an embedding for each section and save it in a vector database. Turning on the persist option avoids the need to recreate indexes for existing content.&#x20;

We use vector storage to store the embeddings of the document and retrieve them based on search techniques for the given prompt. The Vector Store accommodates various search types, with similarity search being utilized in this instance.

Since we are handling large chunks of data, it is advisable to enable persistence in the directory. This ensures that we do not recreate the index if it has already been created. We can use the directory `/mnt/models/chroma` for persistence.

<figure><img src="/files/lvoznSRZc2pePOoSScht" alt=""><figcaption></figcaption></figure>

### Step-3: Generator and Retriever

The Retrieval-Augmented Generation (RAG) pipeline involves two main parts: the Retriever and the Generator. The Retriever finds useful information from the index based on the user's query. Then, this relevant information, along with the prompt, is given to the Large Language Model (LLM), which acts as the generator in the RAG pipeline.

Learn what is RAG and how it works: <https://docs.aiplanet.com/terminologies/rag-retrieval-augmented-generation>&#x20;

<figure><img src="https://lh7-us.googleusercontent.com/NEYEVPvRQZbTk32QVlMBRGLT6FOfaxSLsPtYZmvotkaVy4m15oZImO0wmmp6J6lZYvQf6jgm30MxBD1jjkhVtLOnBxrcz4bK-t8NqYHTi49ge97fhtvKDZ3AF3LXAEibYkoP975LcxXfpgaU5XIZe98" alt=""><figcaption></figcaption></figure>

### Step-4: Chat with your multiple document

Build the stack(⚡),  Upon a successful build, navigate to the chat icon to commence interaction.

<figure><img src="https://lh7-us.googleusercontent.com/iyCFrHypmQX5-vsdOUqGHb1Bx9PqLrOZg0PYSq75d7ypNBgvxtaeFUu4kdYdda7UbRbInGFhMNymjjkLxiPI8h_n_weWWZHCEeCm-MkPnRtNKc_PJ7Fox3IEytE4sBWtnqde6w9HMqgxDm0KNEtBIIQ" alt=""><figcaption></figcaption></figure>

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aiplanet.com/genai-stack-1/usecases/chat-with-multiple-documents.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
