Repository: truera/trulens
Issue: Incompatibility between trulens and llamaindex: How to debug?
Root cause: Environment Incompatibility

**Bug Description**
**Tried to define the following function**
```
qs_relevance = (
    Feedback(truopenai.relevance_with_cot_reasons, name = "Context Relevance")
    .on_input()
    .on(TruLlama.select_source_nodes().node.text)
    .aggregate(np.mean)
)
```

**Got**
```
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/opt/miniconda3/envs/lindex/lib/python3.11/site-packages/trulens_eval/utils/imports.py", line 521, in __getattr__
    raise self.exception_class(self.message)
ModuleNotFoundError: 
You have llama-index installed but we could not import the required
components. There may be a version incompatibility. Please try installing this
exact package with pip: 

    ```bash
    pip install "llama-index==0.9.26"
    ```
```


**To Reproduce**
```
python3
Python 3.11.9 (main, Apr 19 2024, 11:43:47) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from trulens_eval import Feedback, TruLlama
>>> from trulens_eval import OpenAI as TruOpenAI
>>> truopenai =  TruOpenAI()
>>> qs_relevance = (
...     Feedback(truopenai.relevance_with_cot_reasons, name = "Context Relevance")
...     .on_input()
...     .on(TruLlama.select_source_nodes().node.text)
...     .aggregate(np.mean)
... )
```




**Expected behavior**
Either the function can de defined or the output states which component could not be imported

**Relevant Logs/Tracebacks**
Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. If the issue is related to the TruLens dashboard, please also include a screenshot.

**Environment:**
 - OS: MacOS
 - Conda Packages:
 
# packages in environment at /opt/miniconda3/envs/lindex:
#
# Name                    Version                   Build  Channel
aiohttp                   3.9.5                    pypi_0    pypi
aiosignal                 1.3.1                    pypi_0    pypi
alembic                   1.13.2                   pypi_0    pypi
altair                    5.3.0                    pypi_0    pypi
annotated-types           0.7.0                    pypi_0    pypi
anyio                     4.4.0                    pypi_0    pypi
appnope                   0.1.4                    pypi_0    pypi
argon2-cffi               23.1.0                   pypi_0    pypi
argon2-cffi-bindings      21.2.0                   pypi_0    pypi
arrow                     1.3.0                    pypi_0    pypi
asttokens                 2.4.1                    pypi_0    pypi
async-lru                 2.0.4                    pypi_0    pypi
asyncio                   3.4.3                    pypi_0    pypi
attrs                     23.2.0                   pypi_0    pypi
babel                     2.15.0                   pypi_0    pypi
beautifulsoup4            4.12.3                   pypi_0    pypi
bleach                    6.1.0                    pypi_0    pypi
blinker                   1.8.2                    pypi_0    pypi
bzip2                     1.0.8                h80987f9_6  
ca-certificates           2024.7.2             hca03da5_0  
cachetools                5.4.0                    pypi_0    pypi
certifi                   2024.7.4                 pypi_0    pypi
cffi                      1.16.0                   pypi_0    pypi
charset-normalizer        3.3.2                    pypi_0    pypi
click                     8.1.7                    pypi_0    pypi
comm                      0.2.2                    pypi_0    pypi
contourpy                 1.2.1                    pypi_0    pypi
cycler                    0.12.1                   pypi_0    pypi
dataclasses-json          0.6.7                    pypi_0    pypi
debugpy                   1.8.2                    pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
defusedxml                0.7.1                    pypi_0    pypi
deprecated                1.2.14                   pypi_0    pypi
dill                      0.3.8                    pypi_0    pypi
dirtyjson                 1.0.8                    pypi_0    pypi
distro                    1.9.0                    pypi_0    pypi
entrypoints               0.4                      pypi_0    pypi
executing                 2.0.1                    pypi_0    pypi
faker                     26.0.0                   pypi_0    pypi
fastjsonschema            2.20.0                   pypi_0    pypi
favicon                   0.7.0                    pypi_0    pypi
fonttools                 4.53.1                   pypi_0    pypi
fqdn                      1.5.1                    pypi_0    pypi
frozendict                2.4.4                    pypi_0    pypi
frozenlist                1.4.1                    pypi_0    pypi
fsspec                    2024.6.1                 pypi_0    pypi
gitdb                     4.0.11                   pypi_0    pypi
gitpython                 3.1.43                   pypi_0    pypi
google-api-core           2.19.1                   pypi_0    pypi
google-auth               2.32.0                   pypi_0    pypi
google-cloud-core         2.4.1                    pypi_0    pypi
google-cloud-firestore    2.17.0                   pypi_0    pypi
googleapis-common-protos  1.63.2                   pypi_0    pypi
greenlet                  3.0.3                    pypi_0    pypi
grpcio                    1.65.1                   pypi_0    pypi
grpcio-status             1.62.2                   pypi_0    pypi
h11                       0.14.0                   pypi_0    pypi
htbuilder                 0.6.2                    pypi_0    pypi
httpcore                  1.0.5                    pypi_0    pypi
httpx                     0.27.0                   pypi_0    pypi
humanize                  4.10.0                   pypi_0    pypi
idna                      3.7                      pypi_0    pypi
ipykernel                 6.29.5                   pypi_0    pypi
ipython                   8.26.0                   pypi_0    pypi
isoduration               20.11.0                  pypi_0    pypi
jedi                      0.19.1                   pypi_0    pypi
jinja2                    3.1.4                    pypi_0    pypi
joblib                    1.4.2                    pypi_0    pypi
json5                     0.9.25                   pypi_0    pypi
jsonpatch                 1.33                     pypi_0    pypi
jsonpointer               3.0.0                    pypi_0    pypi
jsonschema                4.23.0                   pypi_0    pypi
jsonschema-specifications 2023.12.1                pypi_0    pypi
jupyter-client            8.6.2                    pypi_0    pypi
jupyter-core              5.7.2                    pypi_0    pypi
jupyter-events            0.10.0                   pypi_0    pypi
jupyter-lsp               2.2.5                    pypi_0    pypi
jupyter-server            2.14.2                   pypi_0    pypi
jupyter-server-terminals  0.5.3                    pypi_0    pypi
jupyterlab                4.2.4                    pypi_0    pypi
jupyterlab-pygments       0.3.0                    pypi_0    pypi
jupyterlab-server         2.27.3                   pypi_0    pypi
kiwisolver                1.4.5                    pypi_0    pypi
langchain                 0.2.11                   pypi_0    pypi
langchain-community       0.2.10                   pypi_0    pypi
langchain-core            0.2.23                   pypi_0    pypi
langchain-text-splitters  0.2.2                    pypi_0    pypi
langsmith                 0.1.93                   pypi_0    pypi
libffi                    3.4.4                hca03da5_1  
llama-index-core          0.10.57                  pypi_0    pypi
llama-index-embeddings-openai 0.1.11                   pypi_0    pypi
llama-index-llms-openai   0.1.27                   pypi_0    pypi
llama-index-packs-auto-merging-retriever 0.1.3                    pypi_0    pypi
llama-index-postprocessor-rankgpt-rerank 0.1.6                    pypi_0    pypi
llama-index-postprocessor-sbert-rerank 0.1.4                    pypi_0    pypi
llama-index-readers-file  0.1.30                   pypi_0    pypi
llama-index-storage-docstore-firestore 0.1.3                    pypi_0    pypi
llama-index-storage-index-store-firestore 0.1.3                    pypi_0    pypi
llama-index-storage-kvstore-firestore 0.2.1                    pypi_0    pypi
llama-index-vector-stores-pinecone 0.1.8                    pypi_0    pypi
llama-parse               0.4.9                    pypi_0    pypi
lxml                      5.2.2                    pypi_0    pypi
mako                      1.3.5                    pypi_0    pypi
markdown                  3.6                      pypi_0    pypi
markdown-it-py            3.0.0                    pypi_0    pypi
markdownlit               0.0.7                    pypi_0    pypi
markupsafe                2.1.5                    pypi_0    pypi
marshmallow               3.21.3                   pypi_0    pypi
matplotlib                3.9.1                    pypi_0    pypi
matplotlib-inline         0.1.7                    pypi_0    pypi
mdurl                     0.1.2                    pypi_0    pypi
merkle-json               1.0.0                    pypi_0    pypi
millify                   0.1.1                    pypi_0    pypi
mistune                   3.0.2                    pypi_0    pypi
more-itertools            10.3.0                   pypi_0    pypi
multidict                 6.0.5                    pypi_0    pypi
munch                     4.0.0                    pypi_0    pypi
mypy-extensions           1.0.0                    pypi_0    pypi
nbclient                  0.10.0                   pypi_0    pypi
nbconvert                 7.16.4                   pypi_0    pypi
nbformat                  5.10.4                   pypi_0    pypi
ncurses                   6.4                  h313beb8_0  
nest-asyncio              1.6.0                    pypi_0    pypi
networkx                  3.3                      pypi_0    pypi
nltk                      3.8.1                    pypi_0    pypi
notebook                  7.2.1                    pypi_0    pypi
notebook-shim             0.2.4                    pypi_0    pypi
numpy                     1.26.4                   pypi_0    pypi
openai                    1.37.0                   pypi_0    pypi
openssl                   3.0.14               h80987f9_0  
orjson                    3.10.6                   pypi_0    pypi
overrides                 7.7.0                    pypi_0    pypi
packaging                 24.1                     pypi_0    pypi
pandas                    2.2.2                    pypi_0    pypi
pandocfilters             1.5.1                    pypi_0    pypi
parso                     0.8.4                    pypi_0    pypi
pexpect                   4.9.0                    pypi_0    pypi
pillow                    10.4.0                   pypi_0    pypi
pinecone                  4.0.0                    pypi_0    pypi
pinecone-client           3.2.2                    pypi_0    pypi
pip                       24.0            py311hca03da5_0  
platformdirs              4.2.2                    pypi_0    pypi
prometheus-client         0.20.0                   pypi_0    pypi
prompt-toolkit            3.0.47                   pypi_0    pypi
proto-plus                1.24.0                   pypi_0    pypi
protobuf                  4.25.3                   pypi_0    pypi
psutil                    6.0.0                    pypi_0    pypi
ptyprocess                0.7.0                    pypi_0    pypi
pure-eval                 0.2.3                    pypi_0    pypi
pyarrow                   17.0.0                   pypi_0    pypi
pyasn1                    0.6.0                    pypi_0    pypi
pyasn1-modules            0.4.0                    pypi_0    pypi
pycparser                 2.22                     pypi_0    pypi
pydantic                  2.8.2                    pypi_0    pypi
pydantic-core             2.20.1                   pypi_0    pypi
pydeck                    0.9.1                    pypi_0    pypi
pygments                  2.18.0                   pypi_0    pypi
pymdown-extensions        10.8.1                   pypi_0    pypi
pyparsing                 3.1.2                    pypi_0    pypi
pypdf                     4.3.1                    pypi_0    pypi
python                    3.11.9               hb885b13_0  
python-dateutil           2.9.0.post0              pypi_0    pypi
python-decouple           3.8                      pypi_0    pypi
python-dotenv             1.0.1                    pypi_0    pypi
python-json-logger        2.0.7                    pypi_0    pypi
pytils                    0.4.1                    pypi_0    pypi
pytz                      2024.1                   pypi_0    pypi
pyyaml                    6.0.1                    pypi_0    pypi
pyzmq                     26.0.3                   pypi_0    pypi
readline                  8.2                  h1a28f6b_0  
referencing               0.35.1                   pypi_0    pypi
regex                     2024.5.15                pypi_0    pypi
requests                  2.32.3                   pypi_0    pypi
rfc3339-validator         0.1.4                    pypi_0    pypi
rfc3986-validator         0.1.1                    pypi_0    pypi
rich                      13.7.1                   pypi_0    pypi
rpds-py                   0.19.0                   pypi_0    pypi
rsa                       4.9                      pypi_0    pypi
selectors                 0.0.14                   pypi_0    pypi
send2trash                1.8.3                    pypi_0    pypi
setuptools                69.5.1          py311hca03da5_0  
six                       1.16.0                   pypi_0    pypi
smmap                     5.0.1                    pypi_0    pypi
sniffio                   1.3.1                    pypi_0    pypi
soupsieve                 2.5                      pypi_0    pypi
sqlalchemy                2.0.31                   pypi_0    pypi
sqlite                    3.45.3               h80987f9_0  
st-annotated-text         4.0.1                    pypi_0    pypi
st-theme                  1.2.3                    pypi_0    pypi
stack-data                0.6.3                    pypi_0    pypi
streamlit                 1.36.0                   pypi_0    pypi
streamlit-aggrid          0.3.4                    pypi_0    pypi
streamlit-camera-input-live 0.2.0                    pypi_0    pypi
streamlit-card            1.0.2                    pypi_0    pypi
streamlit-embedcode       0.1.2                    pypi_0    pypi
streamlit-extras          0.4.3                    pypi_0    pypi
streamlit-faker           0.0.3                    pypi_0    pypi
streamlit-image-coordinates 0.1.9                    pypi_0    pypi
streamlit-keyup           0.2.4                    pypi_0    pypi
streamlit-pills           0.3.0                    pypi_0    pypi
streamlit-toggle-switch   1.0.2                    pypi_0    pypi
streamlit-vertical-slider 2.5.5                    pypi_0    pypi
striprtf                  0.0.26                   pypi_0    pypi
tenacity                  8.5.0                    pypi_0    pypi
terminado                 0.18.1                   pypi_0    pypi
tiktoken                  0.7.0                    pypi_0    pypi
tinycss2                  1.3.0                    pypi_0    pypi
tk                        8.6.14               h6ba3021_0  
toml                      0.10.2                   pypi_0    pypi
toolz                     0.12.1                   pypi_0    pypi
tornado                   6.4.1                    pypi_0    pypi
tqdm                      4.66.4                   pypi_0    pypi
traitlets                 5.14.3                   pypi_0    pypi
trulens-eval              0.33.0                   pypi_0    pypi
types-python-dateutil     2.9.0.20240316           pypi_0    pypi
typing-extensions         4.12.2                   pypi_0    pypi
typing-inspect            0.9.0                    pypi_0    pypi
tzdata                    2024.1                   pypi_0    pypi
uri-template              1.3.0                    pypi_0    pypi
urllib3                   2.2.2                    pypi_0    pypi
user-agent                0.1.10                   pypi_0    pypi
validators                0.33.0                   pypi_0    pypi
wcwidth                   0.2.13                   pypi_0    pypi
webcolors                 24.6.0                   pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
weblib                    0.1.30                   pypi_0    pypi
websocket-client          1.8.0                    pypi_0    pypi
wheel                     0.43.0          py311hca03da5_0  
wrapt                     1.16.0                   pypi_0    pypi
xz                        5.4.6                h80987f9_1  
yarl                      1.9.4                    pypi_0    pypi
zlib                      1.2.13               h18a0788_1  


**Additional context**
Add any other context about the problem here.


<!-- Greeting -->
Hey @subhachandrachandra! I'm here to help you with your bug 🐛 Let's squash it together!

<!-- Answer -->
To resolve the `ModuleNotFoundError` when defining the function using the `trulens` and `llamaindex` packages, ensure you have the correct version of the `llama-index` package installed. The error message suggests installing version `0.9.26`, but the latest code checks for version `0.10.0` or later.

Here is the relevant part of the code that handles the imports:

```python
with OptionalImports(messages=REQUIREMENT_LLAMA) as opt:
    import llama_index

    version = get_package_version("llama_index")

    legacy: bool = version is None or isinstance(llama_index, Dummy)

    if not legacy:
        if version < parse_version("0.10.0"):
            legacy = True

    if not legacy:
        from llama_index.core.base.base_query_engine import BaseQueryEngine
        # ... other imports for versions >= 0.10.0
    else:
        if version is not None:
            logger.warning(
                "Using legacy llama_index version %s. Consider upgrading to 0.10.0 or later.",
                version
            )
```

Ensure you have `llama-index` version `0.10.0` or later installed:

```sh
pip install llama-index==0.10.0
```

If you have already installed the correct version and still face the issue, double-check the installation and ensure there are no conflicting versions of the package. Additionally, `trulens_eval` uses a context-manager-based scheme to handle optional packages. If `llama_index` is not installed, you will receive a message indicating that it is required and how to install it:

```
ModuleNotFoundError: 
llama-index package is required for instrumenting llama_index apps.
You should be able to install it with pip:

    pip install "llama-index>=v0.9.14.post3"
```

Make sure to follow these instructions if prompted. If you import directly from `TruLlama` and the package is not installed, you will get the message immediately <sup>[[1]](https://github.com/truera/trulens/blob/main/trulens_eval/trulens_eval/tru_llama.py)</sup><sup>[[2]](https://github.com/truera/trulens/blob/main/trulens_eval/trulens_eval/utils/imports.py)</sup>.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*


@dosu The issue has been solved. I had only installed the llama-index-core package and not llama-index itself. Installing that solved the problem. I was already using 0.10.57