Find answers from the community

Updated 2 months ago

I have multiple indices that are already in llamacloud. However, I want to assign specific

@kapa.ai
I have multiple indices that are already in llamacloud. However, I want to assign specific documents to a certain agent. In other words, I want to use multiple document agents. Can you tell me how to do that ? Assuming I want to have 2 or 3 agents where each agent will be assigned particular documents. So that I can query later on
k
i
9 comments
Please stand by @ihgumilar_ as I search the knowledge base. I normally take about 15 seconds or so. :wave:
----------------------
To implement multiple document agents in LlamaIndex, where each agent is assigned specific documents, you can use the MultiDocumentAgentsPack. This pack allows you to create a multi-document agents architecture where you can set up document agents for each document and a top-level agent to manage them. Here's how you can do it:

  1. First, you need to prepare your documents and their metadata:
Plain Text
docs = [doc1, doc2, doc3]  # Your document objects
doc_titles = ["Title1", "Title2", "Title3"]  # Titles for each document
doc_descriptions = ["Description1", "Description2", "Description3"]  # Descriptions for each document


  1. Download and initialize the MultiDocumentAgentsPack:
Plain Text
from llama_index.core.llama_pack import download_llama_pack

MultiDocumentAgentsPack = download_llama_pack(
    "MultiDocumentAgentsPack",
    "./multi_doc_agents_pack"
)

multi_doc_agents_pack = MultiDocumentAgentsPack(
    docs=docs,
    doc_titles=doc_titles,
    doc_descriptions=doc_descriptions
)


Source ()

This will create a separate agent for each document, and a top-level agent to manage them. Each document agent will have both a vector index (for semantic search) and a summary index (for summarization).

  1. To query the multi-document agent setup, you can use the query method of the pack:
Plain Text
response = multi_doc_agents_pack.query("Your question here")


This will allow the top-level agent to route the query to the appropriate document agent(s) based on the content of the question.
Keep in mind that this approach creates a new set of indices and agents. If you already have indices in LlamaCloud and want to use them directly, you might need to adapt this approach or consider building a custom solution using the individual components (like OpenAIAgent, VectorStoreIndex, and SummaryIndex) to work with your existing indices.

Source ()

Remember that the exact implementation might vary depending on your specific use case and the current state of your LlamaCloud indices. You may need to modify the approach to fit your particular requirements.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@kapa.ai I want to retrieve the availabel indices from llamacloud not using local store. Please give examples
Let me check the knowledge base for you again. One moment! :books:
----------------------
To retrieve available indices from LlamaCloud, you can use the LlamaCloudIndex and LlamaCloudRetriever classes provided by LlamaIndex. Here's an example of how you can do it:

First, you need to set your LlamaCloud API key:

Plain Text
import os
os.environ["LLAMA_CLOUD_API_KEY"] = "llx-..."  # replace with your actual API key


Then, you can connect to an existing index on LlamaCloud:

Plain Text
from llama_index.indices.managed.llama_cloud import LlamaCloudIndex

# connect to an existing index
index = LlamaCloudIndex("my_first_index", project_name="default")


You can also configure a retriever for managed retrieval:

Plain Text
# from the existing index
index.as_retriever()

# or from scratch
from llama_index.indices.managed.llama_cloud import LlamaCloudRetriever

retriever = LlamaCloudRetriever("my_first_index", project_name="default")


And of course, you can use other index shortcuts to get use out of your new managed index:

Plain Text
query_engine = index.as_query_engine(llm=llm)

chat_engine = index.as_chat_engine(llm=llm)


Please replace "my_first_index" and "default" with your actual index name and project name.

Source ()
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@kapa.ai how can I integrate that index with multi document agent
Let me check the knowledge base for you again. One moment! :books:
----------------------
To integrate the indices retrieved from LlamaCloud with a multi-document agent, you would need to modify the process of creating the MultiDocumentAgentsPack. Instead of creating new indices from local documents, you would use the indices retrieved from LlamaCloud.

However, the current LlamaIndex API does not provide a direct way to create a MultiDocumentAgentsPack using indices from LlamaCloud. The MultiDocumentAgentsPack is designed to create new indices from a set of documents and use them to build the agents.

If you want to use existing indices from LlamaCloud, you might need to create a custom solution. This could involve creating a new class similar to MultiDocumentAgentsPack but designed to work with LlamaCloud indices, or modifying the existing MultiDocumentAgentsPack class to accept LlamaCloud indices.

Please note that this would require a good understanding of the LlamaIndex API and possibly some advanced Python programming skills. If you're not comfortable with this, you might want to consider seeking help from a developer or a data scientist with experience in Python and LlamaIndex.

Source ()
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord