run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
33.88k stars 4.77k forks source link

[Question]: How to fix Only one root is supported issue? #12911

Open avalonliberty opened 3 months ago

avalonliberty commented 3 months ago

Question Validation

Question

I am trying to replace the default model in RAG. Here is my script for creating custom CLI

from llama_index.core.ingestion import IngestionPipeline
from llama_index.core.query_pipeline import QueryPipeline
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.core import Settings
from llama_index.llms.ollama import Ollama
from llama_index.cli.rag import RagCLI

Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
custom_ingestion_pipeline = IngestionPipeline()
custom_query_pipeline = QueryPipeline()

llm = Ollama(model="llama2:7b", request_timeout=30.0)
rag_cli_instance = RagCLI(
    ingestion_pipeline=custom_ingestion_pipeline,
    query_pipeline=custom_query_pipeline,
    llm=llm,
)
if __name__ == "__main__":
    rag_cli_instance.cli()

However, when I tried to ask question to the model it showed this error message

Traceback (most recent call last):
  File "/home/ubuntu/ollama/ollama-index_cli.py", line 19, in <module>
    rag_cli_instance.cli()
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 392, in cli
    args.func(args)
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 371, in <lambda>
    func=lambda args: asyncio.run(
                      ^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 296, in handle_cli
    await self.handle_question(question)
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 306, in handle_question
    response = chat_engine.chat(question)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/callbacks/utils.py", line 41, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/chat_engine/condense_question.py", line 188, in chat
    query_response = self._query_engine.query(condensed_question)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/query_engine/custom.py", line 45, in query
    raw_response = self.custom_query(query_str)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 61, in custom_query
    return self.query_pipeline.run(query_str=query_str)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/query_pipeline/query.py", line 320, in run
    outputs, _ = self._run(
                 ^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/query_pipeline/query.py", line 542, in _run
    root_key, kwargs = self._get_root_key_and_kwargs(*args, **kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/query_pipeline/query.py", line 484, in _get_root_key_and_kwargs
    raise ValueError("Only one root is supported.")
ValueError: Only one root is supported.
(ollama) ubuntu@ip-172-31-13-5:~/ollama$ python ollama-index_cli.py rag --question "Who is Harry?"
Traceback (most recent call last):
  File "/home/ubuntu/ollama/ollama-index_cli.py", line 19, in <module>
    rag_cli_instance.cli()
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 392, in cli
    args.func(args)
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 371, in <lambda>
    func=lambda args: asyncio.run(
                      ^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 296, in handle_cli
    await self.handle_question(question)
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 306, in handle_question
    response = chat_engine.chat(question)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/callbacks/utils.py", line 41, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/chat_engine/condense_question.py", line 188, in chat
    query_response = self._query_engine.query(condensed_question)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/query_engine/custom.py", line 45, in query
    raw_response = self.custom_query(query_str)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/cli/rag/base.py", line 61, in custom_query
    return self.query_pipeline.run(query_str=query_str)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/query_pipeline/query.py", line 320, in run
    outputs, _ = self._run(
                 ^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/query_pipeline/query.py", line 542, in _run
    root_key, kwargs = self._get_root_key_and_kwargs(*args, **kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/ollama/lib/python3.11/site-packages/llama_index/core/query_pipeline/query.py", line 484, in _get_root_key_and_kwargs
    raise ValueError("Only one root is supported.")
ValueError: Only one root is supported.

I've looked into the code. It seems that the root key is related to DAG in the background. I don't see the reason why it can trigger an error given I purely use the default query pipeline. Is there any way to solve this issue?

dosubot[bot] commented 3 months ago

The error "Only one root is supported" suggests an issue with how directories are managed in your setup, particularly in relation to the RagCLI class's expectations for directory structures. This error often occurs when the system expects a single root directory but finds multiple, which can happen in several areas of your custom CLI setup:

  1. Check Persist Directory Handling: Ensure the persist_dir attribute in RagCLI, which determines where ingestion pipeline data is stored, is correctly set to a single path.

  2. Review Ingestion Pipeline Configuration: Your ingestion_pipeline should be configured to work with a single root directory. If your custom model or data processing steps involve directory management, make sure they comply with this requirement.

  3. Ensure Compatibility of Custom Model Integration: If your custom model has specific directory structure needs, verify that these are compatible with the RagCLI's handling of directories, particularly the persist_dir.

  4. CLI Arguments and Data Handling: The way CLI arguments are processed and how data ingestion is handled in the handle_cli method might also be areas where the issue arises. Ensure that the logic does not lead to the creation or use of multiple root directories.

To resolve the issue, focus on aligning your custom setup with the single-root directory principle, ensuring that all parts of your system are configured to use and expect only one root directory for operations. If the problem persists after checking these areas, consider isolating the operation that triggers the error for a more detailed review of the directory and file handling logic involved.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.